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.

109 lines
2.8 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. TCHAR szGuid[GUID_SIZE];
  31. // write out the Handler to the Registry.
  32. if (ERROR_SUCCESS == RegCreateKeyEx(HKEY_CURRENT_USER,
  33. IDLESYNC_REGKEY, 0, NULL,
  34. REG_OPTION_NON_VOLATILE, KEY_QUERY_VALUE, NULL, &hkeyIdle,
  35. NULL))
  36. {
  37. DWORD dwDataSize;
  38. DWORD dwType;
  39. dwDataSize = sizeof(szGuid);
  40. dwType = REG_SZ;
  41. if (ERROR_SUCCESS != RegQueryValueEx(hkeyIdle, SZ_IDLELASTHANDLERKEY ,NULL, &dwType, (LPBYTE) szGuid, &dwDataSize))
  42. {
  43. hr = S_FALSE;
  44. }
  45. // Explicit NULL termination...
  46. szGuid[ARRAYSIZE(szGuid)-1] = 0;
  47. RegCloseKey(hkeyIdle);
  48. }
  49. else
  50. {
  51. hr = S_FALSE;
  52. }
  53. if (hr == S_FALSE)
  54. {
  55. return hr;
  56. }
  57. return CLSIDFromString(szGuid, clsidHandler);
  58. }
  59. //--------------------------------------------------------------------------------
  60. //
  61. // FUNCTION: SetLastIdleHandler()
  62. //
  63. // PURPOSE: sets the last handler synchronized on an Idle
  64. //
  65. //
  66. //--------------------------------------------------------------------------------
  67. STDMETHODIMP SetLastIdleHandler(REFCLSID clsidHandler)
  68. {
  69. HRESULT hr = E_UNEXPECTED;
  70. HKEY hkeyIdle;
  71. TCHAR szGuid[GUID_SIZE];
  72. DWORD dwDataSize;
  73. if (0 == StringFromGUID2(clsidHandler, szGuid, ARRAYSIZE(szGuid)))
  74. {
  75. AssertSz(0,"SetLastIdleHandler Failed");
  76. return E_UNEXPECTED;
  77. }
  78. // write out the Handler to the Registry.
  79. if (ERROR_SUCCESS == RegCreateKeyEx(HKEY_CURRENT_USER,
  80. IDLESYNC_REGKEY,0,NULL,
  81. REG_OPTION_NON_VOLATILE,KEY_WRITE,NULL,&hkeyIdle,
  82. NULL))
  83. {
  84. dwDataSize = sizeof(szGuid);
  85. DWORD dwRet = RegSetValueEx(hkeyIdle,SZ_IDLELASTHANDLERKEY ,NULL, REG_SZ, (LPBYTE) szGuid, dwDataSize);
  86. hr = HRESULT_FROM_WIN32(dwRet);
  87. RegCloseKey(hkeyIdle);
  88. }
  89. return hr;
  90. }