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.

253 lines
6.1 KiB

  1. #pragma once
  2. #include "ihost.h"
  3. #include "ithunk.h"
  4. #include "idsource.h"
  5. #include "iuiview.h"
  6. HRESULT
  7. SxApwHostCreateObject(
  8. REFCLSID rclsid,
  9. REFIID riid,
  10. DWORD dwFlags,
  11. void** pp
  12. );
  13. /*
  14. an acceptable error from CreateActCtx
  15. */
  16. BOOL
  17. SxApwIsErrorResourceNotFound(
  18. DWORD dwError
  19. );
  20. class CSxApwActCtxHandle;
  21. class CSxApwActCtxScope;
  22. class CSxApwActCtxHandle : public CFusionActCtxHandle
  23. {
  24. private:
  25. typedef CFusionActCtxHandle Base;
  26. public:
  27. CSxApwActCtxHandle() { }
  28. CSxApwActCtxHandle(HANDLE handle) : Base(handle) { }
  29. ~CSxApwActCtxHandle() { }
  30. void operator=(HANDLE handle) { Base::operator=(handle); }
  31. HRESULT HrCreate(const std::wstring& dllPath)
  32. {
  33. HRESULT hr = S_OK;
  34. ACTCTXW actCtx;
  35. BOOL fResourceNotFound = FALSE;
  36. actCtx.cbSize = sizeof(actCtx);
  37. actCtx.dwFlags = ACTCTX_FLAG_RESOURCE_NAME_VALID;
  38. actCtx.lpResourceName = MAKEINTRESOURCE(3); // magic number
  39. actCtx.lpSource = dllPath.c_str();
  40. IFFALSE_WIN32TOHR_EXIT(hr, Win32Create(&actCtx)
  41. || (fResourceNotFound = SxApwIsErrorResourceNotFound(::GetLastError())));
  42. if (fResourceNotFound)
  43. Base::operator=(static_cast<HANDLE>(NULL));
  44. hr = S_OK;
  45. Exit:
  46. return hr;
  47. }
  48. };
  49. template <typename T>
  50. class CSxApwThunk
  51. {
  52. public:
  53. CSxApwThunk() { }
  54. ~CSxApwThunk()
  55. {
  56. //hack/leak/undone/garbage
  57. //if (m_actctxHandle != NULL)
  58. // SxApwReleaseActCtx(m_actctxHandle->GetCPlusPlusObject());
  59. }
  60. STDMETHOD(InitThunk)(
  61. IUnknown* underlyingUnknown,
  62. HANDLE actctxHandle
  63. )
  64. {
  65. m_underlying = underlyingUnknown;
  66. m_actctxHandle = actctxHandle;
  67. return S_OK;
  68. }
  69. protected:
  70. CSxApwComPtr<T> m_underlying;
  71. CSxApwActCtxHandle m_actctxHandle;
  72. private:
  73. CSxApwThunk(const CSxApwThunk&); // intentially not implemented
  74. void operator=(const CSxApwThunk&); // intentially not implemented
  75. };
  76. class __declspec(uuid(CLSID_CSxApwHostThunk_declspec_uuid)) CSxApwHostThunk :
  77. public ATL::CComObjectRootEx<CComSingleThreadModel>,
  78. public ATL::CComCoClass<CSxApwHostThunk, &__uuidof(CSxApwHostThunk)>,
  79. public ISxApwHost,
  80. public ISxApwThunk,
  81. public CSxApwThunk<ISxApwHost>
  82. {
  83. typedef CSxApwThunk<ISxApwHost> CSxApwThunk;
  84. public:
  85. BEGIN_COM_MAP(CSxApwHostThunk)
  86. COM_INTERFACE_ENTRY(ISxApwHost)
  87. COM_INTERFACE_ENTRY(ISxApwThunk)
  88. COM_INTERFACE_ENTRY(CSxApwHostThunk)
  89. END_COM_MAP()
  90. DECLARE_NO_REGISTRY();
  91. CSxApwHostThunk() { }
  92. ~CSxApwHostThunk() { }
  93. typedef ISxApwHost ThunkedInterface;
  94. STDMETHOD(InitThunk)(
  95. IUnknown* underlyingUnknown,
  96. HANDLE actctxHandle
  97. ) { return CSxApwThunk::InitThunk(underlyingUnknown, actctxHandle); }
  98. STDMETHOD(RunQuery)(
  99. LPCWSTR
  100. );
  101. STDMETHOD(SetDataSource)(
  102. LPCWSTR
  103. );
  104. STDMETHOD(CreateView)(
  105. LPCWSTR
  106. );
  107. STDMETHOD(DestroyView)(
  108. LPCWSTR
  109. );
  110. STDMETHOD(OnQueryDone)(
  111. );
  112. STDMETHOD(InformSchema)(
  113. const SxApwColumnInfo rgColumnInfo[],
  114. int nColumns
  115. );
  116. STDMETHOD(OnNextRow)(
  117. int nColumns,
  118. const LPCWSTR columns[]
  119. );
  120. STDMETHOD(OnRowCountEstimateAvailable)(
  121. int nRowCountEstimate
  122. );
  123. private:
  124. CSxApwHostThunk(const CSxApwHostThunk&); // intentially not implemented
  125. void operator=(const CSxApwHostThunk&); // intentially not implemented
  126. };
  127. class __declspec(uuid(CLSID_CSxApwDataSourceThunk_declspec_uuid)) CSxApwDataSourceThunk :
  128. public ATL::CComObjectRootEx<CComSingleThreadModel>,
  129. public ATL::CComCoClass<CSxApwDataSourceThunk, &__uuidof(CSxApwDataSourceThunk)>,
  130. public ISxApwDataSource,
  131. public ISxApwThunk,
  132. public CSxApwThunk<ISxApwDataSource>
  133. {
  134. typedef CSxApwThunk<ISxApwDataSource> CSxApwThunk;
  135. public:
  136. BEGIN_COM_MAP(CSxApwDataSourceThunk)
  137. COM_INTERFACE_ENTRY(ISxApwDataSource)
  138. COM_INTERFACE_ENTRY(ISxApwThunk)
  139. END_COM_MAP()
  140. DECLARE_NO_REGISTRY();
  141. typedef ISxApwDataSource ThunkedInterface;
  142. CSxApwDataSourceThunk() { }
  143. ~CSxApwDataSourceThunk() { }
  144. STDMETHOD(InitThunk)(
  145. IUnknown* underlyingUnknown,
  146. HANDLE actctxHandle
  147. ) { return CSxApwThunk::InitThunk(underlyingUnknown, actctxHandle); }
  148. STDMETHOD(SetSite)(
  149. ISxApwHost* host
  150. );
  151. STDMETHOD(RunQuery)(
  152. LPCWSTR query
  153. );
  154. STDMETHOD(StopQuery)(
  155. );
  156. private:
  157. CSxApwDataSourceThunk(const CSxApwDataSourceThunk&); // intentially not implemented
  158. void operator=(const CSxApwDataSourceThunk&); // intentially not implemented
  159. };
  160. class __declspec(uuid(CLSID_CSxApwUiViewThunk_declspec_uuid)) CSxApwUiViewThunk :
  161. public ATL::CComObjectRootEx<CComSingleThreadModel>,
  162. public ATL::CComCoClass<CSxApwUiViewThunk, &__uuidof(CSxApwUiViewThunk)>,
  163. public ISxApwUiView,
  164. public ISxApwThunk,
  165. public CSxApwThunk<ISxApwUiView>
  166. {
  167. typedef CSxApwThunk<ISxApwUiView> CSxApwThunk;
  168. public:
  169. typedef ISxApwUiView ThunkedInterface;
  170. BEGIN_COM_MAP(CSxApwUiViewThunk)
  171. COM_INTERFACE_ENTRY(ISxApwUiView)
  172. COM_INTERFACE_ENTRY(ISxApwThunk)
  173. END_COM_MAP()
  174. DECLARE_NO_REGISTRY();
  175. CSxApwUiViewThunk() { }
  176. ~CSxApwUiViewThunk() { }
  177. STDMETHOD(InitThunk)(
  178. IUnknown* underlyingUnknown,
  179. HANDLE actctxHandle
  180. ) { return CSxApwThunk::InitThunk(underlyingUnknown, actctxHandle); }
  181. STDMETHOD(SetSite)(
  182. ISxApwHost* host
  183. );
  184. STDMETHOD(CreateWindow)(
  185. HWND hWnd
  186. );
  187. STDMETHOD(OnNextRow)(
  188. int nColumns,
  189. const LPCWSTR* prgszColumns
  190. );
  191. STDMETHOD(OnRowCountEstimateAvailable)(
  192. int nRowCountEstimate
  193. );
  194. STDMETHOD(OnQueryStart)(
  195. );
  196. STDMETHOD(OnQueryDone)(
  197. );
  198. STDMETHOD(InformSchema)(
  199. const SxApwColumnInfo rgColumnInfo[],
  200. int nColumns
  201. );
  202. private:
  203. CSxApwUiViewThunk(const CSxApwUiViewThunk&); // intentially not implemented
  204. void operator=(const CSxApwUiViewThunk&); // intentially not implemented
  205. };