Leaked source code of windows server 2003
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.

194 lines
5.5 KiB

  1. //==========================================================================;
  2. //
  3. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  4. // KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  5. // IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  6. // PURPOSE.
  7. //
  8. // Copyright (c) 1994-1996 Microsoft Corporation
  9. //
  10. //--------------------------------------------------------------------------;
  11. //
  12. // profile.c
  13. //
  14. // Description:
  15. // This file contains routines to access the registry directly. You
  16. // must include profile.h to use these routines.
  17. //
  18. // All keys are opened under the following key:
  19. //
  20. // HKEY_CURRENT_USER\Software\Microsoft\Multimedia\Audio
  21. // Compression Manager
  22. //
  23. // Keys should be opened at boot time, and closed at shutdown.
  24. //
  25. //==========================================================================;
  26. #include <windows.h>
  27. #include <windowsx.h>
  28. #include <mmsystem.h>
  29. #include <mmddk.h>
  30. #include <mmreg.h>
  31. #include <msacm.h>
  32. #include <msacmdrv.h>
  33. #include "msacmmap.h"
  34. #include "profile.h"
  35. #include "debug.h"
  36. #define ACM_PROFILE_ROOTKEY HKEY_CURRENT_USER
  37. const TCHAR gszAcmProfileKey[] =
  38. TEXT("Software\\Microsoft\\Multimedia");
  39. //
  40. // Chicago Win16 does not appear to support RegCreateKeyEx, so we implement
  41. // it using this define.
  42. //
  43. #ifndef _WIN32
  44. #define RegCreateKeyEx( hkey, lpszSubKey, a, b, c, d, e, phkResult, f ) \
  45. RegCreateKey( hkey, lpszSubKey, phkResult )
  46. #endif
  47. //--------------------------------------------------------------------------;
  48. //
  49. // HKEY IRegOpenKey
  50. //
  51. // Description:
  52. // This routine opens a sub key under the default ACM key. We allow
  53. // all access to the key.
  54. //
  55. // Arguments:
  56. // LPCTSTR pszKeyName: Name of the sub key.
  57. //
  58. // Return (HKEY): Handle to the opened key, or NULL if the request failed.
  59. //
  60. //--------------------------------------------------------------------------;
  61. HKEY FNGLOBAL IRegOpenKey
  62. (
  63. LPCTSTR pszKeyName
  64. )
  65. {
  66. HKEY hkeyAcm = NULL;
  67. HKEY hkeyRet = NULL;
  68. RegCreateKeyEx( ACM_PROFILE_ROOTKEY, gszAcmProfileKey, 0, NULL, 0,
  69. KEY_WRITE, NULL, &hkeyAcm, NULL );
  70. if( NULL != hkeyAcm )
  71. {
  72. RegCreateKeyEx( hkeyAcm, pszKeyName, 0, NULL, 0,
  73. KEY_WRITE | KEY_READ, NULL, &hkeyRet, NULL );
  74. RegCloseKey( hkeyAcm );
  75. }
  76. return hkeyRet;
  77. }
  78. //--------------------------------------------------------------------------;
  79. //
  80. // BOOL IRegReadString
  81. //
  82. // Description:
  83. // This routine reads a value from an opened registry key. The return
  84. // value indicates success or failure. If the HKEY is NULL, we return
  85. // a failure. Note that there is no default string...
  86. //
  87. // Arguments:
  88. // HKEY hkey: An open registry key. If NULL, we fail.
  89. // LPCTSTR pszValue: Name of the value.
  90. // LPTSTR pszData: Buffer to store the data in.
  91. // DWORD cchData: Size (in chars) of the buffer.
  92. //
  93. // Return (BOOL): TRUE indicates success. If the return is FALSE, you
  94. // can't count on the data in pszData - it might be something weird.
  95. //
  96. //--------------------------------------------------------------------------;
  97. BOOL FNGLOBAL IRegReadString
  98. (
  99. HKEY hkey,
  100. LPCTSTR pszValue,
  101. LPTSTR pszData,
  102. DWORD cchData
  103. )
  104. {
  105. DWORD dwType = (DWORD)~REG_SZ; // Init to anything but REG_SZ.
  106. DWORD cbData;
  107. LONG lError;
  108. cbData = sizeof(TCHAR) * cchData;
  109. lError = RegQueryValueEx( hkey,
  110. (LPTSTR)pszValue,
  111. NULL,
  112. &dwType,
  113. (LPBYTE)pszData,
  114. &cbData );
  115. return ( ERROR_SUCCESS == lError && REG_SZ == dwType );
  116. }
  117. //--------------------------------------------------------------------------;
  118. //
  119. // DWORD IRegReadDwordDefault
  120. //
  121. // Description:
  122. // This routine reads a given value from the registry, and returns a
  123. // default value if the read is not successful.
  124. //
  125. // Arguments:
  126. // HKEY hkey: Registry key to read from.
  127. // LPCTSTR pszValue:
  128. // DWORD dwDefault:
  129. //
  130. // Return (DWORD):
  131. //
  132. //--------------------------------------------------------------------------;
  133. DWORD FNGLOBAL IRegReadDwordDefault
  134. (
  135. HKEY hkey,
  136. LPCTSTR pszValue,
  137. DWORD dwDefault
  138. )
  139. {
  140. DWORD dwType = (DWORD)~REG_DWORD; // Init to anything but REG_DWORD.
  141. DWORD cbSize = sizeof(DWORD);
  142. DWORD dwRet = 0;
  143. LONG lError;
  144. lError = RegQueryValueEx( hkey,
  145. (LPTSTR)pszValue,
  146. NULL,
  147. &dwType,
  148. (LPBYTE)&dwRet,
  149. &cbSize );
  150. //
  151. // Really we should have a test like this:
  152. //
  153. // if( ERROR_SUCCESS != lError || REG_DWORD != dwType )
  154. //
  155. // But, the Chicago RegEdit will not let you enter REG_DWORD values,
  156. // it will only let you enter REG_BINARY values, so that test is
  157. // too strict. Just test for no error instead.
  158. //
  159. if( ERROR_SUCCESS != lError )
  160. dwRet = dwDefault;
  161. return dwRet;
  162. }