Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

145 lines
3.6 KiB

  1. // TVProfile.cpp : Implementation of CTVProfile
  2. #include "stdafx.h"
  3. #include "Tvprof.h"
  4. #include "TVProfile.h"
  5. typedef TCHAR IPADDR_TSTR[4*4];
  6. TCHAR gc_tszPathTVProfile[] = _TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\TVPlayer");
  7. TCHAR gc_tszIPSinkAddress[] = _TEXT("IPSinkAddress");
  8. TCHAR gc_tszAudioDestination[] = _TEXT("AudioDestination");
  9. /////////////////////////////////////////////////////////////////////////////
  10. // CTVProfile
  11. STDMETHODIMP CTVProfile::get_IPSinkAddress(BSTR *pVal)
  12. {
  13. if (NULL == pVal)
  14. return E_POINTER;
  15. HRESULT hr = S_OK;
  16. HKEY hKey = NULL;
  17. LONG lRes;
  18. // TODO: Once we expand the list of environment variables, write a function
  19. // ReadMachineProfile that reads and caches all HKLM variables at once, and
  20. // call it from here if not already called.
  21. // Open key
  22. lRes = RegCreateKeyEx(HKEY_LOCAL_MACHINE,
  23. gc_tszPathTVProfile,
  24. 0,
  25. NULL,
  26. REG_OPTION_NON_VOLATILE,
  27. KEY_QUERY_VALUE,
  28. NULL,
  29. &hKey,
  30. NULL );
  31. if ((lRes != ERROR_SUCCESS) || (hKey == NULL))
  32. return E_FAIL;
  33. IPADDR_TSTR tszData;
  34. DWORD cbData;
  35. DWORD dwType;
  36. cbData = sizeof(IPADDR_TSTR);
  37. lRes = RegQueryValueExA(hKey,
  38. gc_tszIPSinkAddress,
  39. NULL,
  40. &dwType,
  41. (LPBYTE)tszData,
  42. &cbData);
  43. RegCloseKey(hKey);
  44. if (lRes != ERROR_SUCCESS)
  45. {
  46. return E_FAIL;
  47. }
  48. if (dwType != REG_SZ)
  49. {
  50. // Registry is messed up. Value of IPStringAddress is not a string.
  51. return E_FAIL;
  52. }
  53. #ifdef UNICODE
  54. *pVal = SysAllocString(tszData);
  55. if (NULL == *pVal)
  56. {
  57. return E_OUTOFMEMORY;
  58. }
  59. #else
  60. *pVal = SysAllocStringLen(NULL, cbData); // length of string == cbData
  61. if (NULL == *pVal)
  62. {
  63. return E_OUTOFMEMORY;
  64. }
  65. int cConverted = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, tszData, cbData, *pVal, cbData);
  66. if (0 == cConverted)
  67. {
  68. return HRESULT_FROM_WIN32(GetLastError());
  69. }
  70. #endif
  71. return S_OK;
  72. }
  73. //******************************************************************************************
  74. STDMETHODIMP CTVProfile::get_AudioDestination(long *pVal)
  75. {
  76. if (NULL == pVal)
  77. return E_POINTER;
  78. HRESULT hr = S_OK;
  79. HKEY hKey = NULL;
  80. LONG lRes;
  81. // Open key
  82. lRes = RegCreateKeyEx(HKEY_LOCAL_MACHINE,
  83. gc_tszPathTVProfile,
  84. 0,
  85. NULL,
  86. REG_OPTION_NON_VOLATILE,
  87. KEY_QUERY_VALUE,
  88. NULL,
  89. &hKey,
  90. NULL );
  91. if ((lRes != ERROR_SUCCESS) || (hKey == NULL))
  92. return E_FAIL;
  93. DWORD dwAudioDestination;
  94. DWORD cbData;
  95. DWORD dwType;
  96. cbData = sizeof(DWORD);
  97. lRes = RegQueryValueEx(hKey,
  98. gc_tszAudioDestination,
  99. NULL,
  100. &dwType,
  101. (LPBYTE)&dwAudioDestination,
  102. &cbData);
  103. RegCloseKey(hKey);
  104. if (lRes != ERROR_SUCCESS)
  105. {
  106. return E_FAIL;
  107. }
  108. if (dwType != REG_DWORD)
  109. {
  110. // Registry is messed up. Value of AudioDestination is not a dword
  111. return E_FAIL;
  112. }
  113. *pVal = (long)dwAudioDestination;
  114. return S_OK;
  115. }