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.

84 lines
1.8 KiB

  1. #ifndef _CREGISTRY_H
  2. #define _CREGISTRY_H
  3. class CRegistry {
  4. public:
  5. CRegistry(LPTSTR szHomeRegistryKey)
  6. {
  7. DWORD dwDisposition = 0;
  8. LONG ErrorResult = RegCreateKeyEx(
  9. HKEY_CURRENT_USER,
  10. szHomeRegistryKey,
  11. 0,
  12. NULL,
  13. REG_OPTION_NON_VOLATILE,
  14. KEY_ALL_ACCESS,
  15. NULL,
  16. &m_hHomeKey,
  17. &dwDisposition);
  18. m_bReady = (ErrorResult == ERROR_SUCCESS);
  19. }
  20. ~CRegistry()
  21. {
  22. if(NULL != m_hHomeKey){
  23. RegCloseKey(m_hHomeKey);
  24. }
  25. }
  26. LONG ReadStringValue(LPTSTR szValueName, LPTSTR szValue, DWORD dwBufferSize)
  27. {
  28. DWORD Type = REG_SZ;
  29. LONG ErrorResult = RegQueryValueEx(m_hHomeKey,
  30. szValueName,
  31. NULL,
  32. &Type,
  33. (LPBYTE)szValue,
  34. &dwBufferSize);
  35. return ErrorResult;
  36. }
  37. LONG ReadLongValue(LPTSTR szValueName)
  38. {
  39. DWORD dwBufferSize = sizeof(LONG);
  40. DWORD Type = REG_DWORD;
  41. LONG ReturnValue = 0;
  42. LONG ErrorResult = RegQueryValueEx(m_hHomeKey,
  43. szValueName,
  44. NULL,
  45. &Type,
  46. (LPBYTE)&ReturnValue,
  47. &dwBufferSize);
  48. return ReturnValue;
  49. }
  50. LONG WriteStringValue(LPTSTR szValueName, LPTSTR szValue)
  51. {
  52. return RegSetValueEx(m_hHomeKey,
  53. szValueName,
  54. 0,
  55. REG_SZ,
  56. (LPBYTE)szValue,
  57. lstrlen(szValue) + 1);
  58. }
  59. LONG WriteLongValue(LPTSTR szValueName, LONG lValue)
  60. {
  61. return RegSetValueEx(m_hHomeKey,
  62. szValueName,
  63. 0,
  64. REG_DWORD,
  65. (LPBYTE)&lValue,
  66. sizeof(LONG));
  67. }
  68. private:
  69. HKEY m_hHomeKey;
  70. HKEY m_CurrentKey;
  71. BOOL m_bReady;
  72. protected:
  73. };
  74. #endif