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.

554 lines
9.0 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Abstract:
  4. Adds properties to ds
  5. Author:
  6. Steve Wilson (NT) December 1996
  7. Revision History:
  8. --*/
  9. #define INC_OLE2
  10. #include "precomp.h"
  11. #pragma hdrstop
  12. #include "varconv.hxx"
  13. #include "property.hxx"
  14. #include "client.h"
  15. #define VALIDATE_PTR(pPtr) \
  16. if (!pPtr) { \
  17. hr = E_ADS_BAD_PARAMETER;\
  18. }\
  19. BAIL_ON_FAILURE(hr);
  20. HRESULT
  21. put_BSTR_Property(
  22. IADs * pADsObject,
  23. BSTR bstrPropertyName,
  24. BSTR pSrcStringProperty
  25. )
  26. {
  27. HRESULT hr;
  28. VARIANT varInputData;
  29. hr = PackString2Variant(
  30. pSrcStringProperty,
  31. &varInputData
  32. );
  33. BAIL_ON_FAILURE(hr);
  34. if (!pSrcStringProperty || !*pSrcStringProperty) {
  35. hr = pADsObject->PutEx(
  36. ADS_PROPERTY_CLEAR,
  37. bstrPropertyName,
  38. varInputData
  39. );
  40. BAIL_ON_FAILURE(hr);
  41. } else {
  42. hr = pADsObject->Put(
  43. bstrPropertyName,
  44. varInputData
  45. );
  46. BAIL_ON_FAILURE(hr);
  47. }
  48. error:
  49. VariantClear(&varInputData);
  50. return hr;
  51. }
  52. HRESULT
  53. put_DWORD_Property(
  54. IADs *pADsObject,
  55. BSTR bstrPropertyName,
  56. DWORD *pdwSrcProperty
  57. )
  58. {
  59. HRESULT hr = S_OK;
  60. VARIANT varInputData;
  61. if (!pdwSrcProperty)
  62. return S_OK;
  63. hr = PackDWORD2Variant(
  64. *pdwSrcProperty,
  65. &varInputData
  66. );
  67. BAIL_ON_FAILURE(hr);
  68. hr = pADsObject->Put(
  69. bstrPropertyName,
  70. varInputData
  71. );
  72. BAIL_ON_FAILURE(hr);
  73. error:
  74. return hr;
  75. }
  76. HRESULT
  77. put_Dispatch_Property(
  78. IADs *pADsObject,
  79. BSTR bstrPropertyName,
  80. IDispatch *pdwSrcProperty
  81. )
  82. {
  83. HRESULT hr = S_OK;
  84. VARIANT varInputData;
  85. if (!pdwSrcProperty)
  86. return S_OK;
  87. hr = PackDispatch2Variant(
  88. pdwSrcProperty,
  89. &varInputData
  90. );
  91. BAIL_ON_FAILURE(hr);
  92. hr = pADsObject->Put(
  93. bstrPropertyName,
  94. varInputData
  95. );
  96. BAIL_ON_FAILURE(hr);
  97. error:
  98. return hr;
  99. }
  100. HRESULT
  101. get_Dispatch_Property(
  102. IADs *pADsObject,
  103. BSTR bstrPropertyName,
  104. IDispatch **ppDispatch
  105. )
  106. {
  107. HRESULT hr = S_OK;
  108. VARIANT varOutputData;
  109. VariantInit( &varOutputData );
  110. hr = pADsObject->Get(
  111. bstrPropertyName,
  112. &varOutputData
  113. );
  114. BAIL_ON_FAILURE(hr);
  115. hr = UnpackDispatchfromVariant(
  116. varOutputData,
  117. ppDispatch
  118. );
  119. BAIL_ON_FAILURE(hr);
  120. error:
  121. return hr;
  122. }
  123. HRESULT
  124. put_MULTISZ_Property(
  125. IADs *pADsObject,
  126. BSTR bstrPropertyName,
  127. BSTR pSrcStringProperty
  128. )
  129. {
  130. HRESULT hr = S_OK;
  131. VARIANT var;
  132. VARIANT varInputData;
  133. BSTR pStr;
  134. BSTR *pStrArray;
  135. DWORD i;
  136. BSTR pMultiString;
  137. if (!pSrcStringProperty || !*pSrcStringProperty)
  138. pMultiString = L"";
  139. else
  140. pMultiString = pSrcStringProperty;
  141. VariantInit(&var);
  142. // Convert MULTI_SZ to string array (last element of array must be NULL)
  143. for (i = 0, pStr = pMultiString ; *pStr ; ++i, pStr += wcslen(pStr) + 1)
  144. ;
  145. if (!(pStrArray = (BSTR *) AllocSplMem((i + 1)*sizeof(BSTR)))) {
  146. hr = MAKE_HRESULT( SEVERITY_ERROR, FACILITY_WIN32, GetLastError());
  147. BAIL_ON_FAILURE(hr);
  148. }
  149. for (i = 0, pStr = pMultiString ; *pStr ; ++i, pStr += wcslen(pStr) + 1)
  150. pStrArray[i] = pStr;
  151. pStrArray[i] = NULL;
  152. MakeVariantFromStringArray(pStrArray, &var);
  153. FreeSplMem(pStrArray);
  154. hr = PackVARIANTinVariant(
  155. var,
  156. &varInputData
  157. );
  158. BAIL_ON_FAILURE(hr);
  159. if (!pSrcStringProperty || !*pSrcStringProperty) {
  160. hr = pADsObject->PutEx(
  161. ADS_PROPERTY_CLEAR,
  162. bstrPropertyName,
  163. varInputData
  164. );
  165. BAIL_ON_FAILURE(hr);
  166. } else {
  167. hr = pADsObject->Put(
  168. bstrPropertyName,
  169. varInputData
  170. );
  171. BAIL_ON_FAILURE(hr);
  172. }
  173. error:
  174. VariantClear(&var);
  175. VariantClear(&varInputData);
  176. return hr;
  177. }
  178. HRESULT
  179. put_BOOL_Property(
  180. IADs *pADsObject,
  181. BSTR bstrPropertyName,
  182. BOOL *bSrcProperty
  183. )
  184. {
  185. HRESULT hr = S_OK;
  186. VARIANT varInputData;
  187. BOOL bVal;
  188. bVal = bSrcProperty ? *bSrcProperty : 0;
  189. hr = PackBOOL2Variant(
  190. bVal,
  191. &varInputData
  192. );
  193. BAIL_ON_FAILURE(hr);
  194. if (!bSrcProperty) {
  195. hr = pADsObject->PutEx(
  196. ADS_PROPERTY_CLEAR,
  197. bstrPropertyName,
  198. varInputData
  199. );
  200. BAIL_ON_FAILURE(hr);
  201. } else {
  202. hr = pADsObject->Put(
  203. bstrPropertyName,
  204. varInputData
  205. );
  206. BAIL_ON_FAILURE(hr);
  207. }
  208. error:
  209. return hr;
  210. }
  211. HRESULT
  212. get_UI1Array_Property(
  213. IADs *pADsObject,
  214. BSTR bstrPropertyName,
  215. IID *pIID
  216. )
  217. {
  218. HRESULT hr = S_OK;
  219. VARIANT varOutputData;
  220. VariantInit( &varOutputData );
  221. hr = pADsObject->Get(
  222. bstrPropertyName,
  223. &varOutputData
  224. );
  225. BAIL_ON_FAILURE(hr);
  226. hr = UI1Array2IID(
  227. varOutputData,
  228. pIID
  229. );
  230. BAIL_ON_FAILURE(hr);
  231. error:
  232. return hr;
  233. }
  234. HRESULT
  235. get_BSTR_Property(
  236. IADs *pADsObject,
  237. BSTR bstrPropertyName,
  238. BSTR *ppDestStringProperty
  239. )
  240. {
  241. HRESULT hr = S_OK;
  242. VARIANT varOutputData;
  243. VariantInit( &varOutputData );
  244. hr = pADsObject->Get(
  245. bstrPropertyName,
  246. &varOutputData
  247. );
  248. BAIL_ON_FAILURE(hr);
  249. hr = UnpackStringfromVariant(
  250. varOutputData,
  251. ppDestStringProperty
  252. );
  253. BAIL_ON_FAILURE(hr);
  254. error:
  255. return hr;
  256. }
  257. /*
  258. HRESULT
  259. put_LONG_Property(
  260. IADs * pADsObject,
  261. BSTR bstrPropertyName,
  262. LONG lSrcProperty
  263. )
  264. {
  265. HRESULT hr = S_OK;
  266. VARIANT varInputData;
  267. hr = PackLONGinVariant(
  268. lSrcProperty,
  269. &varInputData
  270. );
  271. BAIL_ON_FAILURE(hr);
  272. hr = pADsObject->Put(
  273. bstrPropertyName,
  274. varInputData
  275. );
  276. BAIL_ON_FAILURE(hr);
  277. error:
  278. return hr;
  279. }
  280. HRESULT
  281. get_LONG_Property(
  282. IADs * pADsObject,
  283. BSTR bstrPropertyName,
  284. PLONG plDestProperty
  285. )
  286. {
  287. HRESULT hr = S_OK;
  288. VARIANT varOutputData;
  289. VALIDATE_PTR( plDestProperty );
  290. VariantInit( &varOutputData );
  291. hr = pADsObject->Get(
  292. bstrPropertyName,
  293. &varOutputData
  294. );
  295. BAIL_ON_FAILURE(hr);
  296. hr = UnpackLONGfromVariant(
  297. varOutputData,
  298. plDestProperty
  299. );
  300. BAIL_ON_FAILURE(hr);
  301. error:
  302. return hr;
  303. }
  304. HRESULT
  305. put_DATE_Property(
  306. IADs * pADsObject,
  307. BSTR bstrPropertyName,
  308. DATE daSrcProperty
  309. )
  310. {
  311. HRESULT hr = S_OK;
  312. VARIANT varInputData;
  313. hr = PackDATEinVariant(
  314. daSrcProperty,
  315. &varInputData
  316. );
  317. BAIL_ON_FAILURE(hr);
  318. hr = pADsObject->Put(
  319. bstrPropertyName,
  320. varInputData
  321. );
  322. BAIL_ON_FAILURE(hr);
  323. error:
  324. return hr;
  325. }
  326. HRESULT
  327. get_DATE_Property(
  328. IADs * pADsObject,
  329. BSTR bstrPropertyName,
  330. DATE *pdaDestProperty
  331. )
  332. {
  333. HRESULT hr = S_OK;
  334. VARIANT varOutputData;
  335. VALIDATE_PTR( pdaDestProperty );
  336. VariantInit( &varOutputData );
  337. hr = pADsObject->Get(
  338. bstrPropertyName,
  339. &varOutputData
  340. );
  341. BAIL_ON_FAILURE(hr);
  342. hr = UnpackDATEfromVariant(
  343. varOutputData,
  344. pdaDestProperty
  345. );
  346. BAIL_ON_FAILURE(hr);
  347. error:
  348. return hr;
  349. }
  350. HRESULT
  351. put_VARIANT_BOOL_Property(
  352. IADs * pADsObject,
  353. BSTR bstrPropertyName,
  354. VARIANT_BOOL fSrcProperty
  355. )
  356. {
  357. HRESULT hr = S_OK;
  358. VARIANT varInputData;
  359. hr = PackVARIANT_BOOLinVariant(
  360. fSrcProperty,
  361. &varInputData
  362. );
  363. BAIL_ON_FAILURE(hr);
  364. hr = pADsObject->Put(
  365. bstrPropertyName,
  366. varInputData
  367. );
  368. BAIL_ON_FAILURE(hr);
  369. error:
  370. return hr;
  371. }
  372. HRESULT
  373. get_VARIANT_BOOL_Property(
  374. IADs * pADsObject,
  375. BSTR bstrPropertyName,
  376. VARIANT_BOOL *pfDestProperty
  377. )
  378. {
  379. HRESULT hr = S_OK;
  380. VARIANT varOutputData;
  381. VALIDATE_PTR( pfDestProperty );
  382. VariantInit( &varOutputData );
  383. hr = pADsObject->Get(
  384. bstrPropertyName,
  385. &varOutputData
  386. );
  387. BAIL_ON_FAILURE(hr);
  388. hr = UnpackVARIANT_BOOLfromVariant(
  389. varOutputData,
  390. pfDestProperty
  391. );
  392. BAIL_ON_FAILURE(hr);
  393. error:
  394. return hr;
  395. }
  396. HRESULT
  397. get_VARIANT_Property(
  398. IADs * pADsObject,
  399. BSTR bstrPropertyName,
  400. VARIANT *pvDestProperty
  401. )
  402. {
  403. HRESULT hr = S_OK;
  404. VARIANT varOutputData;
  405. VALIDATE_PTR( pvDestProperty );
  406. VariantInit( &varOutputData );
  407. hr = pADsObject->Get(
  408. bstrPropertyName,
  409. &varOutputData
  410. );
  411. BAIL_ON_FAILURE(hr);
  412. hr = UnpackVARIANTfromVariant(
  413. varOutputData,
  414. pvDestProperty
  415. );
  416. BAIL_ON_FAILURE(hr);
  417. error:
  418. return hr;
  419. }
  420. */