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.

253 lines
5.8 KiB

  1. //==========================================================================
  2. //
  3. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  4. // KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  5. // IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  6. // PURPOSE.
  7. //
  8. // Copyright 1998 - 1999 Microsoft Corporation. All Rights Reserved.
  9. //
  10. //--------------------------------------------------------------------------
  11. #include "precomp.h"
  12. // if writing own handler need to change CLSID value in guid.h
  13. EXTERN_C const GUID CLSID_SyncMgrHandler;
  14. TCHAR szCLSIDDescription[] = TEXT("Sample Synchronization Manager Handler");
  15. WCHAR wszCLSIDDescription[] = L"Sample Synchronization Handler Handler";
  16. //
  17. // Global variables
  18. //
  19. UINT g_cRefThisDll = 0; // Reference count of this DLL.
  20. HINSTANCE g_hmodThisDll = NULL; // Handle to this DLL itself.
  21. CSettings *g_pSettings = NULL; // ptr to global settings class.
  22. //+---------------------------------------------------------------------------
  23. //
  24. // Function: DllMain, public
  25. //
  26. // Synopsis:
  27. //
  28. // Arguments:
  29. //
  30. // Returns:
  31. //
  32. // Modifies:
  33. //
  34. //----------------------------------------------------------------------------
  35. extern "C" int APIENTRY
  36. DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
  37. {
  38. if (dwReason == DLL_PROCESS_ATTACH)
  39. {
  40. // Extension DLL one-time initialization
  41. g_hmodThisDll = hInstance;
  42. g_pSettings = new CSettings;
  43. if (NULL == g_pSettings)
  44. {
  45. return FALSE;
  46. }
  47. //initialize the common controls for property sheets
  48. INITCOMMONCONTROLSEX controlsEx;
  49. controlsEx.dwSize = sizeof(INITCOMMONCONTROLSEX);
  50. controlsEx.dwICC = ICC_USEREX_CLASSES | ICC_WIN95_CLASSES;
  51. InitCommonControlsEx(&controlsEx);
  52. }
  53. else if (dwReason == DLL_PROCESS_DETACH)
  54. {
  55. DWORD cRefs;
  56. CSettings *pSettings = g_pSettings; // ptr to global settings class.
  57. g_pSettings = NULL;
  58. Assert(0 == g_cRefThisDll);
  59. if (pSettings)
  60. {
  61. cRefs = pSettings->Release();
  62. Assert(0 == cRefs);
  63. }
  64. }
  65. return TRUE;
  66. }
  67. //+---------------------------------------------------------------------------
  68. //
  69. // Function: DllRegisterServer, public
  70. //
  71. // Synopsis:
  72. //
  73. // Arguments:
  74. //
  75. // Returns:
  76. //
  77. // Modifies:
  78. //
  79. //----------------------------------------------------------------------------
  80. STDAPI DllRegisterServer(void)
  81. {
  82. HRESULT hr = NOERROR;
  83. #ifndef _UNICODE
  84. WCHAR wszID[GUID_SIZE+1];
  85. #endif // !_UNICODE
  86. TCHAR szID[GUID_SIZE+1];
  87. TCHAR szCLSID[GUID_SIZE+1];
  88. TCHAR szModulePath[MAX_PATH];
  89. // Obtain the path to this module's executable file for later use.
  90. GetModuleFileName(
  91. g_hmodThisDll,
  92. szModulePath,
  93. sizeof(szModulePath)/sizeof(TCHAR));
  94. /*-------------------------------------------------------------------------
  95. Create registry entries for the DllSndBall Component.
  96. -------------------------------------------------------------------------*/
  97. // Create some base key strings.
  98. #ifdef _UNICODE
  99. StringFromGUID2(CLSID_SyncMgrHandler, szID, GUID_SIZE);
  100. #else
  101. BOOL fUsedDefaultChar;
  102. StringFromGUID2(CLSID_SyncMgrHandler, wszID, GUID_SIZE);
  103. WideCharToMultiByte(CP_ACP ,0,
  104. wszID,-1,szID,GUID_SIZE + 1,
  105. NULL,&fUsedDefaultChar);
  106. #endif // _UNICODE
  107. lstrcpy(szCLSID, TEXT("CLSID\\"));
  108. lstrcat(szCLSID, szID);
  109. // Create entries under CLSID.
  110. SetRegKeyValue(HKEY_CLASSES_ROOT,
  111. szCLSID,
  112. NULL,
  113. szCLSIDDescription);
  114. SetRegKeyValue(HKEY_CLASSES_ROOT,
  115. szCLSID,
  116. TEXT("InProcServer32"),
  117. szModulePath);
  118. AddRegNamedValue(
  119. szCLSID,
  120. TEXT("InProcServer32"),
  121. TEXT("ThreadingModel"),
  122. TEXT("Apartment"));
  123. // register with SyncMgr
  124. LPSYNCMGRREGISTER lpSyncMgrRegister;
  125. hr = CoCreateInstance(CLSID_SyncMgr,NULL,CLSCTX_SERVER,IID_ISyncMgrRegister,
  126. (LPVOID *) &lpSyncMgrRegister);
  127. if (SUCCEEDED(hr))
  128. {
  129. hr = lpSyncMgrRegister->RegisterSyncMgrHandler(CLSID_SyncMgrHandler,
  130. wszCLSIDDescription,0 /* dwSyncMgrRegisterFlags */);
  131. AssertSz(SUCCEEDED(hr),"Registration Failed");
  132. lpSyncMgrRegister->Release();
  133. }
  134. return hr;
  135. }
  136. //+---------------------------------------------------------------------------
  137. //
  138. // Function: DllUnregisterServer, public
  139. //
  140. // Synopsis:
  141. //
  142. // Arguments:
  143. //
  144. // Returns:
  145. //
  146. // Modifies:
  147. //
  148. //----------------------------------------------------------------------------
  149. STDAPI DllUnregisterServer(void)
  150. {
  151. HRESULT hr;
  152. // UnRegister with SyncMgr
  153. LPSYNCMGRREGISTER lpSyncMgrRegister;
  154. hr = CoCreateInstance(CLSID_SyncMgr,NULL,CLSCTX_SERVER,IID_ISyncMgrRegister,
  155. (LPVOID *) &lpSyncMgrRegister);
  156. if (SUCCEEDED(hr))
  157. {
  158. hr = lpSyncMgrRegister->UnregisterSyncMgrHandler(CLSID_SyncMgrHandler,0);
  159. lpSyncMgrRegister->Release();
  160. }
  161. return hr;
  162. }
  163. //+---------------------------------------------------------------------------
  164. //
  165. // Function: DllCanUnloadNow, public
  166. //
  167. // Synopsis:
  168. //
  169. // Arguments:
  170. //
  171. // Returns:
  172. //
  173. // Modifies:
  174. //
  175. //----------------------------------------------------------------------------
  176. STDAPI DllCanUnloadNow(void)
  177. {
  178. return (g_cRefThisDll == 0) ? S_OK : S_FALSE;
  179. }
  180. //+---------------------------------------------------------------------------
  181. //
  182. // Function: DllGetClassObject, public
  183. //
  184. // Synopsis:
  185. //
  186. // Arguments:
  187. //
  188. // Returns:
  189. //
  190. // Modifies:
  191. //
  192. //----------------------------------------------------------------------------
  193. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppvOut)
  194. {
  195. *ppvOut = NULL;
  196. if (IsEqualIID(rclsid, CLSID_SyncMgrHandler))
  197. {
  198. CClassFactory *pcf = new CClassFactory;
  199. return pcf->QueryInterface(riid, ppvOut);
  200. }
  201. return CLASS_E_CLASSNOTAVAILABLE;
  202. }