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.

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