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.

441 lines
9.9 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. ULONG cInst = InterlockedIncrement((LONG*)&g_ulcInstancesShare);
  81. ULONG cRef = InterlockedIncrement((LONG*)&_uRefs);
  82. appDebugOut((DEB_ITRACE, "CShare::AddRef, local: %d, DLL: %d\n", cRef, cInst ));
  83. return cRef;
  84. }
  85. STDMETHODIMP_(ULONG)
  86. CShare::Release(
  87. VOID
  88. )
  89. {
  90. appAssert( 0 != g_ulcInstancesShare );
  91. InterlockedDecrement((LONG*)&g_ulcInstancesShare);
  92. appAssert( 0 != _uRefs );
  93. ULONG cRef = InterlockedDecrement((LONG*)&_uRefs);
  94. appDebugOut((DEB_ITRACE,
  95. "CShare::Release, local: %d, DLL: %d\n",
  96. cRef,
  97. g_ulcInstancesShare));
  98. if (0 == cRef)
  99. {
  100. delete this;
  101. }
  102. return cRef;
  103. }
  104. //////////////////////////////////////////////////////////////////////////////
  105. STDMETHODIMP
  106. CShareCF::QueryInterface(REFIID riid, LPVOID* ppvObj)
  107. {
  108. appDebugOut((DEB_ITRACE, "CShareCF::QueryInterface..."));
  109. *ppvObj = NULL;
  110. IUnknown* pUnkTemp = NULL;
  111. HRESULT hr = S_OK;
  112. if (IsEqualIID(IID_IUnknown, riid))
  113. {
  114. appDebugOut((DEB_ITRACE | DEB_NOCOMPNAME, "IUnknown\n"));
  115. pUnkTemp = (IUnknown*) this;
  116. }
  117. else if (IsEqualIID(IID_IClassFactory, riid))
  118. {
  119. appDebugOut((DEB_ITRACE | DEB_NOCOMPNAME, "IClassFactory\n"));
  120. pUnkTemp = (IClassFactory*) this;
  121. }
  122. else
  123. {
  124. appDebugOut((DEB_ITRACE | DEB_NOCOMPNAME, "unknown interface\n"));
  125. hr = E_NOINTERFACE;
  126. }
  127. if (pUnkTemp != NULL)
  128. {
  129. pUnkTemp->AddRef();
  130. }
  131. *ppvObj = pUnkTemp;
  132. return hr;
  133. }
  134. STDMETHODIMP_(ULONG)
  135. CShareCF::AddRef()
  136. {
  137. ULONG cInst = InterlockedIncrement((LONG*)&g_ulcInstancesShare);
  138. appDebugOut((DEB_ITRACE, "CShareCF::AddRef, DLL: %d\n", cInst ));
  139. return cInst;
  140. }
  141. STDMETHODIMP_(ULONG)
  142. CShareCF::Release()
  143. {
  144. appAssert( 0 != g_ulcInstancesShare );
  145. InterlockedDecrement((LONG*)&g_ulcInstancesShare);
  146. appDebugOut((DEB_ITRACE,
  147. "CShareCF::Release, DLL: %d\n",
  148. g_ulcInstancesShare));
  149. return g_ulcInstancesShare;
  150. }
  151. STDMETHODIMP
  152. CShareCF::CreateInstance(IUnknown* pUnkOuter, REFIID riid, LPVOID* ppvObj)
  153. {
  154. appDebugOut((DEB_ITRACE, "CShareCF::CreateInstance\n"));
  155. if (pUnkOuter != NULL)
  156. {
  157. // don't support aggregation
  158. return E_NOTIMPL;
  159. }
  160. CShare* pShare = new CShare();
  161. if (NULL == pShare)
  162. {
  163. return E_OUTOFMEMORY;
  164. }
  165. HRESULT hr = pShare->QueryInterface(riid, ppvObj);
  166. pShare->Release();
  167. return hr;
  168. }
  169. STDMETHODIMP
  170. CShareCF::LockServer(BOOL fLock)
  171. {
  172. //
  173. // FEATURE: Whats supposed to happen here?
  174. //
  175. return S_OK;
  176. }
  177. //////////////////////////////////////////////////////////////////////////////
  178. //////////////////////////////////////////////////////////////////////////////
  179. STDMETHODIMP
  180. CShareCopyHook::QueryInterface(
  181. IN REFIID riid,
  182. OUT LPVOID* ppvObj
  183. )
  184. {
  185. appDebugOut((DEB_ITRACE, "CShareCopyHook::QueryInterface..."));
  186. *ppvObj = NULL;
  187. IUnknown* pUnkTemp = NULL;
  188. HRESULT hr = S_OK;
  189. if (IsEqualIID(IID_IUnknown, riid))
  190. {
  191. appDebugOut((DEB_ITRACE | DEB_NOCOMPNAME, "IUnknown\n"));
  192. pUnkTemp = (IUnknown*) this;
  193. }
  194. else
  195. if (IsEqualIID(IID_IShellCopyHook, riid))
  196. {
  197. appDebugOut((DEB_ITRACE | DEB_NOCOMPNAME, "ICopyHook\n"));
  198. pUnkTemp = (ICopyHook*) this;
  199. }
  200. else
  201. {
  202. appDebugOut((DEB_ITRACE | DEB_NOCOMPNAME, "unknown interface\n"));
  203. hr = E_NOINTERFACE;
  204. }
  205. if (pUnkTemp != NULL)
  206. {
  207. pUnkTemp->AddRef();
  208. }
  209. *ppvObj = pUnkTemp;
  210. return hr;
  211. }
  212. STDMETHODIMP_(ULONG)
  213. CShareCopyHook::AddRef(
  214. VOID
  215. )
  216. {
  217. ULONG cInst = InterlockedIncrement((LONG*)&g_ulcInstancesShare);
  218. ULONG cRef = InterlockedIncrement((LONG*)&_uRefs);
  219. appDebugOut((DEB_ITRACE, "CShareCopyHook::AddRef, local: %d, DLL: %d\n", cRef, cInst ));
  220. return cRef;
  221. }
  222. STDMETHODIMP_(ULONG)
  223. CShareCopyHook::Release(
  224. VOID
  225. )
  226. {
  227. appAssert( 0 != g_ulcInstancesShare );
  228. InterlockedDecrement((LONG*)&g_ulcInstancesShare);
  229. appAssert( 0 != _uRefs );
  230. ULONG cRef = InterlockedDecrement((LONG*)&_uRefs);
  231. appDebugOut((DEB_ITRACE,
  232. "CShareCopyHook::Release, local: %d, DLL: %d\n",
  233. cRef,
  234. g_ulcInstancesShare));
  235. if (0 == cRef)
  236. {
  237. delete this;
  238. }
  239. return cRef;
  240. }
  241. //////////////////////////////////////////////////////////////////////////////
  242. STDMETHODIMP
  243. CShareCopyHookCF::QueryInterface(REFIID riid, LPVOID* ppvObj)
  244. {
  245. appDebugOut((DEB_ITRACE, "CShareCopyHookCF::QueryInterface..."));
  246. *ppvObj = NULL;
  247. IUnknown* pUnkTemp = NULL;
  248. HRESULT hr = S_OK;
  249. if (IsEqualIID(IID_IUnknown, riid))
  250. {
  251. appDebugOut((DEB_ITRACE | DEB_NOCOMPNAME, "IUnknown\n"));
  252. pUnkTemp = (IUnknown*) this;
  253. }
  254. else if (IsEqualIID(IID_IClassFactory, riid))
  255. {
  256. appDebugOut((DEB_ITRACE | DEB_NOCOMPNAME, "IClassFactory\n"));
  257. pUnkTemp = (IClassFactory*) this;
  258. }
  259. else
  260. {
  261. appDebugOut((DEB_ITRACE | DEB_NOCOMPNAME, "unknown interface\n"));
  262. hr = E_NOINTERFACE;
  263. }
  264. if (pUnkTemp != NULL)
  265. {
  266. pUnkTemp->AddRef();
  267. }
  268. *ppvObj = pUnkTemp;
  269. return hr;
  270. }
  271. STDMETHODIMP_(ULONG)
  272. CShareCopyHookCF::AddRef()
  273. {
  274. return InterlockedIncrement((LONG*)&g_ulcInstancesShareCopyHook);
  275. }
  276. STDMETHODIMP_(ULONG)
  277. CShareCopyHookCF::Release()
  278. {
  279. appAssert( 0 != g_ulcInstancesShareCopyHook );
  280. InterlockedDecrement((LONG*)&g_ulcInstancesShareCopyHook);
  281. return g_ulcInstancesShareCopyHook;
  282. }
  283. STDMETHODIMP
  284. CShareCopyHookCF::CreateInstance(IUnknown* pUnkOuter, REFIID riid, LPVOID* ppvObj)
  285. {
  286. appDebugOut((DEB_ITRACE, "CShareCopyHookCF::CreateInstance\n"));
  287. if (pUnkOuter != NULL)
  288. {
  289. // don't support aggregation
  290. return E_NOTIMPL;
  291. }
  292. CShareCopyHook* pShareCopyHook = new CShareCopyHook();
  293. if (NULL == pShareCopyHook)
  294. {
  295. return E_OUTOFMEMORY;
  296. }
  297. HRESULT hr = pShareCopyHook->QueryInterface(riid, ppvObj);
  298. pShareCopyHook->Release();
  299. if (FAILED(hr))
  300. {
  301. hr = E_NOINTERFACE; // FEATURE: Whats the error code?
  302. }
  303. else
  304. {
  305. hr = S_OK;
  306. }
  307. return hr;
  308. }
  309. STDMETHODIMP
  310. CShareCopyHookCF::LockServer(BOOL fLock)
  311. {
  312. //
  313. // FEATURE: Whats supposed to happen here?
  314. //
  315. return S_OK;
  316. }
  317. //////////////////////////////////////////////////////////////////////////////
  318. //////////////////////////////////////////////////////////////////////////////
  319. STDAPI
  320. DllCanUnloadNow(
  321. VOID
  322. )
  323. {
  324. OneTimeInit();
  325. if (0 == g_ulcInstancesShare
  326. && 0 == g_ulcInstancesShareCopyHook
  327. && 0 == g_NonOLEDLLRefs)
  328. {
  329. return S_OK;
  330. }
  331. else
  332. {
  333. return S_FALSE;
  334. }
  335. }
  336. CShareCF cfShare;
  337. CShareCopyHookCF cfShareCopyHook;
  338. STDAPI
  339. DllGetClassObject(
  340. REFCLSID cid,
  341. REFIID iid,
  342. LPVOID* ppvObj
  343. )
  344. {
  345. OneTimeInit();
  346. appDebugOut((DEB_TRACE, "DllGetClassObject\n"));
  347. HRESULT hr = E_NOINTERFACE;
  348. if (IsEqualCLSID(cid, CLSID_CShare))
  349. {
  350. hr = cfShare.QueryInterface(iid, ppvObj);
  351. }
  352. else if (IsEqualCLSID(cid, CLSID_CShareCopyHook))
  353. {
  354. hr = cfShareCopyHook.QueryInterface(iid, ppvObj);
  355. }
  356. return hr;
  357. }