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.

113 lines
3.5 KiB

  1. #include "stdafx.h"
  2. #include "DXSvr.h"
  3. /*
  4. //***************************************************************************************
  5. GUID GetRegistryGUID(LPCSTR szName , const GUID& guidDefault)
  6. {
  7. HKEY hKey;
  8. GUID guidReturn = guidDefault;
  9. if (RegOpenKeyEx(HKEY_CURRENT_USER , g_szKeyname , 0 , KEY_READ , &hKey) == ERROR_SUCCESS)
  10. {
  11. GUID guidValue;
  12. DWORD dwValueSize = sizeof(GUID);
  13. DWORD dwType;
  14. if ((RegQueryValueEx(hKey , szName , 0 , &dwType , (LPBYTE) &guidValue , &dwValueSize) == ERROR_SUCCESS)
  15. && (dwType == REG_BINARY || dwType == REG_NONE))
  16. {
  17. guidReturn = guidValue;
  18. }
  19. RegCloseKey(hKey);
  20. }
  21. return guidReturn;
  22. }
  23. //***************************************************************************************
  24. void SetRegistryGUID(LPCSTR szName , const GUID& guidValue)
  25. {
  26. HKEY hKey;
  27. DWORD dwDisposition;
  28. if ((RegCreateKeyEx(HKEY_CURRENT_USER , g_szKeyname , 0 , NULL , REG_OPTION_NON_VOLATILE ,
  29. KEY_WRITE , NULL , &hKey , &dwDisposition) == ERROR_SUCCESS))
  30. {
  31. RegSetValueEx(hKey , szName , 0 , REG_BINARY , (CONST BYTE*)(&guidValue) , sizeof(GUID));
  32. RegCloseKey(hKey);
  33. }
  34. }
  35. //***************************************************************************************
  36. int GetRegistryInt(LPCSTR szName , int iDefault)
  37. {
  38. HKEY hKey;
  39. int iReturn = iDefault;
  40. if (RegOpenKeyEx(HKEY_CURRENT_USER , g_szKeyname , 0 , KEY_READ , &hKey) == ERROR_SUCCESS)
  41. {
  42. int iValue;
  43. DWORD dwValueSize = sizeof(int);
  44. DWORD dwType;
  45. if ((RegQueryValueEx(hKey , szName , 0 , &dwType , (LPBYTE) &iValue , &dwValueSize) == ERROR_SUCCESS)
  46. && dwType == REG_DWORD)
  47. {
  48. iReturn = iValue;
  49. }
  50. RegCloseKey(hKey);
  51. }
  52. return iReturn;
  53. }
  54. //***************************************************************************************
  55. void SetRegistryInt(LPCSTR szName , int iValue)
  56. {
  57. HKEY hKey;
  58. DWORD dwDisposition;
  59. if ((RegCreateKeyEx(HKEY_CURRENT_USER , g_szKeyname , 0 , NULL , REG_OPTION_NON_VOLATILE ,
  60. KEY_WRITE , NULL , &hKey , &dwDisposition) == ERROR_SUCCESS))
  61. {
  62. RegSetValueEx(hKey , szName , 0 , REG_DWORD , (CONST BYTE*)(&iValue) , sizeof(DWORD));
  63. RegCloseKey(hKey);
  64. }
  65. }
  66. //***************************************************************************************
  67. void GetRegistryString(LPCSTR szName , LPSTR szBuffer , DWORD dwBufferLength , LPCSTR szDefault)
  68. {
  69. HKEY hKey;
  70. if (RegOpenKeyEx(HKEY_CURRENT_USER , g_szKeyname , 0 , KEY_READ , &hKey) == ERROR_SUCCESS)
  71. {
  72. DWORD dwType;
  73. if ((RegQueryValueEx(hKey , szName , 0 , &dwType , (LPBYTE) szBuffer , &dwBufferLength) != ERROR_SUCCESS)
  74. || (dwType != REG_SZ && dwType != REG_NONE))
  75. {
  76. strcpy(szBuffer , szDefault);
  77. }
  78. RegCloseKey(hKey);
  79. }
  80. else
  81. strcpy(szBuffer , szDefault);
  82. }
  83. //***************************************************************************************
  84. void SetRegistryString(LPCTSTR szName , LPCTSTR szValue)
  85. {
  86. HKEY hKey;
  87. DWORD dwDisposition;
  88. if ((RegCreateKeyEx(HKEY_CURRENT_USER , g_szKeyname , 0 , NULL , REG_OPTION_NON_VOLATILE ,
  89. KEY_WRITE , NULL , &hKey , &dwDisposition) == ERROR_SUCCESS))
  90. {
  91. RegSetValueEx(hKey , szName , 0 , REG_SZ , (CONST BYTE*)szValue , strlen(szValue)+1);
  92. RegCloseKey(hKey);
  93. }
  94. }
  95. */