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.

257 lines
5.2 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. //
  10. // History: 25-Sep-95 BruceFo Created
  11. //
  12. //----------------------------------------------------------------------------
  13. #include "headers.hxx"
  14. #pragma hdrstop
  15. #include <initguid.h>
  16. #include "guids.h"
  17. #include "ole.hxx"
  18. #include "ext.hxx"
  19. //////////////////////////////////////////////////////////////////////////////
  20. //////////////////////////////////////////////////////////////////////////////
  21. ULONG g_ulcInstancesNetObj = 0;
  22. //////////////////////////////////////////////////////////////////////////////
  23. //////////////////////////////////////////////////////////////////////////////
  24. STDMETHODIMP
  25. CNetObj::QueryInterface(
  26. IN REFIID riid,
  27. OUT LPVOID* ppvObj
  28. )
  29. {
  30. appDebugOut((DEB_ITRACE, "CNetObj::QueryInterface..."));
  31. *ppvObj = NULL;
  32. IUnknown* pUnkTemp = NULL;
  33. HRESULT hr = S_OK;
  34. if (IsEqualIID(IID_IUnknown, riid))
  35. {
  36. appDebugOut((DEB_ITRACE | DEB_NOCOMPNAME, "IUnknown\n"));
  37. pUnkTemp = (IUnknown*)(IShellExtInit*) this; // doesn't matter which
  38. }
  39. else
  40. if (IsEqualIID(IID_IShellExtInit, riid))
  41. {
  42. appDebugOut((DEB_ITRACE | DEB_NOCOMPNAME, "IShellExtInit\n"));
  43. pUnkTemp = (IShellExtInit*) this;
  44. }
  45. else
  46. if (IsEqualIID(IID_IShellPropSheetExt, riid))
  47. {
  48. appDebugOut((DEB_ITRACE | DEB_NOCOMPNAME, "IShellPropSheetExt\n"));
  49. pUnkTemp = (IShellPropSheetExt*) this;
  50. }
  51. else
  52. {
  53. appDebugOut((DEB_ITRACE | DEB_NOCOMPNAME, "unknown interface\n"));
  54. hr = E_NOINTERFACE;
  55. }
  56. if (pUnkTemp != NULL)
  57. {
  58. pUnkTemp->AddRef();
  59. }
  60. *ppvObj = pUnkTemp;
  61. return hr;
  62. }
  63. STDMETHODIMP_(ULONG)
  64. CNetObj::AddRef(
  65. VOID
  66. )
  67. {
  68. InterlockedIncrement((LONG*)&g_ulcInstancesNetObj);
  69. InterlockedIncrement((LONG*)&_uRefs);
  70. appDebugOut((DEB_ITRACE,
  71. "CNetObj::AddRef, local: %d, DLL: %d\n",
  72. _uRefs,
  73. g_ulcInstancesNetObj));
  74. return _uRefs;
  75. }
  76. STDMETHODIMP_(ULONG)
  77. CNetObj::Release(
  78. VOID
  79. )
  80. {
  81. InterlockedDecrement((LONG*)&g_ulcInstancesNetObj);
  82. ULONG cRef = InterlockedDecrement((LONG*)&_uRefs);
  83. appDebugOut((DEB_ITRACE,
  84. "CNetObj::Release, local: %d, DLL: %d\n",
  85. _uRefs,
  86. g_ulcInstancesNetObj));
  87. if (0 == cRef)
  88. {
  89. delete this;
  90. }
  91. return cRef;
  92. }
  93. //////////////////////////////////////////////////////////////////////////////
  94. STDMETHODIMP
  95. CNetObjCF::QueryInterface(REFIID riid, LPVOID* ppvObj)
  96. {
  97. appDebugOut((DEB_ITRACE, "CNetObjCF::QueryInterface..."));
  98. *ppvObj = NULL;
  99. IUnknown* pUnkTemp = NULL;
  100. HRESULT hr = S_OK;
  101. if (IsEqualIID(IID_IUnknown, riid))
  102. {
  103. appDebugOut((DEB_ITRACE | DEB_NOCOMPNAME, "IUnknown\n"));
  104. pUnkTemp = (IUnknown*) this;
  105. }
  106. else if (IsEqualIID(IID_IClassFactory, riid))
  107. {
  108. appDebugOut((DEB_ITRACE | DEB_NOCOMPNAME, "IClassFactory\n"));
  109. pUnkTemp = (IClassFactory*) this;
  110. }
  111. else
  112. {
  113. appDebugOut((DEB_ITRACE | DEB_NOCOMPNAME, "unknown interface\n"));
  114. hr = E_NOINTERFACE;
  115. }
  116. if (pUnkTemp != NULL)
  117. {
  118. pUnkTemp->AddRef();
  119. }
  120. *ppvObj = pUnkTemp;
  121. return hr;
  122. }
  123. STDMETHODIMP_(ULONG)
  124. CNetObjCF::AddRef()
  125. {
  126. InterlockedIncrement((LONG*)&g_ulcInstancesNetObj);
  127. appDebugOut((DEB_ITRACE,
  128. "CNetObjCF::AddRef, DLL: %d\n",
  129. g_ulcInstancesNetObj));
  130. return g_ulcInstancesNetObj;
  131. }
  132. STDMETHODIMP_(ULONG)
  133. CNetObjCF::Release()
  134. {
  135. InterlockedDecrement((LONG*)&g_ulcInstancesNetObj);
  136. appDebugOut((DEB_ITRACE,
  137. "CNetObjCF::Release, DLL: %d\n",
  138. g_ulcInstancesNetObj));
  139. return g_ulcInstancesNetObj;
  140. }
  141. STDMETHODIMP
  142. CNetObjCF::CreateInstance(IUnknown* pUnkOuter, REFIID riid, LPVOID* ppvObj)
  143. {
  144. appDebugOut((DEB_ITRACE, "CNetObjCF::CreateInstance\n"));
  145. if (pUnkOuter != NULL)
  146. {
  147. // don't support aggregation
  148. return E_NOTIMPL;
  149. }
  150. CNetObj* pNetObj = new CNetObj();
  151. if (NULL == pNetObj)
  152. {
  153. return E_OUTOFMEMORY;
  154. }
  155. HRESULT hr = pNetObj->QueryInterface(riid, ppvObj);
  156. pNetObj->Release();
  157. if (FAILED(hr))
  158. {
  159. hr = E_NOINTERFACE; // FEATURE: Whats the error code?
  160. }
  161. else
  162. {
  163. hr = S_OK;
  164. }
  165. return hr;
  166. }
  167. STDMETHODIMP
  168. CNetObjCF::LockServer(BOOL fLock)
  169. {
  170. //
  171. // FEATURE: Whats supposed to happen here?
  172. //
  173. return S_OK;
  174. }
  175. //////////////////////////////////////////////////////////////////////////////
  176. //////////////////////////////////////////////////////////////////////////////
  177. STDAPI
  178. DllCanUnloadNow(
  179. VOID
  180. )
  181. {
  182. if (0 == g_ulcInstancesNetObj
  183. && 0 == g_NonOLEDLLRefs
  184. )
  185. {
  186. return S_OK;
  187. }
  188. else
  189. {
  190. return S_FALSE;
  191. }
  192. }
  193. CNetObjCF cfNetObj;
  194. STDAPI
  195. DllGetClassObject(
  196. REFCLSID cid,
  197. REFIID iid,
  198. LPVOID* ppvObj
  199. )
  200. {
  201. appDebugOut((DEB_TRACE, "DllGetClassObject\n"));
  202. HRESULT hr = E_NOINTERFACE;
  203. if (IsEqualCLSID(cid, CLSID_CNetObj))
  204. {
  205. hr = cfNetObj.QueryInterface(iid, ppvObj);
  206. }
  207. return hr;
  208. }