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.

308 lines
5.6 KiB

  1. #include <pch.cpp>
  2. #pragma hdrstop
  3. #include "csdisp.h"
  4. #include "csprop.h"
  5. #define __dwFILE__ __dwFILE_CERTLIB_EXITDISP_CPP__
  6. //+------------------------------------------------------------------------
  7. // ICertExit dispatch support
  8. //+------------------------------------
  9. // Initialize method:
  10. OLECHAR *exit_apszInitialize[] = {
  11. TEXT("Initialize"),
  12. TEXT("strConfig"),
  13. };
  14. //+------------------------------------
  15. // Notify method:
  16. OLECHAR *exit_apszNotify[] = {
  17. TEXT("Notify"),
  18. TEXT("ExitEvent"),
  19. TEXT("Context"),
  20. };
  21. //+------------------------------------
  22. // GetDescription method:
  23. OLECHAR *exit_apszGetDescription[] = {
  24. TEXT("GetDescription"),
  25. };
  26. //+------------------------------------
  27. // GetManageModule method:
  28. OLECHAR *exit_apszGetManageModule[] = {
  29. TEXT("GetManageModule"),
  30. };
  31. //+------------------------------------
  32. // Dispatch Table:
  33. DISPATCHTABLE g_adtExit[] =
  34. {
  35. DECLARE_DISPATCH_ENTRY(exit_apszInitialize)
  36. DECLARE_DISPATCH_ENTRY(exit_apszNotify)
  37. DECLARE_DISPATCH_ENTRY(exit_apszGetDescription)
  38. DECLARE_DISPATCH_ENTRY(exit_apszGetManageModule)
  39. };
  40. DWORD CEXITDISPATCH (ARRAYSIZE(g_adtExit));
  41. DWORD s_acExitDispatch[] = {
  42. CEXITDISPATCH_V2,
  43. CEXITDISPATCH_V1,
  44. };
  45. IID const *s_apExitiid[] = {
  46. &IID_ICertExit2,
  47. &IID_ICertExit,
  48. };
  49. HRESULT
  50. Exit_Init(
  51. IN DWORD Flags,
  52. IN LPCWSTR pcwszProgID,
  53. IN CLSID const *pclsid,
  54. OUT DISPATCHINTERFACE *pdi)
  55. {
  56. HRESULT hr;
  57. hr = DispatchSetup2(
  58. Flags,
  59. CLSCTX_INPROC_SERVER,
  60. pcwszProgID, // g_wszRegKeyCIPolicyClsid,
  61. pclsid,
  62. ARRAYSIZE(s_acExitDispatch),
  63. s_apExitiid,
  64. s_acExitDispatch,
  65. g_adtExit,
  66. pdi);
  67. _JumpIfError(hr, error, "DispatchSetup");
  68. pdi->pDispatchTable = g_adtPolicy;
  69. error:
  70. return(hr);
  71. }
  72. VOID
  73. Exit_Release(
  74. IN OUT DISPATCHINTERFACE *pdiManage)
  75. {
  76. DispatchRelease(pdiManage);
  77. }
  78. HRESULT
  79. ExitVerifyVersion(
  80. IN DISPATCHINTERFACE *pdiExit,
  81. IN DWORD RequiredVersion)
  82. {
  83. HRESULT hr;
  84. CSASSERT(NULL != pdiExit && NULL != pdiExit->pDispatchTable);
  85. switch (pdiExit->m_dwVersion)
  86. {
  87. case 1:
  88. CSASSERT(
  89. NULL == pdiExit->pDispatch ||
  90. CEXITDISPATCH_V1 == pdiExit->m_cDispatchTable);
  91. break;
  92. case 2:
  93. CSASSERT(
  94. NULL == pdiExit->pDispatch ||
  95. CEXITDISPATCH_V2 == pdiExit->m_cDispatchTable);
  96. break;
  97. default:
  98. hr = HRESULT_FROM_WIN32(ERROR_INTERNAL_ERROR);
  99. _JumpError(hr, error, "m_dwVersion");
  100. }
  101. if (pdiExit->m_dwVersion < RequiredVersion)
  102. {
  103. hr = E_NOTIMPL;
  104. _JumpError(hr, error, "old interface");
  105. }
  106. hr = S_OK;
  107. error:
  108. return(hr);
  109. }
  110. HRESULT
  111. Exit_Initialize(
  112. IN DISPATCHINTERFACE *pdiExit,
  113. IN BSTR strDescription,
  114. IN WCHAR const *pwszConfig,
  115. OUT LONG *pEventMask)
  116. {
  117. HRESULT hr;
  118. BSTR strConfig = NULL;
  119. if (!ConvertWszToBstr(&strConfig, pwszConfig, -1))
  120. {
  121. hr = E_OUTOFMEMORY;
  122. goto error;
  123. }
  124. __try
  125. {
  126. if (NULL != pdiExit->pDispatch)
  127. {
  128. VARIANT avar[1];
  129. CSASSERT(NULL != pdiExit->pDispatchTable);
  130. avar[0].vt = VT_BSTR;
  131. avar[0].bstrVal = strConfig;
  132. hr = DispatchInvoke(
  133. pdiExit,
  134. EXIT_INITIALIZE,
  135. ARRAYSIZE(avar),
  136. avar,
  137. VT_I4,
  138. pEventMask);
  139. _JumpIfError(hr, error, "Invoke(Initialize)");
  140. }
  141. else
  142. {
  143. hr = ((ICertExit *) pdiExit->pUnknown)->Initialize(
  144. strConfig,
  145. pEventMask);
  146. _JumpIfError(hr, error, "ICertExit::Initialize");
  147. }
  148. }
  149. _finally
  150. {
  151. if (NULL != strConfig)
  152. {
  153. SysFreeString(strConfig);
  154. }
  155. }
  156. error:
  157. return(hr);
  158. }
  159. HRESULT
  160. Exit_Notify(
  161. IN DISPATCHINTERFACE *pdiExit,
  162. IN BSTR strDescription,
  163. IN LONG ExitEvent,
  164. IN LONG Context)
  165. {
  166. HRESULT hr;
  167. if (NULL != pdiExit->pDispatch)
  168. {
  169. VARIANT avar[2];
  170. CSASSERT(NULL != pdiExit->pDispatchTable);
  171. avar[0].vt = VT_I4;
  172. avar[0].lVal = ExitEvent;
  173. avar[1].vt = VT_I4;
  174. avar[1].lVal = Context;
  175. hr = DispatchInvoke(
  176. pdiExit,
  177. EXIT_NOTIFY,
  178. ARRAYSIZE(avar),
  179. avar,
  180. 0,
  181. NULL);
  182. _JumpIfError(hr, error, "Invoke(Notify)");
  183. }
  184. else
  185. {
  186. hr = ((ICertExit *) pdiExit->pUnknown)->Notify(ExitEvent, Context);
  187. _JumpIfError(hr, error, "ICertExit::Notify");
  188. }
  189. error:
  190. return(hr);
  191. }
  192. HRESULT
  193. Exit_GetDescription(
  194. IN DISPATCHINTERFACE *pdiExit,
  195. OUT BSTR *pstrDescription)
  196. {
  197. HRESULT hr;
  198. if (NULL != pdiExit->pDispatch)
  199. {
  200. CSASSERT(NULL != pdiExit->pDispatchTable);
  201. hr = DispatchInvoke(
  202. pdiExit,
  203. EXIT_GETDESCRIPTION,
  204. 0,
  205. NULL,
  206. VT_BSTR,
  207. pstrDescription);
  208. _JumpIfError(hr, error, "Invoke(GetDescription)");
  209. }
  210. else
  211. {
  212. hr = ((ICertExit *) pdiExit->pUnknown)->GetDescription(pstrDescription);
  213. _JumpIfError(hr, error, "ICertExit::GetDescription");
  214. }
  215. error:
  216. return(hr);
  217. }
  218. HRESULT
  219. Exit2_GetManageModule(
  220. IN DISPATCHINTERFACE *pdiExit,
  221. OUT DISPATCHINTERFACE *pdiManageModule)
  222. {
  223. HRESULT hr;
  224. ICertManageModule *pManageModule = NULL;
  225. hr = ExitVerifyVersion(pdiExit, 2);
  226. _JumpIfError(hr, error, "ExitVerifyVersion");
  227. if (NULL != pdiExit->pDispatch)
  228. {
  229. CSASSERT(NULL != pdiExit->pDispatchTable);
  230. hr = DispatchInvoke(
  231. pdiExit,
  232. EXIT2_GETMANAGEMODULE,
  233. 0,
  234. NULL,
  235. VT_DISPATCH,
  236. &pManageModule);
  237. _JumpIfError(hr, error, "Invoke(GetManageModule)");
  238. }
  239. else
  240. {
  241. hr = ((ICertExit2 *) pdiExit->pUnknown)->GetManageModule(
  242. &pManageModule);
  243. _JumpIfError(hr, error, "ICertExit::GetManageModule");
  244. }
  245. hr = ManageModule_Init2(
  246. NULL != pdiExit->pDispatch,
  247. pManageModule,
  248. pdiManageModule);
  249. _JumpIfError(hr, error, "ManageModule_Init2");
  250. error:
  251. return(hr);
  252. }