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.

550 lines
10 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1995 - 1999
  6. //
  7. // File: viewcol.cpp
  8. //
  9. // Contents: IEnumCERTVIEWCOLUMN 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. // IEnumCERTVIEWCOLUMN 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. // GetDisplayName method:
  31. static OLECHAR *_apszGetDisplayName[] = {
  32. TEXT("GetDisplayName"),
  33. };
  34. //+------------------------------------
  35. // GetType method:
  36. static OLECHAR *_apszGetType[] = {
  37. TEXT("GetType"),
  38. };
  39. //+------------------------------------
  40. // IsIndexed method:
  41. static OLECHAR *_apszIsIndexed[] = {
  42. TEXT("IsIndexed"),
  43. };
  44. //+------------------------------------
  45. // GetMaxLength method:
  46. static OLECHAR *_apszGetMaxLength[] = {
  47. TEXT("GetMaxLength"),
  48. };
  49. //+------------------------------------
  50. // GetValue method:
  51. static OLECHAR *_apszGetValue[] = {
  52. TEXT("GetValue"),
  53. TEXT("Flags"),
  54. };
  55. //+------------------------------------
  56. // Skip method:
  57. static OLECHAR *_apszSkip[] = {
  58. TEXT("Skip"),
  59. TEXT("celt"),
  60. };
  61. //+------------------------------------
  62. // Reset method:
  63. static OLECHAR *_apszReset[] = {
  64. TEXT("Reset"),
  65. };
  66. //+------------------------------------
  67. // Clone method:
  68. static OLECHAR *_apszClone[] = {
  69. TEXT("Clone"),
  70. };
  71. //+------------------------------------
  72. // Dispatch Table:
  73. DISPATCHTABLE g_adtViewColumn[] =
  74. {
  75. #define VIEWCOL_NEXT 0
  76. DECLARE_DISPATCH_ENTRY(_apszNext)
  77. #define VIEWCOL_GETNAME 1
  78. DECLARE_DISPATCH_ENTRY(_apszGetName)
  79. #define VIEWCOL_GETDISPLAYNAME 2
  80. DECLARE_DISPATCH_ENTRY(_apszGetDisplayName)
  81. #define VIEWCOL_GETTYPE 3
  82. DECLARE_DISPATCH_ENTRY(_apszGetType)
  83. #define VIEWCOL_ISINDEXED 4
  84. DECLARE_DISPATCH_ENTRY(_apszIsIndexed)
  85. #define VIEWCOL_GETMAXLENGTH 5
  86. DECLARE_DISPATCH_ENTRY(_apszGetMaxLength)
  87. #define VIEWCOL_GETVALUE 6
  88. DECLARE_DISPATCH_ENTRY(_apszGetValue)
  89. #define VIEWCOL_SKIP 7
  90. DECLARE_DISPATCH_ENTRY(_apszSkip)
  91. #define VIEWCOL_RESET 8
  92. DECLARE_DISPATCH_ENTRY(_apszReset)
  93. #define VIEWCOL_CLONE 9
  94. DECLARE_DISPATCH_ENTRY(_apszClone)
  95. };
  96. #define CVIEWCOLDISPATCH (ARRAYSIZE(g_adtViewColumn))
  97. HRESULT
  98. ViewColumn_Init2(
  99. IN BOOL fIDispatch,
  100. IN IEnumCERTVIEWCOLUMN *pEnumColumn,
  101. OUT DISPATCHINTERFACE *pdiViewColumn)
  102. {
  103. HRESULT hr;
  104. IDispatch *pDispatch = NULL;
  105. static BOOL s_fInitialized = FALSE;
  106. pdiViewColumn->pDispatchTable = NULL;
  107. pdiViewColumn->pDispatch = NULL;
  108. pdiViewColumn->pUnknown = NULL;
  109. if (fIDispatch)
  110. {
  111. hr = pEnumColumn->QueryInterface(
  112. IID_IDispatch,
  113. (VOID **) &pDispatch);
  114. _JumpIfError(hr, error, "QueryInterface");
  115. hr = DispatchGetIds(
  116. pDispatch,
  117. CVIEWCOLDISPATCH,
  118. g_adtViewColumn,
  119. pdiViewColumn);
  120. _JumpIfError(hr, error, "DispatchGetIds");
  121. pdiViewColumn->pDispatch = pDispatch;
  122. pDispatch = NULL;
  123. }
  124. else
  125. {
  126. pEnumColumn->AddRef();
  127. pdiViewColumn->pUnknown = (IUnknown *) pEnumColumn;
  128. hr = S_OK;
  129. }
  130. pdiViewColumn->pDispatchTable = g_adtViewColumn;
  131. error:
  132. if (NULL != pDispatch)
  133. {
  134. pDispatch->Release();
  135. }
  136. return(hr);
  137. }
  138. VOID
  139. ViewColumn_Release(
  140. IN OUT DISPATCHINTERFACE *pdiViewColumn)
  141. {
  142. DispatchRelease(pdiViewColumn);
  143. }
  144. HRESULT
  145. ViewColumn_Next(
  146. IN DISPATCHINTERFACE *pdiViewColumn,
  147. OUT LONG *pIndex)
  148. {
  149. HRESULT hr;
  150. CSASSERT(NULL != pdiViewColumn && NULL != pdiViewColumn->pDispatchTable);
  151. if (NULL != pdiViewColumn->pDispatch)
  152. {
  153. hr = DispatchInvoke(
  154. pdiViewColumn,
  155. VIEWCOL_NEXT,
  156. 0,
  157. NULL,
  158. VT_I4,
  159. pIndex);
  160. _JumpIfError2(hr, error, "Invoke(Next)", S_FALSE);
  161. }
  162. else
  163. {
  164. hr = ((IEnumCERTVIEWCOLUMN *) pdiViewColumn->pUnknown)->Next(pIndex);
  165. _JumpIfError2(hr, error, "Next", S_FALSE);
  166. }
  167. error:
  168. return(hr);
  169. }
  170. HRESULT
  171. ViewColumn_GetName(
  172. IN DISPATCHINTERFACE *pdiViewColumn,
  173. OUT BSTR *pstrOut)
  174. {
  175. HRESULT hr;
  176. CSASSERT(NULL != pdiViewColumn && NULL != pdiViewColumn->pDispatchTable);
  177. if (NULL != pdiViewColumn->pDispatch)
  178. {
  179. hr = DispatchInvoke(
  180. pdiViewColumn,
  181. VIEWCOL_GETNAME,
  182. 0,
  183. NULL,
  184. VT_BSTR,
  185. pstrOut);
  186. _JumpIfError(hr, error, "Invoke(GetName)");
  187. }
  188. else
  189. {
  190. hr = ((IEnumCERTVIEWCOLUMN *) pdiViewColumn->pUnknown)->GetName(pstrOut);
  191. _JumpIfError(hr, error, "GetName");
  192. }
  193. error:
  194. return(hr);
  195. }
  196. HRESULT
  197. ViewColumn_GetDisplayName(
  198. IN DISPATCHINTERFACE *pdiViewColumn,
  199. OUT BSTR *pstrOut)
  200. {
  201. HRESULT hr;
  202. CSASSERT(NULL != pdiViewColumn && NULL != pdiViewColumn->pDispatchTable);
  203. if (NULL != pdiViewColumn->pDispatch)
  204. {
  205. hr = DispatchInvoke(
  206. pdiViewColumn,
  207. VIEWCOL_GETDISPLAYNAME,
  208. 0,
  209. NULL,
  210. VT_BSTR,
  211. pstrOut);
  212. _JumpIfError(hr, error, "Invoke(GetDisplayName)");
  213. }
  214. else
  215. {
  216. hr = ((IEnumCERTVIEWCOLUMN *) pdiViewColumn->pUnknown)->GetDisplayName(pstrOut);
  217. _JumpIfError(hr, error, "GetDisplayName");
  218. }
  219. error:
  220. return(hr);
  221. }
  222. HRESULT
  223. ViewColumn_GetType(
  224. IN DISPATCHINTERFACE *pdiViewColumn,
  225. OUT LONG *pType)
  226. {
  227. HRESULT hr;
  228. CSASSERT(NULL != pdiViewColumn && NULL != pdiViewColumn->pDispatchTable);
  229. if (NULL != pdiViewColumn->pDispatch)
  230. {
  231. hr = DispatchInvoke(
  232. pdiViewColumn,
  233. VIEWCOL_GETTYPE,
  234. 0,
  235. NULL,
  236. VT_I4,
  237. pType);
  238. _JumpIfError(hr, error, "Invoke(GetType)");
  239. }
  240. else
  241. {
  242. hr = ((IEnumCERTVIEWCOLUMN *) pdiViewColumn->pUnknown)->GetType(pType);
  243. _JumpIfError(hr, error, "GetType");
  244. }
  245. error:
  246. return(hr);
  247. }
  248. HRESULT
  249. ViewColumn_IsIndexed(
  250. IN DISPATCHINTERFACE *pdiViewColumn,
  251. OUT LONG *pIndexed)
  252. {
  253. HRESULT hr;
  254. CSASSERT(NULL != pdiViewColumn && NULL != pdiViewColumn->pDispatchTable);
  255. if (NULL != pdiViewColumn->pDispatch)
  256. {
  257. hr = DispatchInvoke(
  258. pdiViewColumn,
  259. VIEWCOL_ISINDEXED,
  260. 0,
  261. NULL,
  262. VT_I4,
  263. pIndexed);
  264. _JumpIfError(hr, error, "Invoke(IsIndexed)");
  265. }
  266. else
  267. {
  268. hr = ((IEnumCERTVIEWCOLUMN *) pdiViewColumn->pUnknown)->IsIndexed(pIndexed);
  269. _JumpIfError(hr, error, "IsIndexed");
  270. }
  271. error:
  272. return(hr);
  273. }
  274. HRESULT
  275. ViewColumn_GetMaxLength(
  276. IN DISPATCHINTERFACE *pdiViewColumn,
  277. OUT LONG *pMaxLength)
  278. {
  279. HRESULT hr;
  280. CSASSERT(NULL != pdiViewColumn && NULL != pdiViewColumn->pDispatchTable);
  281. if (NULL != pdiViewColumn->pDispatch)
  282. {
  283. hr = DispatchInvoke(
  284. pdiViewColumn,
  285. VIEWCOL_GETMAXLENGTH,
  286. 0,
  287. NULL,
  288. VT_I4,
  289. pMaxLength);
  290. _JumpIfError(hr, error, "Invoke(GetMaxLength)");
  291. }
  292. else
  293. {
  294. hr = ((IEnumCERTVIEWCOLUMN *) pdiViewColumn->pUnknown)->GetMaxLength(
  295. pMaxLength);
  296. _JumpIfError(hr, error, "GetMaxLength");
  297. }
  298. error:
  299. return(hr);
  300. }
  301. HRESULT
  302. ViewColumn_GetValue(
  303. IN DISPATCHINTERFACE *pdiViewColumn,
  304. IN LONG Flags,
  305. IN LONG ColumnType,
  306. OUT VOID *pColumnValue)
  307. {
  308. HRESULT hr;
  309. LONG RetType;
  310. VARIANT varResult;
  311. VariantInit(&varResult);
  312. CSASSERT(NULL != pdiViewColumn && NULL != pdiViewColumn->pDispatchTable);
  313. switch (ColumnType)
  314. {
  315. case PROPTYPE_BINARY:
  316. case PROPTYPE_STRING:
  317. RetType = VT_BSTR;
  318. break;
  319. case PROPTYPE_DATE:
  320. RetType = VT_DATE;
  321. break;
  322. case PROPTYPE_LONG:
  323. RetType = VT_I4;
  324. break;
  325. default:
  326. hr = E_INVALIDARG;
  327. _JumpError(hr, error, "PropertyType");
  328. }
  329. if (NULL != pdiViewColumn->pDispatch)
  330. {
  331. VARIANT avar[1];
  332. avar[0].vt = VT_I4;
  333. avar[0].lVal = Flags;
  334. hr = DispatchInvoke(
  335. pdiViewColumn,
  336. VIEWCOL_GETVALUE,
  337. ARRAYSIZE(avar),
  338. avar,
  339. RetType,
  340. pColumnValue);
  341. _JumpIfError2(hr, error, "Invoke(GetValue)", CERTSRV_E_PROPERTY_EMPTY);
  342. }
  343. else
  344. {
  345. hr = ((IEnumCERTVIEWCOLUMN *) pdiViewColumn->pUnknown)->GetValue(
  346. Flags,
  347. &varResult);
  348. _JumpIfError(hr, error, "GetValue");
  349. hr = DispatchGetReturnValue(&varResult, RetType, pColumnValue);
  350. _JumpIfError2(hr, error, "DispatchGetReturnValue", CERTSRV_E_PROPERTY_EMPTY);
  351. }
  352. error:
  353. VariantClear(&varResult);
  354. return(hr);
  355. }
  356. HRESULT
  357. ViewColumn_Skip(
  358. IN DISPATCHINTERFACE *pdiViewColumn,
  359. IN LONG celt)
  360. {
  361. HRESULT hr;
  362. CSASSERT(NULL != pdiViewColumn && NULL != pdiViewColumn->pDispatchTable);
  363. if (NULL != pdiViewColumn->pDispatch)
  364. {
  365. VARIANT avar[1];
  366. avar[0].vt = VT_I4;
  367. avar[0].lVal = celt;
  368. hr = DispatchInvoke(
  369. pdiViewColumn,
  370. VIEWCOL_SKIP,
  371. ARRAYSIZE(avar),
  372. avar,
  373. 0,
  374. NULL);
  375. _JumpIfError(hr, error, "Invoke(Skip)");
  376. }
  377. else
  378. {
  379. hr = ((IEnumCERTVIEWCOLUMN *) pdiViewColumn->pUnknown)->Skip(celt);
  380. _JumpIfError(hr, error, "Skip");
  381. }
  382. error:
  383. return(hr);
  384. }
  385. HRESULT
  386. ViewColumn_Reset(
  387. IN DISPATCHINTERFACE *pdiViewColumn,
  388. IN LONG celt)
  389. {
  390. HRESULT hr;
  391. CSASSERT(NULL != pdiViewColumn && NULL != pdiViewColumn->pDispatchTable);
  392. if (NULL != pdiViewColumn->pDispatch)
  393. {
  394. hr = DispatchInvoke(
  395. pdiViewColumn,
  396. VIEWCOL_RESET,
  397. 0,
  398. NULL,
  399. 0,
  400. NULL);
  401. _JumpIfError(hr, error, "Invoke(Reset)");
  402. }
  403. else
  404. {
  405. hr = ((IEnumCERTVIEWCOLUMN *) pdiViewColumn->pUnknown)->Reset();
  406. _JumpIfError(hr, error, "Reset");
  407. }
  408. error:
  409. return(hr);
  410. }
  411. HRESULT
  412. ViewColumn_Clone(
  413. IN DISPATCHINTERFACE *pdiViewColumn,
  414. OUT DISPATCHINTERFACE *pdiViewColumnClone)
  415. {
  416. HRESULT hr;
  417. IEnumCERTVIEWCOLUMN *pEnumColumn = NULL;
  418. CSASSERT(NULL != pdiViewColumn && NULL != pdiViewColumn->pDispatchTable);
  419. if (NULL != pdiViewColumn->pDispatch)
  420. {
  421. hr = DispatchInvoke(
  422. pdiViewColumn,
  423. VIEWCOL_CLONE,
  424. 0,
  425. NULL,
  426. VT_DISPATCH,
  427. &pEnumColumn);
  428. _JumpIfError(hr, error, "Invoke(Clone)");
  429. }
  430. else
  431. {
  432. hr = ((IEnumCERTVIEWCOLUMN *) pdiViewColumn->pUnknown)->Clone(
  433. &pEnumColumn);
  434. _JumpIfError(hr, error, "Clone");
  435. }
  436. hr = ViewColumn_Init2(
  437. NULL != pdiViewColumn->pDispatch,
  438. pEnumColumn,
  439. pdiViewColumnClone);
  440. _JumpIfError(hr, error, "ViewColumn_Init2");
  441. error:
  442. if (NULL != pEnumColumn)
  443. {
  444. pEnumColumn->Release();
  445. }
  446. return(hr);
  447. }