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.

606 lines
11 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1995 - 1999
  6. //
  7. // File: view.cpp
  8. //
  9. // Contents: ICertView 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. // ICertView dispatch support
  19. //WCHAR wszRegKeyViewClsid[] = wszCLASS_CERTVIEW TEXT("\\Clsid");
  20. //+------------------------------------
  21. // OpenConnection method:
  22. static OLECHAR *_apszOpenConnection[] = {
  23. TEXT("OpenConnection"),
  24. TEXT("strConfig"),
  25. };
  26. //+------------------------------------
  27. // EnumCertViewColumn method:
  28. static OLECHAR *_apszEnumCertViewColumn[] = {
  29. TEXT("EnumCertViewColumn"),
  30. TEXT("fResultColumn"),
  31. };
  32. //+------------------------------------
  33. // GetColumnCount method:
  34. static OLECHAR *_apszGetColumnCount[] = {
  35. TEXT("GetColumnCount"),
  36. TEXT("fResultColumn"),
  37. };
  38. //+------------------------------------
  39. // GetColumnIndex method:
  40. static OLECHAR *_apszGetColumnIndex[] = {
  41. TEXT("GetColumnIndex"),
  42. TEXT("fResultColumn"),
  43. TEXT("strColumnName"),
  44. };
  45. //+------------------------------------
  46. // SetResultColumnCount method:
  47. static OLECHAR *_apszSetResultColumnCount[] = {
  48. TEXT("SetResultColumnCount"),
  49. TEXT("cResultColumn"),
  50. };
  51. //+------------------------------------
  52. // SetResultColumn method:
  53. static OLECHAR *_apszSetResultColumn[] = {
  54. TEXT("SetResultColumn"),
  55. TEXT("ColumnIndex"),
  56. };
  57. //+------------------------------------
  58. // SetRestriction method:
  59. static OLECHAR *_apszSetRestriction[] = {
  60. TEXT("SetRestriction"),
  61. TEXT("ColumnIndex"),
  62. TEXT("SeekOperator"),
  63. TEXT("SortOrder"),
  64. TEXT("pvarValue"),
  65. };
  66. //+------------------------------------
  67. // OpenView method:
  68. static OLECHAR *_apszOpenView[] = {
  69. TEXT("OpenView"),
  70. };
  71. //+------------------------------------
  72. // SetTable method:
  73. static OLECHAR *_apszSetTable[] = {
  74. TEXT("SetTable"),
  75. TEXT("Table"),
  76. };
  77. //+------------------------------------
  78. // Dispatch Table:
  79. DISPATCHTABLE s_adtView[] =
  80. {
  81. #define VIEW_OPENCONNECTION 0
  82. DECLARE_DISPATCH_ENTRY(_apszOpenConnection)
  83. #define VIEW_ENUMCERTVIEWCOLUMN 1
  84. DECLARE_DISPATCH_ENTRY(_apszEnumCertViewColumn)
  85. #define VIEW_GETCOLUMNCOUNT 2
  86. DECLARE_DISPATCH_ENTRY(_apszGetColumnCount)
  87. #define VIEW_GETCOLUMNINDEX 3
  88. DECLARE_DISPATCH_ENTRY(_apszGetColumnIndex)
  89. #define VIEW_SETRESULTCOLUMNCOUNT 4
  90. DECLARE_DISPATCH_ENTRY(_apszSetResultColumnCount)
  91. #define VIEW_SETRESULTCOLUMN 5
  92. DECLARE_DISPATCH_ENTRY(_apszSetResultColumn)
  93. #define VIEW_SETRESTRICTION 6
  94. DECLARE_DISPATCH_ENTRY(_apszSetRestriction)
  95. #define VIEW_OPENVIEW 7
  96. DECLARE_DISPATCH_ENTRY(_apszOpenView)
  97. #define VIEW2_SETTABLE 8
  98. DECLARE_DISPATCH_ENTRY(_apszSetTable)
  99. };
  100. #define CVIEWDISPATCH (ARRAYSIZE(s_adtView))
  101. #define CVIEWDISPATCH_V1 VIEW2_SETTABLE
  102. #define CVIEWDISPATCH_V2 CVIEWDISPATCH
  103. DWORD s_acViewDispatch[] = {
  104. CVIEWDISPATCH_V2,
  105. CVIEWDISPATCH_V1,
  106. };
  107. IID const *s_apViewiid[] = {
  108. &IID_ICertView2,
  109. &IID_ICertView,
  110. };
  111. HRESULT
  112. View_Init(
  113. IN DWORD Flags,
  114. OUT DISPATCHINTERFACE *pdiView)
  115. {
  116. HRESULT hr;
  117. hr = DispatchSetup2(
  118. Flags,
  119. CLSCTX_INPROC_SERVER,
  120. wszCLASS_CERTVIEW,
  121. &CLSID_CCertView,
  122. ARRAYSIZE(s_acViewDispatch), // cver
  123. s_apViewiid,
  124. s_acViewDispatch,
  125. s_adtView,
  126. pdiView);
  127. _JumpIfError(hr, error, "DispatchSetup2(ICertView)");
  128. error:
  129. return(hr);
  130. }
  131. VOID
  132. View_Release(
  133. IN OUT DISPATCHINTERFACE *pdiView)
  134. {
  135. DispatchRelease(pdiView);
  136. }
  137. HRESULT
  138. ViewVerifyVersion(
  139. IN DISPATCHINTERFACE *pdiView,
  140. IN DWORD RequiredVersion)
  141. {
  142. HRESULT hr;
  143. CSASSERT(NULL != pdiView && NULL != pdiView->pDispatchTable);
  144. switch (pdiView->m_dwVersion)
  145. {
  146. case 1:
  147. CSASSERT(
  148. NULL == pdiView->pDispatch ||
  149. CVIEWDISPATCH_V1 == pdiView->m_cDispatchTable);
  150. break;
  151. case 2:
  152. CSASSERT(
  153. NULL == pdiView->pDispatch ||
  154. CVIEWDISPATCH_V2 == pdiView->m_cDispatchTable);
  155. break;
  156. default:
  157. hr = HRESULT_FROM_WIN32(ERROR_INTERNAL_ERROR);
  158. _JumpError(hr, error, "m_dwVersion");
  159. }
  160. if (pdiView->m_dwVersion < RequiredVersion)
  161. {
  162. hr = E_NOTIMPL;
  163. _JumpError(hr, error, "old interface");
  164. }
  165. hr = S_OK;
  166. error:
  167. return(hr);
  168. }
  169. HRESULT
  170. View_OpenConnection(
  171. IN DISPATCHINTERFACE *pdiView,
  172. IN WCHAR const *pwszConfig)
  173. {
  174. HRESULT hr;
  175. BSTR strConfig = NULL;
  176. CSASSERT(NULL != pdiView && NULL != pdiView->pDispatchTable);
  177. if (!ConvertWszToBstr(&strConfig, pwszConfig, -1))
  178. {
  179. hr = E_OUTOFMEMORY;
  180. _JumpError(hr, error, "ConvertWszToBstr");
  181. }
  182. if (NULL != pdiView->pDispatch)
  183. {
  184. VARIANT avar[1];
  185. avar[0].vt = VT_BSTR;
  186. avar[0].bstrVal = strConfig;
  187. hr = DispatchInvoke(
  188. pdiView,
  189. VIEW_OPENCONNECTION,
  190. ARRAYSIZE(avar),
  191. avar,
  192. 0,
  193. NULL);
  194. _JumpIfError(hr, error, "Invoke(OpenConnection)");
  195. }
  196. else
  197. {
  198. hr = ((ICertView *) pdiView->pUnknown)->OpenConnection(strConfig);
  199. _JumpIfError(hr, error, "OpenConnection");
  200. }
  201. error:
  202. if (NULL != strConfig)
  203. {
  204. SysFreeString(strConfig);
  205. }
  206. return(hr);
  207. }
  208. HRESULT
  209. View_GetColumnCount(
  210. IN DISPATCHINTERFACE *pdiView,
  211. IN LONG fResultColumn,
  212. OUT LONG *pcColumn)
  213. {
  214. HRESULT hr;
  215. CSASSERT(NULL != pdiView && NULL != pdiView->pDispatchTable);
  216. if (NULL != pdiView->pDispatch)
  217. {
  218. VARIANT avar[1];
  219. avar[0].vt = VT_I4;
  220. avar[0].lVal = fResultColumn;
  221. hr = DispatchInvoke(
  222. pdiView,
  223. VIEW_GETCOLUMNCOUNT,
  224. ARRAYSIZE(avar),
  225. avar,
  226. VT_I4,
  227. pcColumn);
  228. _JumpIfError(hr, error, "Invoke(GetColumnCount)");
  229. }
  230. else
  231. {
  232. hr = ((ICertView *) pdiView->pUnknown)->GetColumnCount(
  233. fResultColumn,
  234. pcColumn);
  235. _JumpIfError(hr, error, "GetColumnCount");
  236. }
  237. error:
  238. return(hr);
  239. }
  240. HRESULT
  241. View_GetColumnIndex(
  242. IN DISPATCHINTERFACE *pdiView,
  243. IN LONG fResultColumn,
  244. IN WCHAR const *pwszColumnName,
  245. OUT LONG *pColumnIndex)
  246. {
  247. HRESULT hr;
  248. BSTR strColumnName = NULL;
  249. CSASSERT(NULL != pdiView && NULL != pdiView->pDispatchTable);
  250. if (!ConvertWszToBstr(&strColumnName, pwszColumnName, -1))
  251. {
  252. hr = E_OUTOFMEMORY;
  253. _JumpError(hr, error, "ConvertWszToBstr");
  254. }
  255. if (NULL != pdiView->pDispatch)
  256. {
  257. VARIANT avar[2];
  258. avar[0].vt = VT_I4;
  259. avar[0].lVal = fResultColumn;
  260. avar[1].vt = VT_BSTR;
  261. avar[1].bstrVal = strColumnName;
  262. hr = DispatchInvoke(
  263. pdiView,
  264. VIEW_GETCOLUMNINDEX,
  265. ARRAYSIZE(avar),
  266. avar,
  267. VT_I4,
  268. pColumnIndex);
  269. _JumpIfError(hr, error, "Invoke(GetColumnIndex)");
  270. }
  271. else
  272. {
  273. hr = ((ICertView *) pdiView->pUnknown)->GetColumnIndex(
  274. fResultColumn,
  275. strColumnName,
  276. pColumnIndex);
  277. _JumpIfError(hr, error, "GetColumnIndex");
  278. }
  279. error:
  280. if (NULL != strColumnName)
  281. {
  282. SysFreeString(strColumnName);
  283. }
  284. return(hr);
  285. }
  286. HRESULT
  287. View_SetResultColumnCount(
  288. IN DISPATCHINTERFACE *pdiView,
  289. IN LONG cResultColumn)
  290. {
  291. HRESULT hr;
  292. CSASSERT(NULL != pdiView && NULL != pdiView->pDispatchTable);
  293. if (NULL != pdiView->pDispatch)
  294. {
  295. VARIANT avar[1];
  296. avar[0].vt = VT_I4;
  297. avar[0].lVal = cResultColumn;
  298. hr = DispatchInvoke(
  299. pdiView,
  300. VIEW_SETRESULTCOLUMNCOUNT,
  301. ARRAYSIZE(avar),
  302. avar,
  303. 0,
  304. NULL);
  305. _JumpIfError(hr, error, "Invoke(SetResultColumnCount)");
  306. }
  307. else
  308. {
  309. hr = ((ICertView *) pdiView->pUnknown)->SetResultColumnCount(cResultColumn);
  310. _JumpIfError(hr, error, "SetResultColumnCount");
  311. }
  312. error:
  313. return(hr);
  314. }
  315. HRESULT
  316. View_SetResultColumn(
  317. IN DISPATCHINTERFACE *pdiView,
  318. IN LONG ColumnIndex)
  319. {
  320. HRESULT hr;
  321. CSASSERT(NULL != pdiView && NULL != pdiView->pDispatchTable);
  322. if (NULL != pdiView->pDispatch)
  323. {
  324. VARIANT avar[1];
  325. avar[0].vt = VT_I4;
  326. avar[0].lVal = ColumnIndex;
  327. hr = DispatchInvoke(
  328. pdiView,
  329. VIEW_SETRESULTCOLUMN,
  330. ARRAYSIZE(avar),
  331. avar,
  332. 0,
  333. NULL);
  334. _JumpIfError(hr, error, "Invoke(SetResultColumn)");
  335. }
  336. else
  337. {
  338. hr = ((ICertView *) pdiView->pUnknown)->SetResultColumn(ColumnIndex);
  339. _JumpIfError(hr, error, "SetResultColumn");
  340. }
  341. error:
  342. return(hr);
  343. }
  344. HRESULT
  345. View_SetRestriction(
  346. IN DISPATCHINTERFACE *pdiView,
  347. IN LONG ColumnIndex,
  348. IN LONG SeekOperator,
  349. IN LONG SortOrder,
  350. IN VARIANT const *pvarValue)
  351. {
  352. HRESULT hr;
  353. CSASSERT(NULL != pdiView && NULL != pdiView->pDispatchTable);
  354. if (NULL != pdiView->pDispatch)
  355. {
  356. VARIANT avar[4];
  357. avar[0].vt = VT_I4;
  358. avar[0].lVal = ColumnIndex;
  359. avar[1].vt = VT_I4;
  360. avar[1].lVal = SeekOperator;
  361. avar[2].vt = VT_I4;
  362. avar[2].lVal = SortOrder;
  363. avar[3] = *pvarValue;
  364. hr = DispatchInvoke(
  365. pdiView,
  366. VIEW_SETRESTRICTION,
  367. ARRAYSIZE(avar),
  368. avar,
  369. 0,
  370. NULL);
  371. _JumpIfError(hr, error, "Invoke(SetRestriction)");
  372. }
  373. else
  374. {
  375. hr = ((ICertView *) pdiView->pUnknown)->SetRestriction(
  376. ColumnIndex,
  377. SeekOperator,
  378. SortOrder,
  379. pvarValue);
  380. _JumpIfError(hr, error, "SetRestriction");
  381. }
  382. error:
  383. return(hr);
  384. }
  385. HRESULT
  386. View_OpenView(
  387. IN DISPATCHINTERFACE *pdiView,
  388. OUT DISPATCHINTERFACE *pdiViewRow)
  389. {
  390. HRESULT hr;
  391. IEnumCERTVIEWROW *pEnumRow = NULL;
  392. CSASSERT(NULL != pdiView && NULL != pdiView->pDispatchTable);
  393. if (NULL != pdiView->pDispatch)
  394. {
  395. hr = DispatchInvoke(
  396. pdiView,
  397. VIEW_OPENVIEW,
  398. 0,
  399. NULL,
  400. VT_DISPATCH,
  401. &pEnumRow);
  402. _JumpIfError(hr, error, "Invoke(OpenView)");
  403. }
  404. else
  405. {
  406. hr = ((ICertView *) pdiView->pUnknown)->OpenView(&pEnumRow);
  407. _JumpIfError(hr, error, "OpenView");
  408. }
  409. hr = ViewRow_Init2(NULL != pdiView->pDispatch, pEnumRow, pdiViewRow);
  410. _JumpIfError(hr, error, "ViewRow_Init2");
  411. error:
  412. if (NULL != pEnumRow)
  413. {
  414. pEnumRow->Release();
  415. }
  416. return(hr);
  417. }
  418. HRESULT
  419. View2_SetTable(
  420. IN DISPATCHINTERFACE *pdiView,
  421. IN LONG Table)
  422. {
  423. HRESULT hr;
  424. CSASSERT(NULL != pdiView && NULL != pdiView->pDispatchTable);
  425. hr = ViewVerifyVersion(pdiView, 2);
  426. _JumpIfError(hr, error, "ViewVerifyVersion");
  427. if (NULL != pdiView->pDispatch)
  428. {
  429. VARIANT avar[1];
  430. avar[0].vt = VT_I4;
  431. avar[0].lVal = Table;
  432. hr = DispatchInvoke(
  433. pdiView,
  434. VIEW2_SETTABLE,
  435. ARRAYSIZE(avar),
  436. avar,
  437. 0,
  438. NULL);
  439. _JumpIfError(hr, error, "Invoke(SetTable)");
  440. }
  441. else
  442. {
  443. hr = ((ICertView2 *) pdiView->pUnknown)->SetTable(Table);
  444. _JumpIfError(hr, error, "SetTable");
  445. }
  446. error:
  447. return(hr);
  448. }
  449. HRESULT
  450. View_EnumCertViewColumn(
  451. IN DISPATCHINTERFACE *pdiView,
  452. IN LONG fResultColumn,
  453. OUT DISPATCHINTERFACE *pdiViewColumn)
  454. {
  455. HRESULT hr;
  456. IEnumCERTVIEWCOLUMN *pEnumColumn = NULL;
  457. CSASSERT(NULL != pdiView && NULL != pdiView->pDispatchTable);
  458. if (NULL != pdiView->pDispatch)
  459. {
  460. VARIANT avar[1];
  461. avar[0].vt = VT_I4;
  462. avar[0].lVal = fResultColumn;
  463. hr = DispatchInvoke(
  464. pdiView,
  465. VIEW_ENUMCERTVIEWCOLUMN,
  466. ARRAYSIZE(avar),
  467. avar,
  468. VT_DISPATCH,
  469. &pEnumColumn);
  470. _JumpIfError(hr, error, "Invoke(EnumCertViewColumn)");
  471. }
  472. else
  473. {
  474. hr = ((ICertView *) pdiView->pUnknown)->EnumCertViewColumn(
  475. fResultColumn,
  476. &pEnumColumn);
  477. _JumpIfError(hr, error, "EnumCertViewColumn");
  478. }
  479. hr = ViewColumn_Init2(
  480. NULL != pdiView->pDispatch,
  481. pEnumColumn,
  482. pdiViewColumn);
  483. _JumpIfError(hr, error, "ViewColumn_Init2");
  484. error:
  485. if (NULL != pEnumColumn)
  486. {
  487. pEnumColumn->Release();
  488. }
  489. return(hr);
  490. }