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.

303 lines
6.7 KiB

  1. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  2. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  3. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  4. // PARTICULAR PURPOSE.
  5. //
  6. // Copyright (C) 1993-1996 Microsoft Corporation. All Rights Reserved.
  7. //
  8. // MODULE: shellext.cpp
  9. //
  10. // Purpose: Implements the class factory code as well as COneStopHandler::QI,
  11. // COneStopHandler::AddRef and COneStopHandler::Release code.
  12. #include <objbase.h>
  13. #include "SyncHndl.h"
  14. #include "reg.h"
  15. // vars and functions specific implementations must override.
  16. EXTERN_C const GUID CLSID_OneStopHandler;
  17. extern TCHAR szCLSIDDescription[];
  18. extern COneStopHandler* CreateHandlerObject();
  19. extern void DestroyHandlerObject(COneStopHandler* pOfflineSynchronize);
  20. //
  21. // Global variables
  22. //
  23. UINT g_cRefThisDll = 0; // Reference count of this DLL.
  24. HINSTANCE g_hmodThisDll = NULL; // Handle to this DLL itself.
  25. /////////////////////////////////////////////////////////////////////////////
  26. // DllRegisterServer - Adds entries to the system registry
  27. STDAPI DllRegisterServer(void)
  28. {
  29. HRESULT hr = NOERROR;
  30. #ifndef _UNICODE
  31. WCHAR wszID[GUID_SIZE+1];
  32. #endif // !_UNICODE
  33. TCHAR szID[GUID_SIZE+1];
  34. TCHAR szCLSID[GUID_SIZE+1];
  35. TCHAR szModulePath[MAX_PATH];
  36. // Obtain the path to this module's executable file for later use.
  37. GetModuleFileName(
  38. g_hmodThisDll,
  39. szModulePath,
  40. sizeof(szModulePath)/sizeof(TCHAR));
  41. /*-------------------------------------------------------------------------
  42. Create registry entries for the DllSndBall Component.
  43. -------------------------------------------------------------------------*/
  44. // Create some base key strings.
  45. #ifdef _UNICODE
  46. StringFromGUID2(CLSID_OneStopHandler, szID, GUID_SIZE);
  47. #else
  48. BOOL fUsedDefaultChar;
  49. StringFromGUID2(CLSID_OneStopHandler, wszID, GUID_SIZE);
  50. WideCharToMultiByte(CP_ACP ,0,
  51. wszID,-1,szID,GUID_SIZE + 1,
  52. NULL,&fUsedDefaultChar);
  53. #endif // _UNICODE
  54. lstrcpy(szCLSID, TEXT("CLSID\\"));
  55. lstrcat(szCLSID, szID);
  56. // Create entries under CLSID.
  57. SetRegKeyValue(HKEY_CLASSES_ROOT,
  58. szCLSID,
  59. NULL,
  60. szCLSIDDescription);
  61. SetRegKeyValue(HKEY_CLASSES_ROOT,
  62. szCLSID,
  63. TEXT("InProcServer32"),
  64. szModulePath);
  65. AddRegNamedValue(
  66. szCLSID,
  67. TEXT("InProcServer32"),
  68. TEXT("ThreadingModel"),
  69. TEXT("Apartment"));
  70. #define ONESTOPKEY TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\SyncMgr\\Handlers")
  71. // Register with OneStop
  72. SetRegKeyValue(HKEY_LOCAL_MACHINE,
  73. ONESTOPKEY,
  74. NULL,
  75. TEXT("OneStop Reg Key") );
  76. SetRegKeyValue(HKEY_LOCAL_MACHINE,
  77. ONESTOPKEY,
  78. szID,
  79. szCLSIDDescription);
  80. return hr;
  81. }
  82. extern "C" int APIENTRY
  83. DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
  84. {
  85. if (dwReason == DLL_PROCESS_ATTACH)
  86. {
  87. ODS("In DLLMain, DLL_PROCESS_ATTACH\r\n");
  88. // Extension DLL one-time initialization
  89. g_hmodThisDll = hInstance;
  90. }
  91. else if (dwReason == DLL_PROCESS_DETACH)
  92. {
  93. ODS("In DLLMain, DLL_PROCESS_DETACH\r\n");
  94. }
  95. return 1; // ok
  96. }
  97. //---------------------------------------------------------------------------
  98. // DllCanUnloadNow
  99. //---------------------------------------------------------------------------
  100. STDAPI DllCanUnloadNow(void)
  101. {
  102. ODS("In DLLCanUnloadNow\r\n");
  103. return (g_cRefThisDll == 0 ? S_OK : S_FALSE);
  104. }
  105. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppvOut)
  106. {
  107. ODS("In DllGetClassObject\r\n");
  108. *ppvOut = NULL;
  109. if (IsEqualIID(rclsid, CLSID_OneStopHandler))
  110. {
  111. CClassFactory *pcf = new CClassFactory;
  112. return pcf->QueryInterface(riid, ppvOut);
  113. }
  114. return CLASS_E_CLASSNOTAVAILABLE;
  115. }
  116. CClassFactory::CClassFactory()
  117. {
  118. ODS("CClassFactory::CClassFactory()\r\n");
  119. m_cRef = 0L;
  120. g_cRefThisDll++;
  121. }
  122. CClassFactory::~CClassFactory()
  123. {
  124. g_cRefThisDll--;
  125. }
  126. STDMETHODIMP CClassFactory::QueryInterface(REFIID riid,
  127. LPVOID FAR *ppv)
  128. {
  129. ODS("CClassFactory::QueryInterface()\r\n");
  130. *ppv = NULL;
  131. // Any interface on this object is the object pointer
  132. if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_IClassFactory))
  133. {
  134. *ppv = (LPCLASSFACTORY)this;
  135. AddRef();
  136. return NOERROR;
  137. }
  138. return E_NOINTERFACE;
  139. }
  140. STDMETHODIMP_(ULONG) CClassFactory::AddRef()
  141. {
  142. return ++m_cRef;
  143. }
  144. STDMETHODIMP_(ULONG) CClassFactory::Release()
  145. {
  146. if (--m_cRef)
  147. return m_cRef;
  148. delete this;
  149. return 0L;
  150. }
  151. STDMETHODIMP CClassFactory::CreateInstance(LPUNKNOWN pUnkOuter,
  152. REFIID riid,
  153. LPVOID *ppvObj)
  154. {
  155. HRESULT hr = NOERROR;
  156. *ppvObj = NULL;
  157. ODS("CClassFactory::CreateInstance()\r\n");
  158. // Shell extensions typically don't support aggregation (inheritance)
  159. if (pUnkOuter)
  160. return CLASS_E_NOAGGREGATION;
  161. // Create the main shell extension object. The shell will then call
  162. // QueryInterface with IID_IShellExtInit--this is how shell extensions are
  163. // initialized.
  164. LPSYNCMGRSYNCHRONIZE pOneStopHandler = CreateHandlerObject(); //Create the COneStopHandler object
  165. if (NULL == pOneStopHandler)
  166. return E_OUTOFMEMORY;
  167. hr = pOneStopHandler->QueryInterface(riid, ppvObj);
  168. pOneStopHandler->Release(); // remove our reference.
  169. return hr;
  170. }
  171. STDMETHODIMP CClassFactory::LockServer(BOOL fLock)
  172. {
  173. return NOERROR;
  174. }
  175. // *********************** COneStopHandler *************************
  176. COneStopHandler::COneStopHandler()
  177. {
  178. ODS("COneStopHandler::COneStopHandler()\r\n");
  179. m_cRef = 1;
  180. m_pOfflineHandlerItems = NULL;
  181. m_pOfflineSynchronizeCallback = NULL;
  182. g_cRefThisDll++;
  183. }
  184. COneStopHandler::~COneStopHandler()
  185. {
  186. // TODO: ADD ASSERTS THAT MEMBERS HAVE BEEN RELEASED.
  187. g_cRefThisDll--;
  188. }
  189. STDMETHODIMP COneStopHandler::QueryInterface(REFIID riid, LPVOID FAR *ppv)
  190. {
  191. *ppv = NULL;
  192. if (IsEqualIID(riid, IID_IUnknown))
  193. {
  194. ODS("COneStopHandler::QueryInterface()==>IID_IUknown\r\n");
  195. *ppv = (LPUNKNOWN)this;
  196. }
  197. else if (IsEqualIID(riid, IID_ISyncMgrSynchronize))
  198. {
  199. ODS("COneStopHandler::QueryInterface()==>IID_IOfflineSynchronize\r\n");
  200. *ppv = (LPSYNCMGRSYNCHRONIZE)this;
  201. }
  202. if (*ppv)
  203. {
  204. AddRef();
  205. return NOERROR;
  206. }
  207. ODS("COneStopHandler::QueryInterface()==>Unknown Interface!\r\n");
  208. return E_NOINTERFACE;
  209. }
  210. STDMETHODIMP_(ULONG) COneStopHandler::AddRef()
  211. {
  212. ODS("COneStopHandler::AddRef()\r\n");
  213. return ++m_cRef;
  214. }
  215. STDMETHODIMP_(ULONG) COneStopHandler::Release()
  216. {
  217. ODS("COneStopHandler::Release()\r\n");
  218. if (--m_cRef)
  219. return m_cRef;
  220. DestroyHandler();
  221. return 0L;
  222. }