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.

271 lines
7.1 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1994.
  5. //
  6. // File: ole2splt.cxx
  7. //
  8. // Contents: OLE2 API whose implementation is split between 16/32
  9. //
  10. // History: 07-Mar-94 DrewB Created
  11. //
  12. //----------------------------------------------------------------------------
  13. #include <headers.cxx>
  14. #pragma hdrstop
  15. #include <ole2sp.h>
  16. #include <ole2int.h>
  17. #include <ole2ver.h>
  18. #include <olecoll.h>
  19. #include <map_kv.h>
  20. #include <map_htsk.h>
  21. #include <etask.hxx>
  22. #include <call32.hxx>
  23. #include <apilist.hxx>
  24. // MFC HACK ALERT!!! The followind constant is needed
  25. // for an MFC workaround. See OleInitialize for details
  26. #define CLIPBOARDWNDCLASS "CLIPBOARDWNDCLASS"
  27. //+---------------------------------------------------------------------------
  28. //
  29. // Function: OleInitialize, Split
  30. //
  31. // Synopsis:
  32. //
  33. // Effects:
  34. //
  35. // Arguments: [pMalloc] --
  36. //
  37. // Requires:
  38. //
  39. // Returns:
  40. //
  41. // Signals:
  42. //
  43. // Modifies:
  44. //
  45. // Algorithm:
  46. //
  47. // History: 2-28-94 kevinro Created
  48. // 05-26-94 AlexT Return correct success code
  49. // 08-22-94 AlexGo added MFC CreateWindow hack
  50. //
  51. // Notes:
  52. //
  53. //----------------------------------------------------------------------------
  54. STDAPI OleInitialize(LPMALLOC pMalloc)
  55. {
  56. HTASK htask;
  57. Etask etask;
  58. HRESULT hrCoInit, hrOleInit;
  59. static BOOL fCreatedClipWindowClass = FALSE;
  60. /* This version of ole2.dll simply needs to work with the same major build
  61. of compobj.dll. Future versions of ole2.dll might be restricted to
  62. certain builds of compobj.dll. */
  63. if (HIWORD(CoBuildVersion()) != rmm)
  64. {
  65. return ResultFromScode(OLE_E_WRONGCOMPOBJ);
  66. }
  67. /* if already initialize one or more times, just bump count and return. */
  68. if (LookupEtask(htask, etask) && etask.m_oleinits != 0)
  69. {
  70. etask.m_oleinits++;
  71. thkVerify(SetEtask(htask, etask));
  72. return ResultFromScode(S_FALSE);
  73. }
  74. /* Initialize the 16-bit side of compobj */
  75. hrCoInit = CoInitialize(pMalloc);
  76. if (SUCCEEDED(GetScode(hrCoInit)))
  77. {
  78. /* Thunk OleInitialize
  79. Never pass on the IMalloc */
  80. pMalloc = NULL;
  81. hrOleInit = (HRESULT)CallObjectInWOW(THK_API_METHOD(THK_API_OleInitialize),
  82. PASCAL_STACK_PTR(pMalloc) );
  83. if (FAILED(GetScode(hrOleInit)))
  84. {
  85. CoUninitialize();
  86. return(hrOleInit);
  87. }
  88. thkVerify(LookupEtask(htask, etask) && etask.m_oleinits == 0);
  89. etask.m_oleinits++;
  90. thkVerify(SetEtask(htask, etask));
  91. }
  92. // Since we call 32-bit CoInitialize and then call 32-bit OleInitialize,
  93. // and since the latter internally calls CoInitialize (a second time), we
  94. // want to return the HRESULT of the call to CoInitialize since some
  95. // applications look for S_OK (and our call to OleInitialize will return
  96. // S_FALSE since it will be the second call to CoInitialize).
  97. // MFC HACK ALERT!! MFC2.5 (16bit) has a hack where they scan the
  98. // window hierarchy for a window named "CLIPBOARDWNDCLASS". They then
  99. // subclass this window and do their own processing for clipboard
  100. // windows messages.
  101. //
  102. // In order to make them work, we create a dummy window for MFC to party
  103. // on. This allows them to successfully subclass and not interfere
  104. // with 32bit OLE processing. (since it's a dummy window)
  105. //
  106. // NB!! We do not bother with resource cleanup; we'll leave this window
  107. // around until the process exits. We also don't care about errors
  108. // here. In the off chance that one of the calls fails and we *don't*
  109. // create a window that MFC can party on, then MFC *debug* apps will
  110. // popup an assert dialog. You can safely click 'OK' on this dialog
  111. // and the app will proceed without undue trauma.
  112. if( !fCreatedClipWindowClass )
  113. {
  114. WNDCLASS wc;
  115. // Register Clipboard window class
  116. //
  117. wc.style = 0;
  118. wc.lpfnWndProc = DefWindowProc;
  119. wc.cbClsExtra = 0;
  120. wc.cbWndExtra = 4;
  121. wc.hInstance = hmodOLE2;
  122. wc.hIcon = NULL;
  123. wc.hCursor = NULL;
  124. wc.hbrBackground = NULL;
  125. wc.lpszMenuName = NULL;
  126. wc.lpszClassName = CLIPBOARDWNDCLASS;
  127. // don't bother checking for errors
  128. RegisterClass(&wc);
  129. fCreatedClipWindowClass = TRUE;
  130. }
  131. CreateWindow(CLIPBOARDWNDCLASS,"",WS_POPUP,CW_USEDEFAULT,
  132. CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,
  133. NULL,NULL,hmodOLE2,NULL);
  134. return hrOleInit;
  135. }
  136. //+---------------------------------------------------------------------------
  137. //
  138. // Function: OleUninitialize, Split
  139. //
  140. // Synopsis:
  141. //
  142. // Effects:
  143. //
  144. // Arguments: [void] --
  145. //
  146. // Requires:
  147. //
  148. // Returns:
  149. //
  150. // Signals:
  151. //
  152. // Modifies:
  153. //
  154. // Algorithm:
  155. //
  156. // History: 2-28-94 kevinro Created
  157. //
  158. // Notes:
  159. //
  160. //----------------------------------------------------------------------------
  161. STDAPI_(void) OleUninitialize(void)
  162. {
  163. HTASK htask;
  164. Etask etask;
  165. /* If not init, just return */
  166. if (!LookupEtask(htask, etask) || etask.m_oleinits == 0)
  167. {
  168. return;
  169. }
  170. /* Must always decrement count and set since compobj may still be init'd */
  171. etask.m_oleinits--;
  172. thkVerify(SetEtask(htask, etask));
  173. /* if not last uninit, now return */
  174. if (etask.m_oleinits != 0)
  175. {
  176. return;
  177. }
  178. /* After this point, the uninit should not fail (because we don't have
  179. code to redo the init). */
  180. CallObjectInWOW(THK_API_METHOD(THK_API_OleUninitialize), NULL );
  181. CoUninitialize();
  182. }
  183. //+---------------------------------------------------------------------------
  184. //
  185. // Function: ReadClassStm, Split
  186. //
  187. // Synopsis:
  188. //
  189. // Effects:
  190. //
  191. // Arguments: [pStm] --
  192. // [pclsid] --
  193. //
  194. // Requires:
  195. //
  196. // Returns:
  197. //
  198. // Signals:
  199. //
  200. // Modifies:
  201. //
  202. // Algorithm:
  203. //
  204. // History: 2-28-94 kevinro Created
  205. //
  206. // Notes:
  207. //
  208. //----------------------------------------------------------------------------
  209. STDAPI ReadClassStm(LPSTREAM pStm, CLSID FAR* pclsid)
  210. {
  211. return (HRESULT)CallObjectInWOW(THK_API_METHOD(THK_API_ReadClassStm),
  212. PASCAL_STACK_PTR(pStm) );
  213. }
  214. //+---------------------------------------------------------------------------
  215. //
  216. // Function: WriteClassStm, Split
  217. //
  218. // Synopsis:
  219. //
  220. // Effects:
  221. //
  222. // Arguments: [pStm] --
  223. // [rclsid] --
  224. //
  225. // Requires:
  226. //
  227. // Returns:
  228. //
  229. // Signals:
  230. //
  231. // Modifies:
  232. //
  233. // Algorithm:
  234. //
  235. // History: 2-28-94 kevinro Created
  236. //
  237. // Notes:
  238. //
  239. //----------------------------------------------------------------------------
  240. STDAPI WriteClassStm(LPSTREAM pStm, REFCLSID rclsid)
  241. {
  242. return (HRESULT)CallObjectInWOW(THK_API_METHOD(THK_API_WriteClassStm) ,
  243. PASCAL_STACK_PTR(pStm) );
  244. }