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.

444 lines
9.3 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995 - 1995.
  5. //
  6. // File: ole.cxx
  7. //
  8. // Contents: Class factory, etc, for all OLE objects:
  9. // CShare and CShareCopyHook
  10. //
  11. // History: 6-Apr-95 BruceFo Created
  12. //
  13. //----------------------------------------------------------------------------
  14. #include "headers.hxx"
  15. #pragma hdrstop
  16. #include "ole.hxx"
  17. #include "copyhook.hxx"
  18. #include "share.hxx"
  19. #include "dllmain.hxx"
  20. // {f81e9010-6ea4-11ce-a7ff-00aa003ca9f6}
  21. const CLSID CLSID_CShare = {0xf81e9010, 0x6ea4, 0x11ce, 0xa7, 0xff, 0x00, 0xaa, 0x00, 0x3c, 0xa9, 0xf6 };
  22. // {40dd6e20-7c17-11ce-a804-00aa003ca9f6}
  23. const CLSID CLSID_CShareCopyHook = {0x40dd6e20, 0x7c17, 0x11ce, 0xa8, 0x04, 0x00, 0xaa, 0x00, 0x3c, 0xa9, 0xf6};
  24. //////////////////////////////////////////////////////////////////////////////
  25. //////////////////////////////////////////////////////////////////////////////
  26. ULONG g_ulcInstancesShare = 0;
  27. ULONG g_ulcInstancesShareCopyHook = 0;
  28. //////////////////////////////////////////////////////////////////////////////
  29. //////////////////////////////////////////////////////////////////////////////
  30. STDMETHODIMP
  31. CShare::QueryInterface(
  32. IN REFIID riid,
  33. OUT LPVOID* ppvObj
  34. )
  35. {
  36. appDebugOut((DEB_ITRACE, "CShare::QueryInterface..."));
  37. *ppvObj = NULL;
  38. IUnknown* pUnkTemp = NULL;
  39. HRESULT hr = S_OK;
  40. if (IsEqualIID(IID_IUnknown, riid))
  41. {
  42. appDebugOut((DEB_ITRACE | DEB_NOCOMPNAME, "IUnknown\n"));
  43. pUnkTemp = (IUnknown*)(IShellExtInit*) this; // doesn't matter which
  44. }
  45. else
  46. if (IsEqualIID(IID_IShellExtInit, riid))
  47. {
  48. appDebugOut((DEB_ITRACE | DEB_NOCOMPNAME, "IShellExtInit\n"));
  49. pUnkTemp = (IShellExtInit*) this;
  50. }
  51. else
  52. if (IsEqualIID(IID_IShellPropSheetExt, riid))
  53. {
  54. appDebugOut((DEB_ITRACE | DEB_NOCOMPNAME, "IShellPropSheetExt\n"));
  55. pUnkTemp = (IShellPropSheetExt*) this;
  56. }
  57. else
  58. if (IsEqualIID(IID_IContextMenu, riid))
  59. {
  60. appDebugOut((DEB_ITRACE | DEB_NOCOMPNAME, "IContextMenu\n"));
  61. pUnkTemp = (IContextMenu*) this;
  62. }
  63. else
  64. {
  65. appDebugOut((DEB_ITRACE | DEB_NOCOMPNAME, "unknown interface\n"));
  66. hr = E_NOINTERFACE;
  67. }
  68. if (pUnkTemp != NULL)
  69. {
  70. pUnkTemp->AddRef();
  71. }
  72. *ppvObj = pUnkTemp;
  73. return hr;
  74. }
  75. STDMETHODIMP_(ULONG)
  76. CShare::AddRef(
  77. VOID
  78. )
  79. {
  80. InterlockedIncrement((LONG*)&g_ulcInstancesShare);
  81. InterlockedIncrement((LONG*)&_uRefs);
  82. appDebugOut((DEB_ITRACE,
  83. "CShare::AddRef, local: %d, DLL: %d\n",
  84. _uRefs,
  85. g_ulcInstancesShare));
  86. return _uRefs;
  87. }
  88. STDMETHODIMP_(ULONG)
  89. CShare::Release(
  90. VOID
  91. )
  92. {
  93. InterlockedDecrement((LONG*)&g_ulcInstancesShare);
  94. ULONG cRef = InterlockedDecrement((LONG*)&_uRefs);
  95. appDebugOut((DEB_ITRACE,
  96. "CShare::Release, local: %d, DLL: %d\n",
  97. _uRefs,
  98. g_ulcInstancesShare));
  99. if (0 == cRef)
  100. {
  101. delete this;
  102. }
  103. return cRef;
  104. }
  105. //////////////////////////////////////////////////////////////////////////////
  106. STDMETHODIMP
  107. CShareCF::QueryInterface(REFIID riid, LPVOID* ppvObj)
  108. {
  109. appDebugOut((DEB_ITRACE, "CShareCF::QueryInterface..."));
  110. *ppvObj = NULL;
  111. IUnknown* pUnkTemp = NULL;
  112. HRESULT hr = S_OK;
  113. if (IsEqualIID(IID_IUnknown, riid))
  114. {
  115. appDebugOut((DEB_ITRACE | DEB_NOCOMPNAME, "IUnknown\n"));
  116. pUnkTemp = (IUnknown*) this;
  117. }
  118. else if (IsEqualIID(IID_IClassFactory, riid))
  119. {
  120. appDebugOut((DEB_ITRACE | DEB_NOCOMPNAME, "IClassFactory\n"));
  121. pUnkTemp = (IClassFactory*) this;
  122. }
  123. else
  124. {
  125. appDebugOut((DEB_ITRACE | DEB_NOCOMPNAME, "unknown interface\n"));
  126. hr = E_NOINTERFACE;
  127. }
  128. if (pUnkTemp != NULL)
  129. {
  130. pUnkTemp->AddRef();
  131. }
  132. *ppvObj = pUnkTemp;
  133. return hr;
  134. }
  135. STDMETHODIMP_(ULONG)
  136. CShareCF::AddRef()
  137. {
  138. InterlockedIncrement((LONG*)&g_ulcInstancesShare);
  139. appDebugOut((DEB_ITRACE,
  140. "CShareCF::AddRef, DLL: %d\n",
  141. g_ulcInstancesShare));
  142. return g_ulcInstancesShare;
  143. }
  144. STDMETHODIMP_(ULONG)
  145. CShareCF::Release()
  146. {
  147. InterlockedDecrement((LONG*)&g_ulcInstancesShare);
  148. appDebugOut((DEB_ITRACE,
  149. "CShareCF::Release, DLL: %d\n",
  150. g_ulcInstancesShare));
  151. return g_ulcInstancesShare;
  152. }
  153. STDMETHODIMP
  154. CShareCF::CreateInstance(IUnknown* pUnkOuter, REFIID riid, LPVOID* ppvObj)
  155. {
  156. appDebugOut((DEB_ITRACE, "CShareCF::CreateInstance\n"));
  157. if (pUnkOuter != NULL)
  158. {
  159. // don't support aggregation
  160. return E_NOTIMPL;
  161. }
  162. CShare* pShare = new CShare();
  163. if (NULL == pShare)
  164. {
  165. return E_OUTOFMEMORY;
  166. }
  167. HRESULT hr = pShare->QueryInterface(riid, ppvObj);
  168. pShare->Release();
  169. return hr;
  170. }
  171. STDMETHODIMP
  172. CShareCF::LockServer(BOOL fLock)
  173. {
  174. //
  175. // FEATURE: Whats supposed to happen here?
  176. //
  177. return S_OK;
  178. }
  179. //////////////////////////////////////////////////////////////////////////////
  180. //////////////////////////////////////////////////////////////////////////////
  181. STDMETHODIMP
  182. CShareCopyHook::QueryInterface(
  183. IN REFIID riid,
  184. OUT LPVOID* ppvObj
  185. )
  186. {
  187. appDebugOut((DEB_ITRACE, "CShareCopyHook::QueryInterface..."));
  188. *ppvObj = NULL;
  189. IUnknown* pUnkTemp = NULL;
  190. HRESULT hr = S_OK;
  191. if (IsEqualIID(IID_IUnknown, riid))
  192. {
  193. appDebugOut((DEB_ITRACE | DEB_NOCOMPNAME, "IUnknown\n"));
  194. pUnkTemp = (IUnknown*) this;
  195. }
  196. else
  197. if (IsEqualIID(IID_IShellCopyHook, riid))
  198. {
  199. appDebugOut((DEB_ITRACE | DEB_NOCOMPNAME, "ICopyHook\n"));
  200. pUnkTemp = (ICopyHook*) this;
  201. }
  202. else
  203. {
  204. appDebugOut((DEB_ITRACE | DEB_NOCOMPNAME, "unknown interface\n"));
  205. hr = E_NOINTERFACE;
  206. }
  207. if (pUnkTemp != NULL)
  208. {
  209. pUnkTemp->AddRef();
  210. }
  211. *ppvObj = pUnkTemp;
  212. return hr;
  213. }
  214. STDMETHODIMP_(ULONG)
  215. CShareCopyHook::AddRef(
  216. VOID
  217. )
  218. {
  219. InterlockedIncrement((LONG*)&g_ulcInstancesShare);
  220. InterlockedIncrement((LONG*)&_uRefs);
  221. appDebugOut((DEB_ITRACE,
  222. "CShareCopyHook::AddRef, local: %d, DLL: %d\n",
  223. _uRefs,
  224. g_ulcInstancesShare));
  225. return _uRefs;
  226. }
  227. STDMETHODIMP_(ULONG)
  228. CShareCopyHook::Release(
  229. VOID
  230. )
  231. {
  232. InterlockedDecrement((LONG*)&g_ulcInstancesShare);
  233. ULONG cRef = InterlockedDecrement((LONG*)&_uRefs);
  234. appDebugOut((DEB_ITRACE,
  235. "CShareCopyHook::Release, local: %d, DLL: %d\n",
  236. _uRefs,
  237. g_ulcInstancesShare));
  238. if (0 == cRef)
  239. {
  240. delete this;
  241. }
  242. return cRef;
  243. }
  244. //////////////////////////////////////////////////////////////////////////////
  245. STDMETHODIMP
  246. CShareCopyHookCF::QueryInterface(REFIID riid, LPVOID* ppvObj)
  247. {
  248. appDebugOut((DEB_ITRACE, "CShareCopyHookCF::QueryInterface..."));
  249. *ppvObj = NULL;
  250. IUnknown* pUnkTemp = NULL;
  251. HRESULT hr = S_OK;
  252. if (IsEqualIID(IID_IUnknown, riid))
  253. {
  254. appDebugOut((DEB_ITRACE | DEB_NOCOMPNAME, "IUnknown\n"));
  255. pUnkTemp = (IUnknown*) this;
  256. }
  257. else if (IsEqualIID(IID_IClassFactory, riid))
  258. {
  259. appDebugOut((DEB_ITRACE | DEB_NOCOMPNAME, "IClassFactory\n"));
  260. pUnkTemp = (IClassFactory*) this;
  261. }
  262. else
  263. {
  264. appDebugOut((DEB_ITRACE | DEB_NOCOMPNAME, "unknown interface\n"));
  265. hr = E_NOINTERFACE;
  266. }
  267. if (pUnkTemp != NULL)
  268. {
  269. pUnkTemp->AddRef();
  270. }
  271. *ppvObj = pUnkTemp;
  272. return hr;
  273. }
  274. STDMETHODIMP_(ULONG)
  275. CShareCopyHookCF::AddRef()
  276. {
  277. InterlockedIncrement((LONG*)&g_ulcInstancesShareCopyHook);
  278. return g_ulcInstancesShareCopyHook;
  279. }
  280. STDMETHODIMP_(ULONG)
  281. CShareCopyHookCF::Release()
  282. {
  283. InterlockedDecrement((LONG*)&g_ulcInstancesShareCopyHook);
  284. return g_ulcInstancesShareCopyHook;
  285. }
  286. STDMETHODIMP
  287. CShareCopyHookCF::CreateInstance(IUnknown* pUnkOuter, REFIID riid, LPVOID* ppvObj)
  288. {
  289. appDebugOut((DEB_ITRACE, "CShareCopyHookCF::CreateInstance\n"));
  290. if (pUnkOuter != NULL)
  291. {
  292. // don't support aggregation
  293. return E_NOTIMPL;
  294. }
  295. CShareCopyHook* pShareCopyHook = new CShareCopyHook();
  296. if (NULL == pShareCopyHook)
  297. {
  298. return E_OUTOFMEMORY;
  299. }
  300. HRESULT hr = pShareCopyHook->QueryInterface(riid, ppvObj);
  301. pShareCopyHook->Release();
  302. if (FAILED(hr))
  303. {
  304. hr = E_NOINTERFACE; // FEATURE: Whats the error code?
  305. }
  306. else
  307. {
  308. hr = S_OK;
  309. }
  310. return hr;
  311. }
  312. STDMETHODIMP
  313. CShareCopyHookCF::LockServer(BOOL fLock)
  314. {
  315. //
  316. // FEATURE: Whats supposed to happen here?
  317. //
  318. return S_OK;
  319. }
  320. //////////////////////////////////////////////////////////////////////////////
  321. //////////////////////////////////////////////////////////////////////////////
  322. STDAPI
  323. DllCanUnloadNow(
  324. VOID
  325. )
  326. {
  327. OneTimeInit();
  328. if (0 == g_ulcInstancesShare
  329. && 0 == g_ulcInstancesShareCopyHook
  330. && 0 == g_NonOLEDLLRefs)
  331. {
  332. return S_OK;
  333. }
  334. else
  335. {
  336. return S_FALSE;
  337. }
  338. }
  339. CShareCF cfShare;
  340. CShareCopyHookCF cfShareCopyHook;
  341. STDAPI
  342. DllGetClassObject(
  343. REFCLSID cid,
  344. REFIID iid,
  345. LPVOID* ppvObj
  346. )
  347. {
  348. OneTimeInit();
  349. appDebugOut((DEB_TRACE, "DllGetClassObject\n"));
  350. HRESULT hr = E_NOINTERFACE;
  351. if (IsEqualCLSID(cid, CLSID_CShare))
  352. {
  353. hr = cfShare.QueryInterface(iid, ppvObj);
  354. }
  355. else if (IsEqualCLSID(cid, CLSID_CShareCopyHook))
  356. {
  357. hr = cfShareCopyHook.QueryInterface(iid, ppvObj);
  358. }
  359. return hr;
  360. }