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.

244 lines
6.8 KiB

  1. /*****************************************************************************
  2. *
  3. * Component: sndvol32.exe
  4. * File: reg.c
  5. * Purpose: registry access functions
  6. *
  7. * Copyright (c) 1985-1995 Microsoft Corporation
  8. *
  9. *****************************************************************************/
  10. #include <windows.h>
  11. #include <regstr.h>
  12. // Note: The following line generates a UNICODE error
  13. // so it has been replaced by the line after.
  14. //const TCHAR szRegPath[] = REGSTR_PATH_WINDOWSAPPLETS "\\Volume Control";
  15. const TCHAR szRegPath[] = TEXT ("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Volume Control");
  16. /* ReadRegistryData
  17. *
  18. * Reads information from the registry
  19. *
  20. * Parameters:
  21. *
  22. * pEntryNode - The node under Media Player which should be opened
  23. * for this data. If this is NULL, the value is
  24. * written directly under szRegPath.
  25. *
  26. * pEntryName - The name of the value under pEntryNode to be retrieved.
  27. *
  28. * pType - Pointer to a buffer to receive type of data read. May be NULL.
  29. *
  30. * pData - Pointer to a buffer to receive the value data.
  31. *
  32. * Size - Size, in bytes, of the buffer pointed to by pData.
  33. *
  34. * Return:
  35. *
  36. * Registry status return (NO_ERROR is good)
  37. *
  38. *
  39. * Andrew Bell (andrewbe) wrote it, 10 September 1992
  40. *
  41. */
  42. DWORD ReadRegistryData( LPTSTR pEntryNode,
  43. LPTSTR pEntryName,
  44. PDWORD pType,
  45. LPBYTE pData,
  46. DWORD DataSize )
  47. {
  48. DWORD Status;
  49. HKEY hkeyRegPath;
  50. HKEY hkeyEntryNode;
  51. DWORD Size;
  52. /* Open the top-level node. For Media Player this is:
  53. * "Software\\Microsoft\\Windows NT\\CurrentVersion\\Sound Recorder"
  54. */
  55. Status = RegOpenKeyEx( HKEY_CURRENT_USER, szRegPath, 0,
  56. KEY_READ, &hkeyRegPath );
  57. if( Status == NO_ERROR )
  58. {
  59. /* Open the sub-node:
  60. */
  61. if( pEntryNode )
  62. Status = RegOpenKeyEx( hkeyRegPath, pEntryNode, 0,
  63. KEY_READ, &hkeyEntryNode );
  64. else
  65. hkeyEntryNode = hkeyRegPath;
  66. if( Status == NO_ERROR )
  67. {
  68. Size = DataSize;
  69. /* Read the entry from the registry:
  70. */
  71. Status = RegQueryValueEx( hkeyEntryNode,
  72. pEntryName,
  73. 0,
  74. pType,
  75. pData,
  76. &Size );
  77. if( pEntryNode )
  78. RegCloseKey( hkeyEntryNode );
  79. }
  80. RegCloseKey( hkeyRegPath );
  81. }
  82. return Status;
  83. }
  84. DWORD QueryRegistryDataSize(
  85. LPTSTR pEntryNode,
  86. LPTSTR pEntryName,
  87. DWORD *pDataSize )
  88. {
  89. DWORD Status;
  90. HKEY hkeyRegPath;
  91. HKEY hkeyEntryNode;
  92. DWORD Size;
  93. /* Open the top-level node. For Media Player this is:
  94. * "Software\\Microsoft\\Windows NT\\CurrentVersion\\Sound Recorder"
  95. */
  96. Status = RegOpenKeyEx( HKEY_CURRENT_USER, szRegPath, 0,
  97. KEY_READ, &hkeyRegPath );
  98. if( Status == NO_ERROR )
  99. {
  100. /* Open the sub-node:
  101. */
  102. if( pEntryNode )
  103. Status = RegOpenKeyEx( hkeyRegPath, pEntryNode, 0,
  104. KEY_READ, &hkeyEntryNode );
  105. else
  106. hkeyEntryNode = hkeyRegPath;
  107. if( Status == NO_ERROR )
  108. {
  109. /* Read the entry from the registry:
  110. */
  111. Size = 0;
  112. Status = RegQueryValueEx( hkeyEntryNode,
  113. pEntryName,
  114. 0,
  115. NULL,
  116. NULL,
  117. &Size );
  118. if (Status == NO_ERROR)
  119. *pDataSize = Size;
  120. if( pEntryNode )
  121. RegCloseKey( hkeyEntryNode );
  122. }
  123. RegCloseKey( hkeyRegPath );
  124. }
  125. return Status;
  126. }
  127. /* WriteRegistryData
  128. *
  129. * Writes a bunch of information to the registry
  130. *
  131. * Parameters:
  132. *
  133. * pEntryNode - The node under szRegPath which should be created
  134. * or opened for this data. If this is NULL, the value is
  135. * written directly under szRegPath.
  136. *
  137. * pEntryName - The name of the value under pEntryNode to be set.
  138. *
  139. * Type - Type of data to read (e.g. REG_SZ).
  140. *
  141. * pData - Pointer to the value data to be written. If this is NULL,
  142. * the value under pEntryNode is deleted.
  143. *
  144. * Size - Size, in bytes, of the buffer pointed to by pData.
  145. *
  146. *
  147. * This routine is fairly generic, apart from the name of the top-level node.
  148. *
  149. * The data are stored in the following registry tree:
  150. *
  151. * HKEY_CURRENT_USER
  152. *
  153. * Software
  154. *
  155. * Microsoft
  156. *
  157. * Windows NT
  158. *
  159. * CurrentVersion
  160. *
  161. * Media Player
  162. *
  163. * AVIVideo
  164. *
  165. * DisplayPosition
  166. *
  167. * SysIni
  168. *
  169. *
  170. * Return:
  171. *
  172. * Registry status return (NO_ERROR is good)
  173. *
  174. *
  175. * Andrew Bell (andrewbe) wrote it, 10 September 1992
  176. *
  177. */
  178. DWORD WriteRegistryData( LPTSTR pEntryNode,
  179. LPTSTR pEntryName,
  180. DWORD Type,
  181. LPBYTE pData,
  182. DWORD Size )
  183. {
  184. DWORD Status;
  185. HKEY hkeyRegPath;
  186. HKEY hkeyEntryNode;
  187. /* Open or create the top-level node. For Media Player this is:
  188. * "Software\\Microsoft\\Windows NT\\CurrentVersion\\Media Player"
  189. */
  190. Status = RegCreateKeyEx( HKEY_CURRENT_USER, szRegPath, 0,
  191. NULL, 0, KEY_WRITE, NULL, &hkeyRegPath, NULL );
  192. if( Status == NO_ERROR )
  193. {
  194. /* Open or create the sub-node.
  195. */
  196. if( pEntryNode )
  197. Status = RegCreateKeyEx( hkeyRegPath, pEntryNode, 0,
  198. NULL, 0, KEY_WRITE, NULL, &hkeyEntryNode, NULL );
  199. else
  200. hkeyEntryNode = hkeyRegPath;
  201. if( Status == NO_ERROR )
  202. {
  203. if( pData )
  204. {
  205. Status = RegSetValueEx( hkeyEntryNode,
  206. pEntryName,
  207. 0,
  208. Type,
  209. pData,
  210. Size );
  211. }
  212. else
  213. {
  214. Status = RegDeleteValue( hkeyEntryNode, pEntryName );
  215. }
  216. if( pEntryNode )
  217. RegCloseKey( hkeyEntryNode );
  218. }
  219. RegCloseKey( hkeyRegPath );
  220. }
  221. return Status;
  222. }