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.

175 lines
3.0 KiB

  1. /*++
  2. Copyright (c) 1993 Microsoft Corporation
  3. Module Name:
  4. bkprof.c
  5. Abstract:
  6. Profile routines for online books program
  7. Author:
  8. Ted Miller (tedm) 5-Jan-1995
  9. Revision History:
  10. --*/
  11. #include "books.h"
  12. //
  13. // Registry key where profile values are stored.
  14. //
  15. PWSTR BooksProfileKeyName = L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Online Books";
  16. //
  17. // Name of profile value that stores the last known location
  18. // of the online books helpfile. This value varies depending
  19. // on the product (workstation/server) and is set in FixupNames().
  20. //
  21. PWSTR BooksProfileLocation;
  22. PWSTR
  23. MyGetProfileValue(
  24. IN PWSTR ValueName,
  25. IN PWSTR DefaultValue
  26. )
  27. /*++
  28. Routine Description:
  29. Retreive a profile value as a unicode string.
  30. Arguments:
  31. ValueName - supplies the name of the value to be retreived.
  32. DefaultValue - supplies the default value, which is used if
  33. the given value cannot be retreived for any reason.
  34. Return Value:
  35. Pointer to the profile value. The caller can free this
  36. buffer with MyFree when done with it. Note that this
  37. routine always returns a valid pointer.
  38. --*/
  39. {
  40. LONG l;
  41. DWORD Disposition;
  42. WCHAR Value[128];
  43. HKEY hKey;
  44. DWORD DataType;
  45. DWORD DataSize;
  46. //
  47. // Create the key if it does not exist.
  48. //
  49. l = RegCreateKeyEx(
  50. HKEY_LOCAL_MACHINE,
  51. BooksProfileKeyName,
  52. 0,
  53. NULL,
  54. REG_OPTION_NON_VOLATILE,
  55. KEY_READ,
  56. NULL,
  57. &hKey,
  58. &Disposition
  59. );
  60. if(l == NO_ERROR) {
  61. DataSize = sizeof(Value);
  62. l = RegQueryValueEx(
  63. hKey,
  64. ValueName,
  65. NULL,
  66. &DataType,
  67. (LPBYTE)Value,
  68. &DataSize
  69. );
  70. RegCloseKey(hKey);
  71. if((l != NO_ERROR) || (DataType != REG_SZ)) {
  72. lstrcpy(Value,DefaultValue);
  73. }
  74. } else {
  75. lstrcpy(Value,DefaultValue);
  76. }
  77. return DupString(Value);
  78. }
  79. BOOL
  80. MySetProfileValue(
  81. IN PWSTR ValueName,
  82. OUT PWSTR Value
  83. )
  84. /*++
  85. Routine Description:
  86. Save a unicode string profile value.
  87. Arguments:
  88. ValueName - supplies the name of the value to be set.
  89. Value - supplies the value to be set.
  90. Return Value:
  91. Boolean value indicating whether the operation succeeded.
  92. --*/
  93. {
  94. LONG l;
  95. DWORD Disposition;
  96. HKEY hKey;
  97. //
  98. // Create the key if it does not exist.
  99. //
  100. l = RegCreateKeyEx(
  101. HKEY_LOCAL_MACHINE,
  102. BooksProfileKeyName,
  103. 0,
  104. NULL,
  105. REG_OPTION_NON_VOLATILE,
  106. KEY_WRITE,
  107. NULL,
  108. &hKey,
  109. &Disposition
  110. );
  111. if(l == NO_ERROR) {
  112. l = RegSetValueEx(
  113. hKey,
  114. ValueName,
  115. 0,
  116. REG_SZ,
  117. (PBYTE)Value,
  118. (lstrlen(Value)+1)*sizeof(WCHAR)
  119. );
  120. RegCloseKey(hKey);
  121. }
  122. return(l == NO_ERROR);
  123. }