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.

430 lines
8.1 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1995 - 1999
  6. //
  7. // File: viewext.cpp
  8. //
  9. // Contents: IEnumCERTVIEWEXTENSION IDispatch helper functions
  10. //
  11. //--------------------------------------------------------------------------
  12. #include <pch.cpp>
  13. #pragma hdrstop
  14. #include <stdlib.h>
  15. #include "csdisp.h"
  16. #include "csprop.h"
  17. //+------------------------------------------------------------------------
  18. // IEnumCERTVIEWEXTENSION dispatch support
  19. //+------------------------------------
  20. // OpenConnection method:
  21. static OLECHAR *_apszNext[] = {
  22. TEXT("Next"),
  23. };
  24. //+------------------------------------
  25. // GetName method:
  26. static OLECHAR *_apszGetName[] = {
  27. TEXT("GetName"),
  28. };
  29. //+------------------------------------
  30. // GetFlags method:
  31. static OLECHAR *_apszGetFlags[] = {
  32. TEXT("GetFlags"),
  33. };
  34. //+------------------------------------
  35. // GetValue method:
  36. static OLECHAR *_apszGetValue[] = {
  37. TEXT("GetValue"),
  38. TEXT("Type"),
  39. TEXT("Flags"),
  40. };
  41. //+------------------------------------
  42. // Skip method:
  43. static OLECHAR *_apszSkip[] = {
  44. TEXT("Skip"),
  45. TEXT("celt"),
  46. };
  47. //+------------------------------------
  48. // Reset method:
  49. static OLECHAR *_apszReset[] = {
  50. TEXT("Reset"),
  51. };
  52. //+------------------------------------
  53. // Clone method:
  54. static OLECHAR *_apszClone[] = {
  55. TEXT("Clone"),
  56. };
  57. //+------------------------------------
  58. // Dispatch Table:
  59. DISPATCHTABLE g_adtViewExtension[] =
  60. {
  61. #define VIEWEXT_NEXT 0
  62. DECLARE_DISPATCH_ENTRY(_apszNext)
  63. #define VIEWEXT_GETNAME 1
  64. DECLARE_DISPATCH_ENTRY(_apszGetName)
  65. #define VIEWEXT_GETFLAGS 2
  66. DECLARE_DISPATCH_ENTRY(_apszGetFlags)
  67. #define VIEWEXT_GETVALUE 3
  68. DECLARE_DISPATCH_ENTRY(_apszGetValue)
  69. #define VIEWEXT_SKIP 4
  70. DECLARE_DISPATCH_ENTRY(_apszSkip)
  71. #define VIEWEXT_RESET 5
  72. DECLARE_DISPATCH_ENTRY(_apszReset)
  73. #define VIEWEXT_CLONE 6
  74. DECLARE_DISPATCH_ENTRY(_apszClone)
  75. };
  76. #define CVIEWEXTDISPATCH (ARRAYSIZE(g_adtViewExtension))
  77. HRESULT
  78. ViewExtension_Init2(
  79. IN BOOL fIDispatch,
  80. IN IEnumCERTVIEWEXTENSION *pEnumExtension,
  81. OUT DISPATCHINTERFACE *pdiViewExtension)
  82. {
  83. HRESULT hr;
  84. IDispatch *pDispatch = NULL;
  85. static BOOL s_fInitialized = FALSE;
  86. pdiViewExtension->pDispatchTable = NULL;
  87. pdiViewExtension->pDispatch = NULL;
  88. pdiViewExtension->pUnknown = NULL;
  89. if (fIDispatch)
  90. {
  91. hr = pEnumExtension->QueryInterface(
  92. IID_IDispatch,
  93. (VOID **) &pDispatch);
  94. _JumpIfError(hr, error, "QueryInterface");
  95. hr = DispatchGetIds(
  96. pDispatch,
  97. CVIEWEXTDISPATCH,
  98. g_adtViewExtension,
  99. pdiViewExtension);
  100. _JumpIfError(hr, error, "DispatchGetIds");
  101. pdiViewExtension->pDispatch = pDispatch;
  102. pDispatch = NULL;
  103. }
  104. else
  105. {
  106. pEnumExtension->AddRef();
  107. pdiViewExtension->pUnknown = (IUnknown *) pEnumExtension;
  108. hr = S_OK;
  109. }
  110. pdiViewExtension->pDispatchTable = g_adtViewExtension;
  111. error:
  112. if (NULL != pDispatch)
  113. {
  114. pDispatch->Release();
  115. }
  116. return(hr);
  117. }
  118. VOID
  119. ViewExtension_Release(
  120. IN OUT DISPATCHINTERFACE *pdiViewExtension)
  121. {
  122. DispatchRelease(pdiViewExtension);
  123. }
  124. HRESULT
  125. ViewExtension_Next(
  126. IN DISPATCHINTERFACE *pdiViewExtension,
  127. OUT LONG *pIndex)
  128. {
  129. HRESULT hr;
  130. CSASSERT(NULL != pdiViewExtension && NULL != pdiViewExtension->pDispatchTable);
  131. if (NULL != pdiViewExtension->pDispatch)
  132. {
  133. hr = DispatchInvoke(
  134. pdiViewExtension,
  135. VIEWEXT_NEXT,
  136. 0,
  137. NULL,
  138. VT_I4,
  139. pIndex);
  140. _JumpIfError2(hr, error, "Invoke(Next)", S_FALSE);
  141. }
  142. else
  143. {
  144. hr = ((IEnumCERTVIEWEXTENSION *) pdiViewExtension->pUnknown)->Next(pIndex);
  145. _JumpIfError2(hr, error, "Next", S_FALSE);
  146. }
  147. error:
  148. return(hr);
  149. }
  150. HRESULT
  151. ViewExtension_GetName(
  152. IN DISPATCHINTERFACE *pdiViewExtension,
  153. OUT BSTR *pstrOut)
  154. {
  155. HRESULT hr;
  156. CSASSERT(NULL != pdiViewExtension && NULL != pdiViewExtension->pDispatchTable);
  157. if (NULL != pdiViewExtension->pDispatch)
  158. {
  159. hr = DispatchInvoke(
  160. pdiViewExtension,
  161. VIEWEXT_GETNAME,
  162. 0,
  163. NULL,
  164. VT_BSTR,
  165. pstrOut);
  166. _JumpIfError(hr, error, "Invoke(GetName)");
  167. }
  168. else
  169. {
  170. hr = ((IEnumCERTVIEWEXTENSION *) pdiViewExtension->pUnknown)->GetName(pstrOut);
  171. _JumpIfError(hr, error, "GetName");
  172. }
  173. error:
  174. return(hr);
  175. }
  176. HRESULT
  177. ViewExtension_GetFlags(
  178. IN DISPATCHINTERFACE *pdiViewExtension,
  179. OUT LONG *pFlags)
  180. {
  181. HRESULT hr;
  182. CSASSERT(NULL != pdiViewExtension && NULL != pdiViewExtension->pDispatchTable);
  183. if (NULL != pdiViewExtension->pDispatch)
  184. {
  185. hr = DispatchInvoke(
  186. pdiViewExtension,
  187. VIEWEXT_GETFLAGS,
  188. 0,
  189. NULL,
  190. VT_I4,
  191. pFlags);
  192. _JumpIfError(hr, error, "Invoke(GetFlags)");
  193. }
  194. else
  195. {
  196. hr = ((IEnumCERTVIEWEXTENSION *) pdiViewExtension->pUnknown)->GetFlags(pFlags);
  197. _JumpIfError(hr, error, "GetFlags");
  198. }
  199. error:
  200. return(hr);
  201. }
  202. HRESULT
  203. ViewExtension_GetValue(
  204. IN DISPATCHINTERFACE *pdiViewExtension,
  205. IN LONG Type,
  206. IN LONG Flags,
  207. OUT VOID *pValue)
  208. {
  209. HRESULT hr;
  210. LONG RetType;
  211. VARIANT varResult;
  212. VariantInit(&varResult);
  213. CSASSERT(NULL != pdiViewExtension && NULL != pdiViewExtension->pDispatchTable);
  214. switch (Type)
  215. {
  216. case PROPTYPE_BINARY:
  217. case PROPTYPE_STRING:
  218. RetType = VT_BSTR;
  219. break;
  220. case PROPTYPE_DATE:
  221. RetType = VT_DATE;
  222. break;
  223. case PROPTYPE_LONG:
  224. RetType = VT_I4;
  225. break;
  226. default:
  227. hr = E_INVALIDARG;
  228. _JumpError(hr, error, "PropertyType");
  229. }
  230. if (NULL != pdiViewExtension->pDispatch)
  231. {
  232. VARIANT avar[2];
  233. avar[0].vt = VT_I4;
  234. avar[0].lVal = Type;
  235. avar[1].vt = VT_I4;
  236. avar[1].lVal = Flags;
  237. hr = DispatchInvoke(
  238. pdiViewExtension,
  239. VIEWEXT_GETVALUE,
  240. ARRAYSIZE(avar),
  241. avar,
  242. RetType,
  243. pValue);
  244. _JumpIfError(hr, error, "Invoke(GetValue)");
  245. }
  246. else
  247. {
  248. hr = ((IEnumCERTVIEWEXTENSION *) pdiViewExtension->pUnknown)->GetValue(
  249. Type,
  250. Flags,
  251. &varResult);
  252. _JumpIfError2(hr, error, "GetValue", CERTSRV_E_PROPERTY_EMPTY);
  253. hr = DispatchGetReturnValue(&varResult, RetType, pValue);
  254. _JumpIfError2(hr, error, "DispatchGetReturnValue", CERTSRV_E_PROPERTY_EMPTY);
  255. }
  256. error:
  257. VariantClear(&varResult);
  258. return(hr);
  259. }
  260. HRESULT
  261. ViewExtension_Skip(
  262. IN DISPATCHINTERFACE *pdiViewExtension,
  263. IN LONG celt)
  264. {
  265. HRESULT hr;
  266. CSASSERT(NULL != pdiViewExtension && NULL != pdiViewExtension->pDispatchTable);
  267. if (NULL != pdiViewExtension->pDispatch)
  268. {
  269. VARIANT avar[1];
  270. avar[0].vt = VT_I4;
  271. avar[0].lVal = celt;
  272. hr = DispatchInvoke(
  273. pdiViewExtension,
  274. VIEWEXT_SKIP,
  275. ARRAYSIZE(avar),
  276. avar,
  277. 0,
  278. NULL);
  279. _JumpIfError(hr, error, "Invoke(Skip)");
  280. }
  281. else
  282. {
  283. hr = ((IEnumCERTVIEWEXTENSION *) pdiViewExtension->pUnknown)->Skip(celt);
  284. _JumpIfError(hr, error, "Skip");
  285. }
  286. error:
  287. return(hr);
  288. }
  289. HRESULT
  290. ViewExtension_Reset(
  291. IN DISPATCHINTERFACE *pdiViewExtension)
  292. {
  293. HRESULT hr;
  294. CSASSERT(NULL != pdiViewExtension && NULL != pdiViewExtension->pDispatchTable);
  295. if (NULL != pdiViewExtension->pDispatch)
  296. {
  297. hr = DispatchInvoke(
  298. pdiViewExtension,
  299. VIEWEXT_RESET,
  300. 0,
  301. NULL,
  302. 0,
  303. NULL);
  304. _JumpIfError(hr, error, "Invoke(Reset)");
  305. }
  306. else
  307. {
  308. hr = ((IEnumCERTVIEWEXTENSION *) pdiViewExtension->pUnknown)->Reset();
  309. _JumpIfError(hr, error, "Reset");
  310. }
  311. error:
  312. return(hr);
  313. }
  314. HRESULT
  315. ViewExtension_Clone(
  316. IN DISPATCHINTERFACE *pdiViewExtension,
  317. OUT DISPATCHINTERFACE *pdiViewExtensionClone)
  318. {
  319. HRESULT hr;
  320. IEnumCERTVIEWEXTENSION *pEnumExtension = NULL;
  321. CSASSERT(NULL != pdiViewExtension && NULL != pdiViewExtension->pDispatchTable);
  322. if (NULL != pdiViewExtension->pDispatch)
  323. {
  324. hr = DispatchInvoke(
  325. pdiViewExtension,
  326. VIEWEXT_CLONE,
  327. 0,
  328. NULL,
  329. VT_DISPATCH,
  330. &pEnumExtension);
  331. _JumpIfError(hr, error, "Invoke(Clone)");
  332. }
  333. else
  334. {
  335. hr = ((IEnumCERTVIEWEXTENSION *) pdiViewExtension->pUnknown)->Clone(
  336. &pEnumExtension);
  337. _JumpIfError(hr, error, "Clone");
  338. }
  339. hr = ViewExtension_Init2(
  340. NULL != pdiViewExtension->pDispatch,
  341. pEnumExtension,
  342. pdiViewExtensionClone);
  343. _JumpIfError(hr, error, "ViewExtension_Init2");
  344. error:
  345. if (NULL != pEnumExtension)
  346. {
  347. pEnumExtension->Release();
  348. }
  349. return(hr);
  350. }