home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / include / bpcreg.h < prev    next >
C/C++ Source or Header  |  1998-04-25  |  31KB  |  855 lines

  1. #if _MSC_VER > 1000
  2. #pragma once
  3. #endif
  4.  
  5. #ifndef BPCREG_H
  6. #define BPCREG_H
  7.  
  8. #include <tchar.h>
  9.  
  10. //-----------------------------------------------------------------------------
  11. //
  12. // Registry usage:
  13. //
  14. // HKLM = HKEY_LOCAL_MACHINE
  15. // HKCU = HKEY_CURRENT_USER
  16. //
  17. // HKLM\Software\Microsoft\TV System Services
  18. //
  19. //     REG_SZ (Default)  - Not used.
  20. //     REG_SZ ProductDir - Root directory for BPC software
  21. //     REG_SZ DBFile     - Full path to tss.mdb
  22. //     REG_SZ DBReplacementFile     - Full path to the empty replacement tss.mdb
  23. //     REG_SZ EPGDBFile  - Full path to epg.mdb
  24. //     REG_SZ SystemDB   - Full path to tss.mdw
  25. //     REG_SZ AMFilter   - Full path to dss.grf
  26. //
  27. // HKLM\Software\Microsoft\TV System Services\Tuning Spaces
  28. //
  29. //     REG_SZ (Default)  - Not used.
  30. //
  31. // HKLM\Software\Microsoft\TV System Services\Tuning Spaces\<iTuningSpace>
  32. //
  33. //     REG_SZ (Default)   - Not used.
  34. //     REG_SZ Name        - UNDONE
  35. //     REG_SZ Description - UNDONE
  36. //     REG_SZ Loader      - UNDONE
  37. //     REG_SZ MinChannel  - UNDONE
  38. //     REG_SZ MaxChannel  - UNDONE
  39. //     REG_SZ Devices     - UNDONE
  40. //     REG_SZ MediaType   - UNDONE
  41. //
  42. // HKLM\Software\Microsoft\TV System Services\Tuning Spaces\1
  43. //
  44. //     REG_SZ Messages - UNDONE
  45. //     REG_SZ History  - UNDONE
  46. //
  47. // HKLM\Software\Microsoft\TV System Services\EPG Loaders
  48. //
  49. //     REG_SZ (Default)               - Not used.
  50. //     REG_SZ LastAttempt             - UNDONE
  51. //     REG_BINARY LastAttemptTime     - UNDONE
  52. //     REG_SZ LastCompletion          - UNDONE
  53. //     REG_BINARY LastCompletionTime  - UNDONE
  54. //     REG_DWORD LastCompletionResult - UNDONE
  55. //     REG_BINARY EngineeringByte         - UNDONE
  56. //
  57. // HKLM\Software\Microsoft\TV System Services\EPG Loaders\<guid>
  58. //
  59. //     REG_SZ (Default)               - Not used.
  60. //     REG_SZ Name                    - UNDONE
  61. //     REG_SZ TuningID                - UNDONE
  62. //     REG_BINARY LastAttemptTime     - UNDONE
  63. //     REG_BINARY LastCompletionTime  - UNDONE
  64. //     REG_DWORD LastCompletionResult - UNDONE
  65. //
  66. // HKCU\Software\Microsoft\TV System Services
  67. //
  68. //     REG_SZ (Default)  - Not used.
  69. //
  70. // HKCU\Software\Microsoft\Microsoft TVExplorer
  71. //
  72. //     REG_SZ (Default)  - Not used.
  73. //
  74. // HKCU\Software\Microsoft\Microsoft TVExplorer\RemoteKeys
  75. //
  76. //     REG_SZ (Default)  - Not used.
  77. //
  78. // HKCU\Software\Microsoft\Microsoft TVExplorer\RemoteKeys\CommandLines
  79. //
  80. //     REG_SZ (Default)  - Not used.
  81. //     REG_SZ Guide      - UNDONE
  82. //     REG_SZ TV         - UNDONE
  83. //
  84. // HKCU\Software\Microsoft\Microsoft TVExplorer\RemoteKeys\WakeupKeys
  85. //
  86. //     REG_SZ (Default)  - Not used.
  87. //     REG_SZ Guide      - UNDONE
  88. //     REG_SZ TV         - UNDONE
  89. //
  90. // HKCU\AppEvents\Schemes\Apps\TVExplorer
  91. //
  92. //     REG_SZ (Default)  - "TV Explorer"
  93. //
  94. //-----------------------------------------------------------------------------
  95.  
  96. extern const LPCTSTR g_strBaseRegKey;
  97. extern const LPCTSTR g_strProductDir;
  98. extern const LPCTSTR g_strDBFile;
  99. extern const LPCTSTR g_strDBReplacementFile;
  100. extern const LPCTSTR g_strEPGDBFile;
  101. extern const LPCTSTR g_strDefVBITS;
  102. extern const LPCTSTR g_strDefVBIChan;
  103. extern const LPCTSTR g_strSysFile;
  104. extern const LPCTSTR g_strAMFilter;
  105. extern const LPCTSTR g_strAMFClass;
  106. extern const LPCTSTR g_strTSInputType;
  107. extern const LPCTSTR g_strCountryCode;
  108. extern const LPCTSTR g_strVolume;
  109. extern const LPCTSTR g_strBalance;
  110. extern const LPCTSTR g_strAudioPin;
  111. extern const LPCTSTR g_strTVXRegKey;
  112. extern const LPCTSTR g_strNTSC;
  113. extern const LPCTSTR g_strDistanceViewing;
  114.  
  115. extern const LPCTSTR g_strConfigRegKey;
  116. extern const LPCTSTR g_strConfigLastPage;
  117.  
  118. extern const LPCTSTR g_strTuningSpaceRegKey;
  119. extern const LPCTSTR g_strTuningSpaceName;
  120. extern const LPCTSTR g_strCurTVTuningSpace;
  121. extern const LPCTSTR g_strDSSTuningSpaceRegKey;
  122. extern const LPCTSTR g_strLCIDToSTYPE;
  123.  
  124. extern const LPCTSTR g_strCAProviderRegKey;
  125. extern const LPCTSTR g_strCAProviderName;
  126. extern const LPCTSTR g_strCAProviderDesc;
  127. extern const LPCTSTR g_strVenPrefix;
  128. extern const LPCTSTR g_strDevPrefix;
  129.  
  130. extern const LPCTSTR g_strEPGRegKey;
  131. extern const LPCTSTR g_strEPGLoadersRegKey;
  132. extern const LPCTSTR g_strEPGLoaderAttempt;
  133. extern const LPCTSTR g_strEPGLoaderAttemptTime;
  134. extern const LPCTSTR g_strEPGLoaderCompletion;
  135. extern const LPCTSTR g_strEPGLoaderCompletionTime;
  136. extern const LPCTSTR g_strEPGLoaderCompletionResult;
  137. extern const LPCTSTR g_strEPGLoaderName;
  138. extern const LPCTSTR g_strEPGLoaderTuningID;
  139. extern const LPCTSTR g_strLoaderPostalCode;
  140.  
  141. extern const LPCTSTR g_strLoaderReadPrefix;
  142. extern const LPCTSTR g_strLoaderWritePrefix;
  143. extern const LPCTSTR g_strLoaderReadFile;
  144. extern const LPCTSTR g_strDTVLoaderCSSByte;
  145. extern const LPCTSTR g_strSSLoaderRegionID;
  146. extern const LPCTSTR g_strSSLoaderChannel;
  147. extern const LPCTSTR g_strSSLoaderLine;
  148. extern const LPCTSTR g_strSSLoaderScanReturnCode;
  149. extern const LPCTSTR g_strSSLoaderListenReturnCode;
  150. extern const LPCTSTR g_strSSLoaderListenReturnCodeCount;
  151.  
  152. #ifdef _DEBUG
  153. extern const LPCTSTR g_strDEBUG;
  154. extern const LPCTSTR g_strTrace;
  155. #endif
  156.  
  157.  
  158. //-----------------------------------------------------------------------------
  159. // OpenRegKey
  160. //
  161. // Opens a registry HKEY.  There are several overloads of this function
  162. // that basically just provide defaults for the arguments to this function.
  163. //
  164. // Please use the overload that defaults as much as possible.
  165. //
  166. // The registry key is a combination of the following four parts.
  167. //
  168. //   HKEY hkeyRoot       = Optional root hkey.
  169. //                         Default: HKEY_LOCAL_MACHINE
  170. //
  171. //   LPCTSTR szKey       = Optional key to be set.
  172. //                         Default: g_strBaseRegKey
  173. //
  174. //   LPCTSTR szSubKey1
  175. //   LPCTSTR szSubKey2   = Optional sub keys that are concatenated after
  176. //                         szKey to form the full key.
  177. //                         Backward slashes are added as necessary.
  178. //
  179. //                         Default: NULL
  180. //
  181. //   Note: if only one or two strings are specified they are assumed to be
  182. //         szSubKey1 and szSubKey2.
  183. //         i.e. szKey defaults to g_strBaseRegKey before szSubKey1 and
  184. //         szSubKey2 default to NULL.
  185. //
  186. //         If szKey, szSubKey1, and szSubKey2 are NULL then this will open
  187. //         a duplicate of hkeyRoot.
  188. //
  189. // The only required argument is the destination for the returned HKEY.
  190. //
  191. //   HKEY *pkey  = The returned HKEY.
  192. //                 Remember to use RegCloseKey(*pkey) when you are finished
  193. //                 with this registry key.
  194. //
  195. // The last two arguments are optional.
  196. //
  197. //   REGSAM sam  = Desired access mask.
  198. //                 Default: KEY_ALL_ACCESS
  199. //
  200. //   BOOL fCreate = TRUE if the key should be created.
  201. //                  Default: FALSE
  202. //
  203. // Returns:
  204. //     ERROR_SUCCESS or an error code.
  205. //-----------------------------------------------------------------------------
  206. long OpenRegKey(HKEY hkeyRoot, LPCTSTR szKey, LPCTSTR szSubKey1,
  207.         LPCTSTR szSubKey2, HKEY *pkey,
  208.         REGSAM sam = KEY_ALL_ACCESS, BOOL fCreate = FALSE);
  209.  
  210. inline long OpenRegKey(LPCTSTR szKey, LPCTSTR szSubKey1, LPCTSTR szSubKey2,
  211.         HKEY *pkey, REGSAM sam = KEY_ALL_ACCESS, BOOL fCreate = FALSE)
  212. {
  213.      return OpenRegKey(HKEY_LOCAL_MACHINE, szKey, szSubKey1, szSubKey2, pkey,
  214.              sam, fCreate);
  215. }
  216.  
  217. inline long OpenRegKey(LPCTSTR szSubKey1, LPCTSTR szSubKey2,
  218.         HKEY *pkey, REGSAM sam = KEY_ALL_ACCESS, BOOL fCreate = FALSE)
  219. {
  220.      return OpenRegKey(HKEY_LOCAL_MACHINE, g_strBaseRegKey, szSubKey1,
  221.              szSubKey2, pkey, sam, fCreate);
  222. }
  223.  
  224. inline long OpenRegKey(LPCTSTR szSubKey, HKEY *pkey,
  225.         REGSAM sam = KEY_ALL_ACCESS, BOOL fCreate = FALSE)
  226. {
  227.      return OpenRegKey(HKEY_LOCAL_MACHINE, g_strBaseRegKey, szSubKey, NULL,
  228.              pkey, sam, fCreate);
  229. }
  230.  
  231. inline long OpenRegKey(HKEY *pkey, REGSAM sam = KEY_ALL_ACCESS,
  232.         BOOL fCreate = FALSE)
  233. {
  234.      return OpenRegKey(HKEY_LOCAL_MACHINE, g_strBaseRegKey, NULL, NULL,
  235.              pkey, sam, fCreate);
  236. }
  237.  
  238. //-----------------------------------------------------------------------------
  239. // OpenUserRegKey
  240. //
  241. // Same as OpenRegKey except hkeyRoot defaults to HKEY_CURRENT_USER.
  242. //-----------------------------------------------------------------------------
  243. inline long OpenUserRegKey(LPCTSTR szKey, LPCTSTR szSubKey1, LPCTSTR szSubKey2,
  244.         HKEY *pkey, REGSAM sam = KEY_ALL_ACCESS, BOOL fCreate = FALSE)
  245. {
  246.      return OpenRegKey(HKEY_CURRENT_USER, szKey, szSubKey1, szSubKey2, pkey,
  247.              sam, fCreate);
  248. }
  249.  
  250. inline long OpenUserRegKey(LPCTSTR szSubKey1, LPCTSTR szSubKey2,
  251.         HKEY *pkey, REGSAM sam = KEY_ALL_ACCESS, BOOL fCreate = FALSE)
  252. {
  253.      return OpenRegKey(HKEY_CURRENT_USER, g_strBaseRegKey, szSubKey1,
  254.              szSubKey2, pkey, sam, fCreate);
  255. }
  256.  
  257. inline long OpenUserRegKey(LPCTSTR szSubKey, HKEY *pkey,
  258.         REGSAM sam = KEY_ALL_ACCESS, BOOL fCreate = FALSE)
  259. {
  260.      return OpenRegKey(HKEY_CURRENT_USER, g_strBaseRegKey, szSubKey, NULL,
  261.              pkey, sam, fCreate);
  262. }
  263.  
  264. inline long OpenUserRegKey(HKEY *pkey, REGSAM sam = KEY_ALL_ACCESS,
  265.         BOOL fCreate = FALSE)
  266. {
  267.      return OpenRegKey(HKEY_CURRENT_USER, g_strBaseRegKey, NULL, NULL,
  268.              pkey, sam, fCreate);
  269. }
  270.  
  271. //-----------------------------------------------------------------------------
  272. // GetRegValue
  273. //
  274. // Gets data from the registry.  There are numerous overloads of this function
  275. // that basically just provide defaults for the arguments to this function.
  276. //
  277. // Please use the overload that defaults as much as possible.
  278. //
  279. // The registry key/value is a combination of the following five parts.
  280. // The first four are the same as in OpenRegKey().
  281. //
  282. //   HKEY hkeyRoot
  283. //   LPCTSTR szKey
  284. //   LPCTSTR szSubKey1
  285. //   LPCTSTR szSubKey2
  286. //
  287. //   LPCTSTR szValueName = The name of the value to be set.
  288. //                         If it is NULL then the default value for the key
  289. //                         will be set.
  290. //
  291. //                         Default: none
  292. //
  293. // There are four ways to specify where the data to be returned
  294. // depending on the type of data in the registry.
  295. //
  296. // REG_BINARY
  297. //
  298. //   BYTE *pb      = Out: The data is copied to this location.
  299. //   DWORD *pcb    = In:  Maximum size of the returned data (in bytes).
  300. //                   Out: Actual size of the data (in bytes).
  301. //
  302. // REG_SZ
  303. //
  304. //   TCHAR *psz    = Out: The string is copied to this location.
  305. //   DWORD *pcb    = In:  Maximum size of the returned data (in bytes).
  306. //                   Out: Actual size of the data (in bytes).
  307. //                   Includes the null terminator.
  308. //
  309. // REG_DWORD
  310. //
  311. //   DWORD *pdw    = Out: The data is copied to this location.
  312. //                   The length is assumed to be sizeof(DWORD).
  313. //
  314. // All other types
  315. //
  316. //   DWORD dwType  = The data type.
  317. //   BYTE *pb      = Pointer to the data.
  318. //   DWORD *pcb    = In:  Maximum size of the returned data (in bytes).
  319. //                   Out: Actual size of the data (in bytes).
  320. //                   Includes the null terminator if the data is a string type.
  321. //
  322. // Returns:
  323. //     ERROR_SUCCESS or an error code.
  324. //-----------------------------------------------------------------------------
  325. long GetRegValue(HKEY hkeyRoot, LPCTSTR szKey, LPCTSTR szSubKey1,
  326.         LPCTSTR szSubKey2, LPCTSTR szValueName,
  327.         DWORD dwType, BYTE *pb, DWORD *pcb);
  328.  
  329. //-----------------------------------------------------------------------------
  330. // REG_BINARY variants
  331. //-----------------------------------------------------------------------------
  332. inline long GetRegValue(LPCTSTR szKey, LPCTSTR szSubKey1, LPCTSTR szSubKey2,
  333.         LPCTSTR szValueName, BYTE *pb, DWORD *pcb)
  334. {
  335.     return GetRegValue(HKEY_LOCAL_MACHINE, szKey, szSubKey1, szSubKey2,
  336.             szValueName,
  337.             REG_BINARY, pb, pcb);
  338. }
  339.  
  340. inline long GetRegValue(LPCTSTR szSubKey1, LPCTSTR szSubKey2,
  341.         LPCTSTR szValueName, BYTE *pb, DWORD *pcb)
  342. {
  343.     return GetRegValue(HKEY_LOCAL_MACHINE, g_strBaseRegKey, szSubKey1,
  344.             szSubKey2, szValueName, REG_BINARY, pb, pcb);
  345. }
  346.  
  347. inline long GetRegValue(LPCTSTR szSubKey, LPCTSTR szValueName,
  348.         BYTE *pb, DWORD *pcb)
  349. {
  350.     return GetRegValue(HKEY_LOCAL_MACHINE, g_strBaseRegKey, szSubKey, NULL,
  351.             szValueName, REG_BINARY, pb, pcb);
  352. }
  353.  
  354. inline long GetRegValue(LPCTSTR szValueName, BYTE *pb, DWORD *pcb)
  355. {
  356.     return GetRegValue(HKEY_LOCAL_MACHINE, g_strBaseRegKey, NULL, NULL,
  357.             szValueName, REG_BINARY, pb, pcb);
  358. }
  359.  
  360. //-----------------------------------------------------------------------------
  361. // REG_SZ variants
  362. //-----------------------------------------------------------------------------
  363. inline long GetRegValue(LPCTSTR szKey, LPCTSTR szSubKey1, LPCTSTR szSubKey2,
  364.         LPCTSTR szValueName, TCHAR *psz, DWORD *pcb)
  365. {
  366.     return GetRegValue(HKEY_LOCAL_MACHINE, szKey, szSubKey1, szSubKey2,
  367.             szValueName, REG_SZ, (BYTE *) psz, pcb);
  368. }
  369. inline long GetRegValue(LPCTSTR szSubKey1, LPCTSTR szSubKey2,
  370.         LPCTSTR szValueName, TCHAR *psz, DWORD *pcb)
  371. {
  372.     return GetRegValue(HKEY_LOCAL_MACHINE, g_strBaseRegKey, szSubKey1,
  373.             szSubKey2, szValueName, REG_SZ, (BYTE *) psz, pcb);
  374. }
  375.  
  376. inline long GetRegValue(LPCTSTR szSubKey, LPCTSTR szValueName,
  377.         TCHAR *psz, DWORD *pcb)
  378. {
  379.     return GetRegValue(HKEY_LOCAL_MACHINE, g_strBaseRegKey, szSubKey, NULL,
  380.             szValueName, REG_SZ, (BYTE *)psz, pcb);
  381. }
  382.  
  383. #if 0
  384. inline long GetRegValue(HKEY hk, LPCTSTR szValueName,
  385.         TCHAR *psz, DWORD *pcb)
  386. {
  387.     return GetRegValue(hk, NULL, NULLy, NULL,
  388.             szValueName, REG_SZ, (BYTE *)psz, pcb);
  389. }
  390. #endif
  391.  
  392. inline long GetRegValue(LPCTSTR szValueName, TCHAR *psz, DWORD *pcb)
  393. {
  394.     return GetRegValue(HKEY_LOCAL_MACHINE, g_strBaseRegKey, NULL, NULL,
  395.             szValueName, REG_SZ, (BYTE *) psz, pcb);
  396. }
  397.  
  398. //-----------------------------------------------------------------------------
  399. // REG_DWORD variants
  400. //-----------------------------------------------------------------------------
  401. inline long GetRegValue(LPCTSTR szKey, LPCTSTR szSubKey1, LPCTSTR szSubKey2,
  402.         LPCTSTR szValueName, DWORD *pdw)
  403. {
  404.     DWORD cb = sizeof(DWORD);
  405.  
  406.     return GetRegValue(HKEY_LOCAL_MACHINE, szKey, szSubKey1, szSubKey2,
  407.             szValueName, REG_DWORD, (BYTE *) pdw, &cb);
  408. }
  409.  
  410. inline long GetRegValue(LPCTSTR szSubKey1, LPCTSTR szSubKey2,
  411.         LPCTSTR szValueName, DWORD *pdw)
  412. {
  413.     DWORD cb = sizeof(DWORD);
  414.  
  415.     return GetRegValue(HKEY_LOCAL_MACHINE, g_strBaseRegKey, szSubKey1,
  416.             szSubKey2, szValueName, REG_DWORD, (BYTE *) pdw, &cb);
  417. }
  418.  
  419.  
  420. inline long GetRegValue(LPCTSTR szSubKey, LPCTSTR szValueName, DWORD *pdw)
  421. {
  422.     DWORD cb = sizeof(DWORD);
  423.  
  424.     return GetRegValue(HKEY_LOCAL_MACHINE, g_strBaseRegKey, szSubKey, NULL,
  425.             szValueName, REG_DWORD, (BYTE *) pdw, &cb);
  426. }
  427.  
  428. inline long GetRegValue(LPCTSTR szValueName, DWORD *pdw)
  429. {
  430.     DWORD cb = sizeof(DWORD);
  431.  
  432.     return GetRegValue(HKEY_LOCAL_MACHINE, g_strBaseRegKey, NULL, NULL,
  433.             szValueName, REG_DWORD, (BYTE *) pdw, &cb);
  434. }
  435.  
  436. //-----------------------------------------------------------------------------
  437. // The following variants are for getting values from an already open key.
  438. //-----------------------------------------------------------------------------
  439. inline long GetRegValue(HKEY hkey, LPCTSTR szKey, LPCTSTR szSubKey,
  440.         LPCTSTR szValueName, TCHAR *psz, DWORD *pcb)
  441. {
  442.     return GetRegValue(hkey, szKey, szSubKey, NULL, szValueName,
  443.             REG_SZ, (BYTE *) psz, pcb);
  444. }
  445.  
  446. inline long GetRegValue(HKEY hkey, LPCTSTR szValueName, BYTE *pb, DWORD *pcb)
  447. {
  448.     return GetRegValue(hkey, NULL, NULL, NULL, szValueName,
  449.             REG_BINARY, pb, pcb);
  450. }
  451.  
  452. inline long GetRegValue(HKEY hkey, LPCTSTR szValueName, TCHAR *psz, DWORD *pcb)
  453. {
  454.     return GetRegValue(hkey, NULL, NULL, NULL, szValueName,
  455.             REG_SZ, (BYTE *) psz, pcb);
  456. }
  457.  
  458. inline long GetRegValue(HKEY hkey, LPCTSTR szValueName, DWORD *pdw)
  459. {
  460.     DWORD cb = sizeof(DWORD);
  461.  
  462.     return GetRegValue(hkey, NULL, NULL, NULL, szValueName,
  463.             REG_DWORD, (BYTE *) pdw, &cb);
  464. }
  465.  
  466. //-----------------------------------------------------------------------------
  467. // GetUserRegValue
  468. //
  469. // Same as GetRegValue except hkeyRoot defaults to HKEY_CURRENT_USER.
  470. //-----------------------------------------------------------------------------
  471. //-----------------------------------------------------------------------------
  472. // REG_BINARY variants
  473. //-----------------------------------------------------------------------------
  474. inline long GetUserRegValue(LPCTSTR szKey, LPCTSTR szSubKey1, LPCTSTR szSubKey2,
  475.         LPCTSTR szValueName, BYTE *pb, DWORD *pcb)
  476. {
  477.     return GetRegValue(HKEY_CURRENT_USER, szKey, szSubKey1, szSubKey2,
  478.             szValueName,
  479.             REG_BINARY, pb, pcb);
  480. }
  481.  
  482. inline long GetUserRegValue(LPCTSTR szSubKey1, LPCTSTR szSubKey2,
  483.         LPCTSTR szValueName, BYTE *pb, DWORD *pcb)
  484. {
  485.     return GetRegValue(HKEY_CURRENT_USER, g_strBaseRegKey, szSubKey1,
  486.             szSubKey2, szValueName, REG_BINARY, pb, pcb);
  487. }
  488.  
  489. inline long GetUserRegValue(LPCTSTR szSubKey, LPCTSTR szValueName,
  490.         BYTE *pb, DWORD *pcb)
  491. {
  492.     return GetRegValue(HKEY_CURRENT_USER, g_strBaseRegKey, szSubKey, NULL,
  493.             szValueName, REG_BINARY, pb, pcb);
  494. }
  495.  
  496. inline long GetUserRegValue(LPCTSTR szValueName, BYTE *pb, DWORD *pcb)
  497. {
  498.     return GetRegValue(HKEY_CURRENT_USER, g_strBaseRegKey, NULL, NULL,
  499.             szValueName, REG_BINARY, pb, pcb);
  500. }
  501.  
  502. //-----------------------------------------------------------------------------
  503. // REG_SZ variants
  504. //-----------------------------------------------------------------------------
  505. inline long GetUserRegValue(LPCTSTR szKey, LPCTSTR szSubKey1, LPCTSTR szSubKey2,
  506.         LPCTSTR szValueName, TCHAR *psz, DWORD *pcb)
  507. {
  508.     return GetRegValue(HKEY_CURRENT_USER, szKey, szSubKey1, szSubKey2,
  509.             szValueName, REG_SZ, (BYTE *) psz, pcb);
  510. }
  511. inline long GetUserRegValue(LPCTSTR szSubKey1, LPCTSTR szSubKey2,
  512.         LPCTSTR szValueName, TCHAR *psz, DWORD *pcb)
  513. {
  514.     return GetRegValue(HKEY_CURRENT_USER, g_strBaseRegKey, szSubKey1,
  515.             szSubKey2, szValueName, REG_SZ, (BYTE *) psz, pcb);
  516. }
  517.  
  518. inline long GetUserRegValue(LPCTSTR szSubKey, LPCTSTR szValueName,
  519.         TCHAR *psz, DWORD *pcb)
  520. {
  521.     return GetRegValue(HKEY_CURRENT_USER, g_strBaseRegKey, szSubKey, NULL,
  522.             szValueName, REG_SZ, (BYTE *)psz, pcb);
  523. }
  524.  
  525. inline long GetUserRegValue(LPCTSTR szValueName, TCHAR *psz, DWORD *pcb)
  526. {
  527.     return GetRegValue(HKEY_CURRENT_USER, g_strBaseRegKey, NULL, NULL,
  528.             szValueName, REG_SZ, (BYTE *) psz, pcb);
  529. }
  530.  
  531. //-----------------------------------------------------------------------------
  532. // REG_DWORD variants
  533. //-----------------------------------------------------------------------------
  534. inline long GetUserRegValue(LPCTSTR szKey, LPCTSTR szSubKey1, LPCTSTR szSubKey2,
  535.         LPCTSTR szValueName, DWORD *pdw)
  536. {
  537.     DWORD cb = sizeof(DWORD);
  538.  
  539.     return GetRegValue(HKEY_CURRENT_USER, szKey, szSubKey1, szSubKey2,
  540.             szValueName, REG_DWORD, (BYTE *) pdw, &cb);
  541. }
  542.  
  543. inline long GetUserRegValue(LPCTSTR szSubKey1, LPCTSTR szSubKey2,
  544.         LPCTSTR szValueName, DWORD *pdw)
  545. {
  546.     DWORD cb = sizeof(DWORD);
  547.  
  548.     return GetRegValue(HKEY_CURRENT_USER, g_strBaseRegKey, szSubKey1,
  549.             szSubKey2, szValueName, REG_DWORD, (BYTE *) pdw, &cb);
  550. }
  551.  
  552.  
  553. inline long GetUserRegValue(LPCTSTR szSubKey, LPCTSTR szValueName, DWORD *pdw)
  554. {
  555.     DWORD cb = sizeof(DWORD);
  556.  
  557.     return GetRegValue(HKEY_CURRENT_USER, g_strBaseRegKey, szSubKey, NULL,
  558.             szValueName, REG_DWORD, (BYTE *) pdw, &cb);
  559. }
  560.  
  561. inline long GetUserRegValue(LPCTSTR szValueName, DWORD *pdw)
  562. {
  563.     DWORD cb = sizeof(DWORD);
  564.  
  565.     return GetRegValue(HKEY_CURRENT_USER, g_strBaseRegKey, NULL, NULL,
  566.             szValueName, REG_DWORD, (BYTE *) pdw, &cb);
  567. }
  568.  
  569. inline long GetUserRegValue(LPCTSTR szSubKey, LPCTSTR szValueName, DWORD &dw)
  570. {
  571.     DWORD cb = sizeof(DWORD);
  572.  
  573.     return GetRegValue(HKEY_CURRENT_USER, g_strBaseRegKey, szSubKey, NULL,
  574.             szValueName, REG_DWORD, (BYTE *) &dw, &cb);
  575. }
  576.  
  577. inline long GetUserRegValue(LPCTSTR szValueName, DWORD &dw)
  578. {
  579.     DWORD cb = sizeof(DWORD);
  580.  
  581.     return GetRegValue(HKEY_CURRENT_USER, g_strBaseRegKey, NULL, NULL,
  582.             szValueName, REG_DWORD, (BYTE *) &dw, &cb);
  583. }
  584.  
  585. //-----------------------------------------------------------------------------
  586. // SetRegValue
  587. //
  588. // Sets data into the registry.  There are numerous overloads of this function
  589. // that basically just provide defaults for the arguments to this function.
  590. //
  591. // Please use the overload that defaults as much as possible.
  592. //
  593. // The registry key/value is a combination of the following five parts.
  594. // The first four are the same as in OpenRegKey().
  595. //
  596. //   HKEY hkeyRoot
  597. //   LPCTSTR szKey
  598. //   LPCTSTR szSubKey1
  599. //   LPCTSTR szSubKey2
  600. //
  601. //   LPCTSTR szValueName = The name of the value to be set.
  602. //                         If it is NULL then the default value for the key
  603. //                         will be set.
  604. //
  605. //                         Default: none
  606. //
  607. // There are four ways to specify the data to be set into the registry
  608. // depending on the type of data being stored.
  609. //
  610. // REG_BINARY
  611. //
  612. //   BYTE *pb      = Pointer to the data.
  613. //   DWORD cb      = Actual size of the data (in bytes).
  614. //
  615. // REG_SZ
  616. //
  617. //   TCHAR *psz    = The data is written as type REG_SZ.
  618. //                   The length is calculated as _tcsclen(psz) + sizeof(TCHAR).
  619. //
  620. // REG_DWORD
  621. //
  622. //   DWORD dw      = The data is written as type DWORD.
  623. //                   The length is calculated as sizeof(DWORD).
  624. //
  625. // All other types
  626. //
  627. //   DWORD dwType  = The data type.
  628. //   BYTE *pb      = Pointer to the data.
  629. //   DWORD cb      = Actual size of the data in bytes.
  630. //
  631. // Returns:
  632. //     ERROR_SUCCESS or an error code.
  633. //-----------------------------------------------------------------------------
  634. long SetRegValue(HKEY hkeyRoot, LPCTSTR szKey, LPCTSTR szSubKey1,
  635.         LPCTSTR szSubKey2, LPCTSTR szValueName,
  636.         DWORD dwType, const BYTE *pb, DWORD cb);
  637.  
  638. //-----------------------------------------------------------------------------
  639. // REG_BINARY variants
  640. //-----------------------------------------------------------------------------
  641. inline long SetRegValue(LPCTSTR szKey, LPCTSTR szSubKey1, LPCTSTR szSubKey2,
  642.         LPCTSTR szValueName, const BYTE *pb, DWORD cb)
  643. {
  644.     return SetRegValue(HKEY_LOCAL_MACHINE, szKey, szSubKey1, szSubKey2,
  645.             szValueName, REG_BINARY, pb, cb);
  646. }
  647.  
  648. inline long SetRegValue(LPCTSTR szSubKey1, LPCTSTR szSubKey2,
  649.         LPCTSTR szValueName, const BYTE *pb, DWORD cb)
  650. {
  651.     return SetRegValue(HKEY_LOCAL_MACHINE, g_strBaseRegKey, szSubKey1,
  652.             szSubKey2, szValueName, REG_BINARY, pb, cb);
  653. }
  654.  
  655. inline long SetRegValue(LPCTSTR szSubKey, LPCTSTR szValueName,
  656.         const BYTE *pb, DWORD cb)
  657. {
  658.     return SetRegValue(HKEY_LOCAL_MACHINE, g_strBaseRegKey, szSubKey, NULL,
  659.             szValueName, REG_BINARY, pb, cb);
  660. }
  661.  
  662. inline long SetRegValue(LPCTSTR szValueName, const BYTE *pb, DWORD cb)
  663. {
  664.     return SetRegValue(HKEY_LOCAL_MACHINE, g_strBaseRegKey, NULL, NULL,
  665.             szValueName, REG_BINARY, pb, cb);
  666. }
  667.  
  668. //-----------------------------------------------------------------------------
  669. // REG_SZ variants
  670. //-----------------------------------------------------------------------------
  671. inline long SetRegValue(LPCTSTR szKey, LPCTSTR szSubKey1, LPCTSTR szSubKey2,
  672.         LPCTSTR szValueName, const TCHAR *psz)
  673. {
  674.     return SetRegValue(HKEY_LOCAL_MACHINE,
  675.             szKey, szSubKey1, szSubKey2, szValueName,
  676.             REG_SZ, (const BYTE *) psz, _tcsclen(psz) + sizeof(TCHAR));
  677. }
  678. inline long SetRegValue(LPCTSTR szSubKey1, LPCTSTR szSubKey2,
  679.         LPCTSTR szValueName, const TCHAR *psz)
  680. {
  681.     return SetRegValue(HKEY_LOCAL_MACHINE, g_strBaseRegKey,
  682.             szSubKey1, szSubKey2, szValueName,
  683.             REG_SZ, (const BYTE *) psz, _tcsclen(psz) + sizeof(TCHAR));
  684. }
  685.  
  686. inline long SetRegValue(LPCTSTR szSubKey, LPCTSTR szValueName, const TCHAR *psz)
  687. {
  688.     return SetRegValue(HKEY_LOCAL_MACHINE,
  689.             g_strBaseRegKey, szSubKey, NULL, szValueName,
  690.             REG_SZ, (const BYTE *)psz, _tcsclen(psz) + sizeof(TCHAR));
  691. }
  692.  
  693. inline long SetRegValue(LPCTSTR szValueName, const TCHAR *psz)
  694. {
  695.     return SetRegValue(HKEY_LOCAL_MACHINE,
  696.             g_strBaseRegKey, NULL, NULL, szValueName,
  697.             REG_SZ, (const BYTE *) psz, _tcsclen(psz) + sizeof(TCHAR));
  698. }
  699.  
  700. //-----------------------------------------------------------------------------
  701. // REG_DWORD variants
  702. //-----------------------------------------------------------------------------
  703. inline long SetRegValue(LPCTSTR szKey, LPCTSTR szSubKey1, LPCTSTR szSubKey2,
  704.         LPCTSTR szValueName, DWORD dw)
  705. {
  706.     return SetRegValue(HKEY_LOCAL_MACHINE,
  707.             szKey, szSubKey1, szSubKey2, szValueName,
  708.             REG_DWORD, (BYTE *) &dw, sizeof(DWORD));
  709. }
  710.  
  711. inline long SetRegValue(LPCTSTR szSubKey1, LPCTSTR szSubKey2,
  712.         LPCTSTR szValueName, DWORD dw)
  713. {
  714.     return SetRegValue(HKEY_LOCAL_MACHINE,
  715.             g_strBaseRegKey, szSubKey1, szSubKey2, szValueName,
  716.             REG_DWORD, (BYTE *) &dw, sizeof(DWORD));
  717. }
  718.  
  719. inline long SetRegValue(LPCTSTR szSubKey, LPCTSTR szValueName, DWORD dw)
  720. {
  721.     return SetRegValue(HKEY_LOCAL_MACHINE,
  722.             g_strBaseRegKey, szSubKey, NULL, szValueName,
  723.             REG_DWORD, (const BYTE *) &dw, sizeof(DWORD));
  724. }
  725.  
  726. inline long SetRegValue(LPCTSTR szValueName, DWORD dw)
  727. {
  728.     return SetRegValue(HKEY_LOCAL_MACHINE,
  729.             g_strBaseRegKey, NULL, NULL, szValueName,
  730.             REG_DWORD, (const BYTE *) &dw, sizeof(DWORD));
  731. }
  732.  
  733. //-----------------------------------------------------------------------------
  734. // The following variants are for setting values in an already open key.
  735. //-----------------------------------------------------------------------------
  736. inline long SetRegValue(HKEY hkey, LPCTSTR szValueName, const BYTE *pb, DWORD cb)
  737. {
  738.     return SetRegValue(hkey, NULL, NULL, NULL, szValueName,
  739.             REG_BINARY, pb, cb);
  740. }
  741.  
  742. inline long SetRegValue(HKEY hkey, LPCTSTR szValueName, const TCHAR *psz)
  743. {
  744.     return SetRegValue(hkey, NULL, NULL, NULL, szValueName,
  745.             REG_SZ, (const BYTE *) psz, _tcsclen(psz) + sizeof(TCHAR));
  746. }
  747.  
  748. inline long SetRegValue(HKEY hkey, LPCTSTR szValueName, DWORD dw)
  749. {
  750.     return SetRegValue(hkey, NULL, NULL, NULL, szValueName,
  751.             REG_DWORD, (const BYTE *) &dw, sizeof(DWORD));
  752. }
  753.  
  754. //-----------------------------------------------------------------------------
  755. // SetUserRegValue
  756. //
  757. // Same as SetRegValue except hkeyRoot defaults to HKEY_CURRENT_USER.
  758. //-----------------------------------------------------------------------------
  759. //-----------------------------------------------------------------------------
  760. // REG_BINARY variants
  761. //-----------------------------------------------------------------------------
  762. inline long SetUserRegValue(LPCTSTR szKey, LPCTSTR szSubKey1, LPCTSTR szSubKey2,
  763.         LPCTSTR szValueName, const BYTE *pb, DWORD cb)
  764. {
  765.     return SetRegValue(HKEY_CURRENT_USER, szKey, szSubKey1, szSubKey2,
  766.             szValueName, REG_BINARY, pb, cb);
  767. }
  768.  
  769. inline long SetUserRegValue(LPCTSTR szSubKey1, LPCTSTR szSubKey2,
  770.         LPCTSTR szValueName, const BYTE *pb, DWORD cb)
  771. {
  772.     return SetRegValue(HKEY_CURRENT_USER, g_strBaseRegKey, szSubKey1,
  773.             szSubKey2, szValueName, REG_BINARY, pb, cb);
  774. }
  775.  
  776. inline long SetUserRegValue(LPCTSTR szSubKey, LPCTSTR szValueName,
  777.         const BYTE *pb, DWORD cb)
  778. {
  779.     return SetRegValue(HKEY_CURRENT_USER, g_strBaseRegKey, szSubKey, NULL,
  780.             szValueName, REG_BINARY, pb, cb);
  781. }
  782.  
  783. inline long SetUserRegValue(LPCTSTR szValueName, const BYTE *pb, DWORD cb)
  784. {
  785.     return SetRegValue(HKEY_CURRENT_USER, g_strBaseRegKey, NULL, NULL,
  786.             szValueName, REG_BINARY, pb, cb);
  787. }
  788.  
  789. //-----------------------------------------------------------------------------
  790. // REG_SZ variants
  791. //-----------------------------------------------------------------------------
  792. inline long SetUserRegValue(LPCTSTR szKey, LPCTSTR szSubKey1, LPCTSTR szSubKey2,
  793.         LPCTSTR szValueName, const TCHAR *psz)
  794. {
  795.     return SetRegValue(HKEY_CURRENT_USER,
  796.             szKey, szSubKey1, szSubKey2, szValueName,
  797.             REG_SZ, (const BYTE *) psz, _tcsclen(psz) + sizeof(TCHAR));
  798. }
  799. inline long SetUserRegValue(LPCTSTR szSubKey1, LPCTSTR szSubKey2,
  800.         LPCTSTR szValueName, const TCHAR *psz)
  801. {
  802.     return SetRegValue(HKEY_CURRENT_USER, g_strBaseRegKey,
  803.             szSubKey1, szSubKey2, szValueName,
  804.             REG_SZ, (const BYTE *) psz, _tcsclen(psz) + sizeof(TCHAR));
  805. }
  806.  
  807. inline long SetUserRegValue(LPCTSTR szSubKey, LPCTSTR szValueName, const TCHAR *psz)
  808. {
  809.     return SetRegValue(HKEY_CURRENT_USER,
  810.             g_strBaseRegKey, szSubKey, NULL, szValueName,
  811.             REG_SZ, (const BYTE *)psz, _tcsclen(psz) + sizeof(TCHAR));
  812. }
  813.  
  814. inline long SetUserRegValue(LPCTSTR szValueName, const TCHAR *psz)
  815. {
  816.     return SetRegValue(HKEY_CURRENT_USER,
  817.             g_strBaseRegKey, NULL, NULL, szValueName,
  818.             REG_SZ, (const BYTE *) psz, _tcsclen(psz) + sizeof(TCHAR));
  819. }
  820.  
  821. //-----------------------------------------------------------------------------
  822. // REG_DWORD variants
  823. //-----------------------------------------------------------------------------
  824. inline long SetUserRegValue(LPCTSTR szKey, LPCTSTR szSubKey1, LPCTSTR szSubKey2,
  825.         LPCTSTR szValueName, DWORD dw)
  826. {
  827.     return SetRegValue(HKEY_CURRENT_USER,
  828.             szKey, szSubKey1, szSubKey2, szValueName,
  829.             REG_DWORD, (BYTE *) &dw, sizeof(DWORD));
  830. }
  831.  
  832. inline long SetUserRegValue(LPCTSTR szSubKey1, LPCTSTR szSubKey2,
  833.         LPCTSTR szValueName, DWORD dw)
  834. {
  835.     return SetRegValue(HKEY_CURRENT_USER,
  836.             g_strBaseRegKey, szSubKey1, szSubKey2, szValueName,
  837.             REG_DWORD, (BYTE *) &dw, sizeof(DWORD));
  838. }
  839.  
  840. inline long SetUserRegValue(LPCTSTR szSubKey, LPCTSTR szValueName, DWORD dw)
  841. {
  842.     return SetRegValue(HKEY_CURRENT_USER,
  843.             g_strBaseRegKey, szSubKey, NULL, szValueName,
  844.             REG_DWORD, (const BYTE *) &dw, sizeof(DWORD));
  845. }
  846.  
  847. inline long SetUserRegValue(LPCTSTR szValueName, DWORD dw)
  848. {
  849.     return SetRegValue(HKEY_CURRENT_USER,
  850.             g_strBaseRegKey, NULL, NULL, szValueName,
  851.             REG_DWORD, (const BYTE *) &dw, sizeof(DWORD));
  852. }
  853.  
  854. #endif // BPCREG_H
  855.