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.

122 lines
3.3 KiB

  1. //
  2. // Registry.h
  3. //
  4. #pragma once
  5. #ifdef __cplusplus
  6. // Note: For strong type checking in the Query functions, #define _REG_STRONGTYPES
  7. #ifndef _REG_STRONGTYPES
  8. #define _REG_STRONGTYPES 1
  9. #endif
  10. // Set _REG_ALLOCMEM to 0 to disable functions which allocate memory
  11. #ifndef _REG_ALLOCMEM
  12. #define _REG_ALLOCMEM 1
  13. #endif
  14. class CRegistry
  15. {
  16. public:
  17. CRegistry();
  18. CRegistry(HKEY hkeyParent, LPCTSTR pszKey, DWORD dwAccessFlags = KEY_ALL_ACCESS, BOOL bCreateIfMissing = TRUE);
  19. ~CRegistry();
  20. void CloseKey();
  21. BOOL OpenKey(HKEY hkeyParent, LPCTSTR pszKey, REGSAM dwAccessFlags = KEY_ALL_ACCESS);
  22. BOOL CreateKey(HKEY hkeyParent, LPCTSTR pszKey, REGSAM dwAccessFlags = KEY_ALL_ACCESS);
  23. BOOL OpenSubKey(LPCTSTR pszKey, REGSAM dwAccessFlags = KEY_ALL_ACCESS);
  24. BOOL CreateSubKey(LPCTSTR pszKey, REGSAM dwAccessFlags = KEY_ALL_ACCESS);
  25. BOOL DeleteSubKey(LPCTSTR pszKey);
  26. DWORD GetValueSize(LPCTSTR pszValueName);
  27. BOOL DoesValueExist(LPCTSTR pszValueName);
  28. BOOL DeleteValue(LPCTSTR pszValueName);
  29. #ifdef _AFX
  30. BOOL QueryStringValue(LPCTSTR pszValueName, CString& strResult);
  31. CString QueryStringValue(LPCTSTR pszValueName);
  32. BOOL SetStringValue(LPCTSTR pszValueName, const CString& strData);
  33. #endif
  34. BOOL QueryStringValue(LPCTSTR pszValueName, LPTSTR pszBuf, int cchBuf, int* pNumCharsWritten);
  35. int QueryStringValue(LPCTSTR pszValueName, LPTSTR pszBuf, int cchBuf);
  36. BOOL SetStringValue(LPCTSTR pszValueName, LPCTSTR pszData);
  37. LPTSTR QueryStringValue(LPCTSTR pszValueName, int* pNumCharsWritten);
  38. DWORD QueryDwordValue(LPCTSTR pszValueName, DWORD dwDefault = 0);
  39. BOOL QueryDwordValue(LPCTSTR pszValueName, DWORD* pVal);
  40. BOOL SetDwordValue(LPCTSTR pszValueName, DWORD dwVal);
  41. BOOL SetBinaryValue(LPCTSTR pszValueName, LPCVOID pvData, DWORD cbData);
  42. int QueryIntValue(LPCTSTR pszValueName);
  43. BOOL QueryIntValue(LPCTSTR pszValueName, int* pVal);
  44. BOOL SetIntValue(LPCTSTR pszValueName, int nVal);
  45. BOOL DeleteAllValues();
  46. BOOL CloneSubKey(LPCTSTR pszExistingSubKey, CRegistry& regDest, BOOL bRecursive);
  47. BOOL CloneSubKey(LPCTSTR pszExistingSubKey, LPCTSTR pszNewSubKey, BOOL bRecursive);
  48. public:
  49. HKEY m_hKey;
  50. };
  51. //
  52. // Inline functions
  53. //
  54. inline CRegistry::CRegistry()
  55. {
  56. m_hKey = NULL;
  57. }
  58. inline BOOL CRegistry::DoesValueExist(LPCTSTR pszValueName)
  59. {
  60. return (BOOL)GetValueSize(pszValueName);
  61. }
  62. inline BOOL CRegistry::DeleteValue(LPCTSTR pszValueName)
  63. {
  64. if (m_hKey)
  65. return (ERROR_SUCCESS == RegDeleteValue(m_hKey, pszValueName));
  66. else
  67. return FALSE;
  68. }
  69. inline int CRegistry::QueryStringValue(LPCTSTR pszValueName, LPTSTR pszBuf, int cchBuf)
  70. {
  71. if (QueryStringValue(pszValueName, pszBuf, cchBuf, &cchBuf))
  72. return cchBuf;
  73. else
  74. return 0;
  75. }
  76. inline DWORD CRegistry::QueryDwordValue(LPCTSTR pszValueName, DWORD dwDefault /*=0*/)
  77. {
  78. DWORD dwVal = dwDefault;
  79. QueryDwordValue(pszValueName, &dwVal);
  80. return dwVal;
  81. }
  82. inline int CRegistry::QueryIntValue(LPCTSTR pszValueName)
  83. {
  84. return (int)QueryDwordValue(pszValueName);
  85. }
  86. inline BOOL CRegistry::QueryIntValue(LPCTSTR pszValueName, int* pVal)
  87. {
  88. return QueryDwordValue(pszValueName, (DWORD*)pVal);
  89. }
  90. inline BOOL CRegistry::SetIntValue(LPCTSTR pszValueName, int nVal)
  91. {
  92. return SetDwordValue(pszValueName, (DWORD)nVal);
  93. }
  94. #endif // __cplusplus