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.

148 lines
3.3 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: Reg.cpp
  7. //
  8. // Contents: Registration Routines
  9. //
  10. // Classes:
  11. //
  12. // Notes:
  13. //
  14. // History: 05-Nov-97 rogerg Created.
  15. //
  16. //--------------------------------------------------------------------------
  17. #include "precomp.h"
  18. //--------------------------------------------------------------------------------
  19. //
  20. // FUNCTION: GetLastIdleHandler()
  21. //
  22. // PURPOSE: returns last handler synchronized on an Idle
  23. //
  24. //
  25. //--------------------------------------------------------------------------------
  26. STDMETHODIMP GetLastIdleHandler(CLSID *clsidHandler)
  27. {
  28. HRESULT hr = E_UNEXPECTED;
  29. HKEY hkeyIdle;
  30. WCHAR wszGuid[GUID_SIZE];
  31. TCHAR *pszGuid;
  32. DWORD dwDataSize;
  33. #ifndef _UNICODE
  34. TCHAR szGuid[GUID_SIZE];
  35. #endif // _UNICODE
  36. #ifdef _UNICODE
  37. dwDataSize = sizeof(wszGuid);
  38. pszGuid = wszGuid;
  39. #else
  40. dwDataSize = sizeof(szGuid);
  41. pszGuid = szGuid;
  42. #endif
  43. // write out the Handler to the Registry.
  44. if (ERROR_SUCCESS == RegCreateKeyExXp(HKEY_CURRENT_USER,
  45. IDLESYNC_REGKEY,0,NULL,
  46. REG_OPTION_NON_VOLATILE,KEY_QUERY_VALUE,NULL,&hkeyIdle,
  47. NULL,FALSE /*fSetSecurity*/))
  48. {
  49. DWORD dwType;
  50. dwType = REG_SZ;
  51. hr = RegQueryValueEx(hkeyIdle,SZ_IDLELASTHANDLERKEY
  52. ,NULL, &dwType ,
  53. (LPBYTE) pszGuid,
  54. &dwDataSize);
  55. RegCloseKey(hkeyIdle);
  56. }
  57. else
  58. {
  59. return S_FALSE;
  60. }
  61. if (hr != ERROR_SUCCESS)
  62. {
  63. hr = S_FALSE;
  64. return hr;
  65. }
  66. #ifndef _UNICODE
  67. MultiByteToWideChar(CP_ACP ,0,szGuid,-1,wszGuid,GUID_SIZE);
  68. #endif // _UNICODE
  69. return CLSIDFromString(wszGuid,clsidHandler);
  70. }
  71. //--------------------------------------------------------------------------------
  72. //
  73. // FUNCTION: SetLastIdleHandler()
  74. //
  75. // PURPOSE: sets the last handler synchronized on an Idle
  76. //
  77. //
  78. //--------------------------------------------------------------------------------
  79. STDMETHODIMP SetLastIdleHandler(REFCLSID clsidHandler)
  80. {
  81. HRESULT hr = E_UNEXPECTED;
  82. HKEY hkeyIdle;
  83. WCHAR wszGuid[GUID_SIZE];
  84. TCHAR *pszGuid;
  85. DWORD dwDataSize;
  86. #ifndef _UNICODE
  87. TCHAR szGuid[GUID_SIZE];
  88. #endif // _UNICODE
  89. if (0 == StringFromGUID2(clsidHandler,wszGuid, GUID_SIZE))
  90. {
  91. AssertSz(0,"SetLastIdleHandler Failed");
  92. return E_UNEXPECTED;
  93. }
  94. #ifdef _UNICODE
  95. pszGuid = wszGuid;
  96. dwDataSize = sizeof(wszGuid);
  97. #else
  98. BOOL fUsedDefaultChar;
  99. WideCharToMultiByte(CP_ACP ,0,wszGuid,
  100. -1,szGuid,GUID_SIZE,
  101. NULL,&fUsedDefaultChar);
  102. pszGuid = szGuid;
  103. dwDataSize = GUID_SIZE * sizeof(TCHAR);
  104. #endif // _UNICODE
  105. // write out the Handler to the Registry.
  106. if (ERROR_SUCCESS == RegCreateKeyExXp(HKEY_CURRENT_USER,
  107. IDLESYNC_REGKEY,0,NULL,
  108. REG_OPTION_NON_VOLATILE,KEY_WRITE,NULL,&hkeyIdle,
  109. NULL,FALSE /*fSetSecurity*/))
  110. {
  111. hr = RegSetValueEx(hkeyIdle,SZ_IDLELASTHANDLERKEY
  112. ,NULL, REG_SZ ,
  113. (LPBYTE) pszGuid,
  114. dwDataSize);
  115. RegCloseKey(hkeyIdle);
  116. }
  117. return hr;
  118. }