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.

1337 lines
29 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. // File: ndscopy.cxx
  7. //
  8. // Contents: NDS Object to Variant Copy Routines
  9. //
  10. // Functions:
  11. //
  12. // History: 25-Apr-96 KrishnaG Created.
  13. //
  14. //
  15. // Issues: Check null ptrs for AllocADsMem and AllocADsStr
  16. //
  17. //
  18. // The following conversions are not supported
  19. //
  20. // NDS_ASN1_TYPE_1
  21. //
  22. // NDS_ASN1_TYPE_2
  23. //
  24. // NDS_ASN1_TYPE_3
  25. //
  26. // NDS_ASN1_TYPE_4
  27. //
  28. // NDS_ASN1_TYPE_5
  29. //
  30. // NDS_ASN1_TYPE_6
  31. //
  32. // NDS_ASN1_TYPE_7
  33. //
  34. // NDS_ASN1_TYPE_8
  35. //
  36. // NDS_ASN1_TYPE_9
  37. //
  38. // NDS_ASN1_TYPE_10
  39. //
  40. // NDS_ASN1_TYPE_11
  41. //
  42. // NDS_ASN1_TYPE_12
  43. //
  44. // NDS_ASN1_TYPE_13
  45. //
  46. // NDS_ASN1_TYPE_14
  47. //
  48. // NDS_ASN1_TYPE_15
  49. //
  50. // NDS_ASN1_TYPE_16
  51. //
  52. // NDS_ASN1_TYPE_17
  53. //
  54. // NDS_ASN1_TYPE_18
  55. //
  56. // NDS_ASN1_TYPE_19
  57. //
  58. // NDS_ASN1_TYPE_20
  59. //
  60. // NDS_ASN1_TYPE_21
  61. //
  62. // NDS_ASN1_TYPE_22
  63. //
  64. // NDS_ASN1_TYPE_23
  65. //
  66. // NDS_ASN1_TYPE_24
  67. //
  68. // NDS_ASN1_TYPE_25
  69. //
  70. // NDS_ASN1_TYPE_26
  71. //
  72. // NDS_ASN1_TYPE_27
  73. //
  74. //
  75. //----------------------------------------------------------------------------
  76. #include "nds.hxx"
  77. //
  78. // NdsType objects copy code
  79. //
  80. void
  81. VarTypeFreeVarObjects(
  82. PVARIANT pVarObject,
  83. DWORD dwNumValues
  84. )
  85. {
  86. DWORD i = 0;
  87. for (i = 0; i < dwNumValues; i++ ) {
  88. VariantClear(pVarObject + i);
  89. }
  90. FreeADsMem(pVarObject);
  91. return;
  92. }
  93. HRESULT
  94. NdsTypeToVarTypeCopyNDSSynId1(
  95. PNDSOBJECT lpNdsSrcObject,
  96. PVARIANT lpVarDestObject
  97. )
  98. {
  99. HRESULT hr = S_OK;
  100. lpVarDestObject->vt = VT_BSTR;
  101. hr = ADsAllocString(
  102. lpNdsSrcObject->NdsValue.value_1.DNString,
  103. &(lpVarDestObject->bstrVal)
  104. );
  105. RRETURN(hr);
  106. }
  107. HRESULT
  108. NdsTypeToVarTypeCopyNDSSynId2(
  109. PNDSOBJECT lpNdsSrcObject,
  110. PVARIANT lpVarDestObject
  111. )
  112. {
  113. HRESULT hr = S_OK;
  114. lpVarDestObject->vt = VT_BSTR;
  115. hr = ADsAllocString(
  116. lpNdsSrcObject->NdsValue.value_1.DNString,
  117. &(lpVarDestObject->bstrVal)
  118. );
  119. RRETURN(hr);
  120. }
  121. HRESULT
  122. NdsTypeToVarTypeCopyNDSSynId3(
  123. PNDSOBJECT lpNdsSrcObject,
  124. PVARIANT lpVarDestObject
  125. )
  126. {
  127. HRESULT hr = S_OK;
  128. VariantInit(lpVarDestObject);
  129. lpVarDestObject->vt = VT_BSTR;
  130. hr = ADsAllocString(
  131. lpNdsSrcObject->NdsValue.value_1.DNString,
  132. &(lpVarDestObject->bstrVal)
  133. );
  134. RRETURN(hr);
  135. }
  136. HRESULT
  137. NdsTypeToVarTypeCopyNDSSynId4(
  138. PNDSOBJECT lpNdsSrcObject,
  139. PVARIANT lpVarDestObject
  140. )
  141. {
  142. HRESULT hr = S_OK;
  143. lpVarDestObject->vt = VT_BSTR;
  144. hr = ADsAllocString(
  145. lpNdsSrcObject->NdsValue.value_1.DNString,
  146. &(lpVarDestObject->bstrVal)
  147. );
  148. RRETURN(hr);
  149. }
  150. HRESULT
  151. NdsTypeToVarTypeCopyNDSSynId5(
  152. PNDSOBJECT lpNdsSrcObject,
  153. PVARIANT lpVarDestObject
  154. )
  155. {
  156. HRESULT hr = S_OK;
  157. lpVarDestObject->vt = VT_BSTR;
  158. hr = ADsAllocString(
  159. lpNdsSrcObject->NdsValue.value_1.DNString,
  160. &(lpVarDestObject->bstrVal)
  161. );
  162. RRETURN(hr);
  163. }
  164. HRESULT
  165. NdsTypeToVarTypeCopyNDSSynId6(
  166. PNDSOBJECT lpNdsSrcObject,
  167. PVARIANT lpVarDestObject
  168. )
  169. {
  170. HRESULT hr = S_OK;
  171. SAFEARRAY *aList = NULL;
  172. SAFEARRAYBOUND aBound;
  173. long i;
  174. BSTR bstrAddress;
  175. DWORD cElements = 0;
  176. IADsCaseIgnoreList* pCaseIgnoreList = NULL;
  177. IDispatch * pDispatch = NULL;
  178. VARIANT VarDestObject;
  179. struct _NDS_CI_LIST *pCurrent = NULL;
  180. VARIANT varElement;
  181. hr = CCaseIgnoreList::CreateCaseIgnoreList(
  182. IID_IADsCaseIgnoreList,
  183. (void **)&pCaseIgnoreList
  184. );
  185. BAIL_ON_FAILURE(hr);
  186. pCurrent = &(lpNdsSrcObject->NdsValue.value_6);
  187. while (pCurrent) {
  188. cElements++;
  189. pCurrent = pCurrent->Next;
  190. }
  191. aBound.lLbound = 0;
  192. aBound.cElements = cElements;
  193. aList = SafeArrayCreate( VT_VARIANT, 1, &aBound );
  194. if ( aList == NULL ) {
  195. hr = E_OUTOFMEMORY;
  196. BAIL_ON_FAILURE(hr);
  197. }
  198. pCurrent = &(lpNdsSrcObject->NdsValue.value_6);
  199. for ( i = 0; i < (long)cElements; i++ ) {
  200. VariantInit(&varElement);
  201. varElement.vt = VT_BSTR;
  202. hr = ADsAllocString(
  203. pCurrent->String,
  204. &varElement.bstrVal
  205. );
  206. BAIL_ON_FAILURE(hr);
  207. hr = SafeArrayPutElement( aList, &i, &varElement);
  208. BAIL_ON_FAILURE(hr);
  209. pCurrent = pCurrent->Next;
  210. VariantClear(&varElement);
  211. }
  212. VariantInit(&VarDestObject);
  213. V_VT(&VarDestObject) = VT_ARRAY | VT_VARIANT;
  214. V_ARRAY(&VarDestObject) = aList;
  215. hr = pCaseIgnoreList->put_CaseIgnoreList(VarDestObject);
  216. BAIL_ON_FAILURE(hr);
  217. VariantClear(&VarDestObject);
  218. aList = NULL;
  219. hr = pCaseIgnoreList->QueryInterface(IID_IDispatch, (void**)&pDispatch);
  220. BAIL_ON_FAILURE(hr);
  221. VariantInit(lpVarDestObject);
  222. V_VT(lpVarDestObject) = VT_DISPATCH;
  223. V_DISPATCH(lpVarDestObject) = pDispatch;
  224. error:
  225. if ( aList ) {
  226. SafeArrayDestroy( aList );
  227. }
  228. if (pCaseIgnoreList) {
  229. pCaseIgnoreList->Release();
  230. }
  231. RRETURN(hr);
  232. }
  233. HRESULT
  234. NdsTypeToVarTypeCopyNDSSynId7(
  235. PNDSOBJECT lpNdsSrcObject,
  236. PVARIANT lpVarDestObject
  237. )
  238. {
  239. HRESULT hr = S_OK;
  240. lpVarDestObject->vt = VT_BOOL;
  241. lpVarDestObject->boolVal =
  242. (lpNdsSrcObject->NdsValue.value_7.Boolean)?
  243. VARIANT_TRUE: VARIANT_FALSE;
  244. RRETURN(hr);
  245. }
  246. HRESULT
  247. NdsTypeToVarTypeCopyNDSSynId8(
  248. PNDSOBJECT lpNdsSrcObject,
  249. PVARIANT lpVarDestObject
  250. )
  251. {
  252. HRESULT hr = S_OK;
  253. lpVarDestObject->vt = VT_I4;
  254. lpVarDestObject->lVal =
  255. lpNdsSrcObject->NdsValue.value_8.Integer;
  256. RRETURN(hr);
  257. }
  258. HRESULT
  259. NdsTypeToVarTypeCopyNDSSynId9(
  260. PNDSOBJECT lpNdsSrcObject,
  261. PVARIANT lpVarDestObject
  262. )
  263. {
  264. HRESULT hr = S_OK;
  265. VariantInit(lpVarDestObject);
  266. hr = BinaryToVariant(
  267. lpNdsSrcObject->NdsValue.value_9.Length,
  268. lpNdsSrcObject->NdsValue.value_9.OctetString,
  269. lpVarDestObject);
  270. RRETURN(hr);
  271. }
  272. HRESULT
  273. NdsTypeToVarTypeCopyNDSSynId10(
  274. PNDSOBJECT lpNdsSrcObject,
  275. PVARIANT lpVarDestObject
  276. )
  277. {
  278. HRESULT hr = S_OK;
  279. lpVarDestObject->vt = VT_BSTR;
  280. hr = ADsAllocString(
  281. lpNdsSrcObject->NdsValue.value_10.TelephoneNumber,
  282. &(lpVarDestObject->bstrVal)
  283. );
  284. RRETURN(hr);
  285. }
  286. HRESULT
  287. NdsTypeToVarTypeCopyNDSSynId11(
  288. PNDSOBJECT lpNdsSrcObject,
  289. PVARIANT lpVarDestObject
  290. )
  291. {
  292. HRESULT hr = S_OK;
  293. IADsFaxNumber * pFaxNumber= NULL;
  294. IDispatch * pDispatch = NULL;
  295. VARIANT VarDestObject;
  296. VariantInit(lpVarDestObject);
  297. hr = CFaxNumber::CreateFaxNumber(
  298. IID_IADsFaxNumber,
  299. (void **)&pFaxNumber
  300. );
  301. BAIL_ON_FAILURE(hr);
  302. hr = pFaxNumber->put_TelephoneNumber(lpNdsSrcObject->NdsValue.value_11.TelephoneNumber);
  303. BAIL_ON_FAILURE(hr);
  304. VariantInit(&VarDestObject);
  305. hr = BinaryToVariant(
  306. lpNdsSrcObject->NdsValue.value_11.NumberOfBits,
  307. lpNdsSrcObject->NdsValue.value_11.Parameters,
  308. &VarDestObject);
  309. BAIL_ON_FAILURE(hr);
  310. hr = pFaxNumber->put_Parameters(VarDestObject);
  311. BAIL_ON_FAILURE(hr);
  312. VariantClear(&VarDestObject);
  313. hr = pFaxNumber->QueryInterface(IID_IDispatch, (void**)&pDispatch);
  314. BAIL_ON_FAILURE(hr);
  315. VariantInit(lpVarDestObject);
  316. V_VT(lpVarDestObject) = VT_DISPATCH;
  317. V_DISPATCH(lpVarDestObject) = pDispatch;
  318. error:
  319. if (pFaxNumber) {
  320. pFaxNumber->Release();
  321. }
  322. RRETURN(hr);
  323. }
  324. HRESULT
  325. NdsTypeToVarTypeCopyNDSSynId12(
  326. PNDSOBJECT lpNdsSrcObject,
  327. PVARIANT lpVarDestObject
  328. )
  329. {
  330. IADsNetAddress * pNetAddress = NULL;
  331. IDispatch * pDispatch = NULL;
  332. HRESULT hr = S_OK;
  333. VARIANT VarDestObject;
  334. VariantInit(lpVarDestObject);
  335. hr = CNetAddress::CreateNetAddress(
  336. IID_IADsNetAddress,
  337. (void **)&pNetAddress
  338. );
  339. BAIL_ON_FAILURE(hr);
  340. hr = pNetAddress->put_AddressType(lpNdsSrcObject->NdsValue.value_12.AddressType);
  341. BAIL_ON_FAILURE(hr);
  342. VariantInit(&VarDestObject);
  343. hr = BinaryToVariant(
  344. lpNdsSrcObject->NdsValue.value_12.AddressLength,
  345. lpNdsSrcObject->NdsValue.value_12.Address,
  346. &VarDestObject);
  347. BAIL_ON_FAILURE(hr);
  348. hr = pNetAddress->put_Address(VarDestObject);
  349. BAIL_ON_FAILURE(hr);
  350. VariantClear(&VarDestObject);
  351. hr = pNetAddress->QueryInterface(IID_IDispatch, (void**)&pDispatch);
  352. BAIL_ON_FAILURE(hr);
  353. VariantInit(lpVarDestObject);
  354. V_VT(lpVarDestObject) = VT_DISPATCH;
  355. V_DISPATCH(lpVarDestObject) = pDispatch;
  356. error:
  357. if (pNetAddress) {
  358. pNetAddress->Release();
  359. }
  360. RRETURN(hr);
  361. }
  362. HRESULT
  363. NdsTypeToVarTypeCopyNDSSynId13(
  364. PNDSOBJECT lpNdsSrcObject,
  365. PVARIANT lpVarDestObject
  366. )
  367. {
  368. HRESULT hr = S_OK;
  369. SAFEARRAY *aList = NULL;
  370. SAFEARRAYBOUND aBound;
  371. CHAR HUGEP *pArray = NULL;
  372. long i;
  373. struct _NDS_OCTET_LIST *pCurrent = NULL;
  374. DWORD cElements = 0;
  375. IADsOctetList* pOctetList = NULL;
  376. IDispatch * pDispatch = NULL;
  377. VARIANT VarDestObject;
  378. VARIANT VarElement;
  379. hr = COctetList::CreateOctetList(
  380. IID_IADsOctetList,
  381. (void **)&pOctetList
  382. );
  383. BAIL_ON_FAILURE(hr);
  384. pCurrent = &(lpNdsSrcObject->NdsValue.value_13);
  385. while (pCurrent) {
  386. cElements++;
  387. pCurrent = pCurrent->Next;
  388. }
  389. aBound.lLbound = 0;
  390. aBound.cElements = cElements;
  391. aList = SafeArrayCreate( VT_VARIANT, 1, &aBound );
  392. if ( aList == NULL ) {
  393. hr = E_OUTOFMEMORY;
  394. BAIL_ON_FAILURE(hr);
  395. }
  396. pCurrent = &(lpNdsSrcObject->NdsValue.value_13);
  397. for ( i = 0; i < (long)cElements; i++ ) {
  398. VariantInit(&VarElement);
  399. hr = BinaryToVariant(
  400. pCurrent->Length,
  401. pCurrent->Data,
  402. &VarElement);
  403. BAIL_ON_FAILURE(hr);
  404. hr = SafeArrayPutElement( aList, &i, &VarElement);
  405. BAIL_ON_FAILURE(hr);
  406. pCurrent = pCurrent->Next;
  407. }
  408. VariantInit(&VarDestObject);
  409. V_VT(&VarDestObject) = VT_ARRAY | VT_BSTR;
  410. V_ARRAY(&VarDestObject) = aList;
  411. hr = pOctetList->put_OctetList(VarDestObject);
  412. BAIL_ON_FAILURE(hr);
  413. VariantClear(&VarDestObject);
  414. aList = NULL;
  415. hr = pOctetList->QueryInterface(IID_IDispatch, (void**)&pDispatch);
  416. BAIL_ON_FAILURE(hr);
  417. VariantInit(lpVarDestObject);
  418. V_VT(lpVarDestObject) = VT_DISPATCH;
  419. V_DISPATCH(lpVarDestObject) = pDispatch;
  420. error:
  421. if ( aList ) {
  422. SafeArrayDestroy( aList );
  423. }
  424. if (pOctetList) {
  425. pOctetList->Release();
  426. }
  427. RRETURN(hr);
  428. }
  429. HRESULT
  430. NdsTypeToVarTypeCopyNDSSynId14(
  431. PNDSOBJECT lpNdsSrcObject,
  432. PVARIANT lpVarDestObject
  433. )
  434. {
  435. HRESULT hr = S_OK;
  436. IADsEmail * pEmail= NULL;
  437. IDispatch * pDispatch = NULL;
  438. VARIANT VarDestObject;
  439. VariantInit(lpVarDestObject);
  440. hr = CEmail::CreateEmail(
  441. IID_IADsEmail,
  442. (void **)&pEmail
  443. );
  444. BAIL_ON_FAILURE(hr);
  445. hr = pEmail->put_Address(lpNdsSrcObject->NdsValue.value_14.Address);
  446. BAIL_ON_FAILURE(hr);
  447. hr = pEmail->put_Type(lpNdsSrcObject->NdsValue.value_14.Type);
  448. BAIL_ON_FAILURE(hr);
  449. hr = pEmail->QueryInterface(IID_IDispatch, (void**)&pDispatch);
  450. BAIL_ON_FAILURE(hr);
  451. VariantInit(lpVarDestObject);
  452. V_VT(lpVarDestObject) = VT_DISPATCH;
  453. V_DISPATCH(lpVarDestObject) = pDispatch;
  454. error:
  455. if (pEmail) {
  456. pEmail->Release();
  457. }
  458. RRETURN(hr);
  459. }
  460. HRESULT
  461. NdsTypeToVarTypeCopyNDSSynId15(
  462. PNDSOBJECT lpNdsSrcObject,
  463. PVARIANT lpVarDestObject
  464. )
  465. {
  466. IADsPath * pPath = NULL;
  467. IDispatch * pDispatch = NULL;
  468. HRESULT hr = S_OK;
  469. VariantInit(lpVarDestObject);
  470. hr = CPath::CreatePath(
  471. IID_IADsPath,
  472. (void **)&pPath
  473. );
  474. BAIL_ON_FAILURE(hr);
  475. hr = pPath->put_Type(lpNdsSrcObject->NdsValue.value_15.Type);
  476. BAIL_ON_FAILURE(hr);
  477. hr = pPath->put_VolumeName(lpNdsSrcObject->NdsValue.value_15.VolumeName);
  478. BAIL_ON_FAILURE(hr);
  479. hr = pPath->put_Path(lpNdsSrcObject->NdsValue.value_15.Path);
  480. BAIL_ON_FAILURE(hr);
  481. hr = pPath->QueryInterface(IID_IDispatch, (void**)&pDispatch);
  482. BAIL_ON_FAILURE(hr);
  483. VariantInit(lpVarDestObject);
  484. V_VT(lpVarDestObject) = VT_DISPATCH;
  485. V_DISPATCH(lpVarDestObject) = pDispatch;
  486. error:
  487. if (pPath) {
  488. pPath->Release();
  489. }
  490. RRETURN(hr);
  491. }
  492. HRESULT
  493. NdsTypeToVarTypeCopyNDSSynId16(
  494. PNDSOBJECT lpNdsSrcObject,
  495. PVARIANT lpVarDestObject
  496. )
  497. {
  498. IADsReplicaPointer * pReplicaPointer = NULL;
  499. IDispatch * pDispatch = NULL;
  500. HRESULT hr = S_OK;
  501. LPWSTR ServerName = NULL;
  502. DWORD ReplicaType = 0;
  503. DWORD ReplicaNumber = 0;
  504. DWORD Count = 0;
  505. NDSOBJECT object;
  506. VARIANT varDestObject;
  507. VariantInit(lpVarDestObject);
  508. hr = CReplicaPointer::CreateReplicaPointer(
  509. IID_IADsReplicaPointer,
  510. (void **)&pReplicaPointer
  511. );
  512. BAIL_ON_FAILURE(hr);
  513. hr = pReplicaPointer->put_ServerName(lpNdsSrcObject->NdsValue.value_16.ServerName);
  514. BAIL_ON_FAILURE(hr);
  515. hr = pReplicaPointer->put_ReplicaType(lpNdsSrcObject->NdsValue.value_16.ReplicaType);
  516. BAIL_ON_FAILURE(hr);
  517. hr = pReplicaPointer->put_ReplicaNumber(lpNdsSrcObject->NdsValue.value_16.ReplicaNumber);
  518. BAIL_ON_FAILURE(hr);
  519. hr = pReplicaPointer->put_Count(lpNdsSrcObject->NdsValue.value_16.Count);
  520. BAIL_ON_FAILURE(hr);
  521. VariantInit(&varDestObject);
  522. memcpy(&object.NdsValue.value_12,
  523. lpNdsSrcObject->NdsValue.value_16.ReplicaAddressHints,
  524. sizeof(NDS_ASN1_TYPE_12));
  525. hr = NdsTypeToVarTypeCopyNDSSynId12(
  526. &object,
  527. &varDestObject
  528. );
  529. BAIL_ON_FAILURE(hr);
  530. hr = pReplicaPointer->put_ReplicaAddressHints(varDestObject);
  531. BAIL_ON_FAILURE(hr);
  532. VariantClear(&varDestObject);
  533. hr = pReplicaPointer->QueryInterface(IID_IDispatch, (void**)&pDispatch);
  534. BAIL_ON_FAILURE(hr);
  535. VariantInit(lpVarDestObject);
  536. V_VT(lpVarDestObject) = VT_DISPATCH;
  537. V_DISPATCH(lpVarDestObject) = pDispatch;
  538. error:
  539. if (pReplicaPointer) {
  540. pReplicaPointer->Release();
  541. }
  542. RRETURN(hr);
  543. }
  544. HRESULT
  545. NdsTypeToVarTypeCopyNDSSynId17(
  546. PNDSOBJECT lpNdsSrcObject,
  547. PVARIANT lpVarDestObject
  548. )
  549. {
  550. IADsAcl * pSecDes = NULL;
  551. IDispatch * pDispatch = NULL;
  552. HRESULT hr = S_OK;
  553. hr = CAcl::CreateSecurityDescriptor(
  554. IID_IADsAcl,
  555. (void **)&pSecDes
  556. );
  557. BAIL_ON_FAILURE(hr);
  558. hr = pSecDes->put_SubjectName(lpNdsSrcObject->NdsValue.value_17.SubjectName);
  559. BAIL_ON_FAILURE(hr);
  560. hr = pSecDes->put_ProtectedAttrName(lpNdsSrcObject->NdsValue.value_17.ProtectedAttrName);
  561. BAIL_ON_FAILURE(hr);
  562. hr = pSecDes->put_Privileges(lpNdsSrcObject->NdsValue.value_17.Privileges);
  563. BAIL_ON_FAILURE(hr);
  564. hr = pSecDes->QueryInterface(IID_IDispatch, (void**)&pDispatch);
  565. BAIL_ON_FAILURE(hr);
  566. VariantInit(lpVarDestObject);
  567. V_VT(lpVarDestObject) = VT_DISPATCH;
  568. V_DISPATCH(lpVarDestObject) = pDispatch;
  569. error:
  570. if (pSecDes) {
  571. pSecDes->Release();
  572. }
  573. RRETURN(hr);
  574. }
  575. HRESULT
  576. NdsTypeToVarTypeCopyNDSSynId18(
  577. PNDSOBJECT lpNdsSrcObject,
  578. PVARIANT lpVarDestObject
  579. )
  580. {
  581. HRESULT hr = S_OK;
  582. SAFEARRAY *aList = NULL;
  583. SAFEARRAYBOUND aBound;
  584. CHAR HUGEP *pArray = NULL;
  585. long i;
  586. BSTR bstrAddress;
  587. IADsPostalAddress* pPostalAddress = NULL;
  588. IDispatch * pDispatch = NULL;
  589. VARIANT VarDestObject;
  590. VARIANT varElement;
  591. hr = CPostalAddress::CreatePostalAddress(
  592. IID_IADsPostalAddress,
  593. (void **)&pPostalAddress
  594. );
  595. BAIL_ON_FAILURE(hr);
  596. aBound.lLbound = 0;
  597. aBound.cElements = 6;
  598. aList = SafeArrayCreate( VT_VARIANT, 1, &aBound );
  599. if ( aList == NULL ) {
  600. hr = E_OUTOFMEMORY;
  601. BAIL_ON_FAILURE(hr);
  602. }
  603. for ( i = 0; i < (long) 6; i++ ) {
  604. VariantInit(&varElement);
  605. varElement.vt = VT_BSTR;
  606. hr = ADsAllocString(
  607. lpNdsSrcObject->NdsValue.value_18.PostalAddress[i],
  608. &varElement.bstrVal
  609. );
  610. BAIL_ON_FAILURE(hr);
  611. hr = SafeArrayPutElement( aList, &i, &varElement);
  612. BAIL_ON_FAILURE(hr);
  613. VariantClear(&varElement);
  614. }
  615. VariantInit(&VarDestObject);
  616. V_VT(&VarDestObject) = VT_ARRAY | VT_VARIANT;
  617. V_ARRAY(&VarDestObject) = aList;
  618. hr = pPostalAddress->put_PostalAddress(VarDestObject);
  619. BAIL_ON_FAILURE(hr);
  620. hr = pPostalAddress->QueryInterface(IID_IDispatch, (void**)&pDispatch);
  621. BAIL_ON_FAILURE(hr);
  622. VariantInit(lpVarDestObject);
  623. V_VT(lpVarDestObject) = VT_DISPATCH;
  624. V_DISPATCH(lpVarDestObject) = pDispatch;
  625. RRETURN(hr);
  626. error:
  627. if ( aList )
  628. SafeArrayDestroy( aList );
  629. RRETURN(hr);
  630. }
  631. HRESULT
  632. NdsTypeToVarTypeCopyNDSSynId19(
  633. PNDSOBJECT lpNdsSrcObject,
  634. PVARIANT lpVarDestObject
  635. )
  636. {
  637. IADsTimestamp * pTime = NULL;
  638. IDispatch * pDispatch = NULL;
  639. HRESULT hr = S_OK;
  640. hr = CTimestamp::CreateTimestamp(
  641. IID_IADsTimestamp,
  642. (void **)&pTime
  643. );
  644. BAIL_ON_FAILURE(hr);
  645. hr = pTime->put_WholeSeconds(lpNdsSrcObject->NdsValue.value_19.WholeSeconds);
  646. BAIL_ON_FAILURE(hr);
  647. hr = pTime->put_EventID(lpNdsSrcObject->NdsValue.value_19.EventID);
  648. BAIL_ON_FAILURE(hr);
  649. hr = pTime->QueryInterface(IID_IDispatch, (void**)&pDispatch);
  650. BAIL_ON_FAILURE(hr);
  651. VariantInit(lpVarDestObject);
  652. V_VT(lpVarDestObject) = VT_DISPATCH;
  653. V_DISPATCH(lpVarDestObject) = pDispatch;
  654. error:
  655. if (pTime) {
  656. pTime->Release();
  657. }
  658. RRETURN(hr);
  659. }
  660. HRESULT
  661. NdsTypeToVarTypeCopyNDSSynId20(
  662. PNDSOBJECT lpNdsSrcObject,
  663. PVARIANT lpVarDestObject
  664. )
  665. {
  666. HRESULT hr = S_OK;
  667. lpVarDestObject->vt = VT_BSTR;
  668. hr = ADsAllocString(
  669. lpNdsSrcObject->NdsValue.value_20.ClassName,
  670. &(lpVarDestObject->bstrVal)
  671. );
  672. RRETURN(hr);
  673. }
  674. HRESULT
  675. NdsTypeToVarTypeCopyNDSSynId21(
  676. PNDSOBJECT lpNdsSrcObject,
  677. PVARIANT lpVarDestObject
  678. )
  679. {
  680. HRESULT hr = S_OK;
  681. VariantInit(lpVarDestObject);
  682. hr = BinaryToVariant(
  683. lpNdsSrcObject->NdsValue.value_21.Length,
  684. lpNdsSrcObject->NdsValue.value_21.Data,
  685. lpVarDestObject);
  686. RRETURN(hr);
  687. }
  688. HRESULT
  689. NdsTypeToVarTypeCopyNDSSynId22(
  690. PNDSOBJECT lpNdsSrcObject,
  691. PVARIANT lpVarDestObject
  692. )
  693. {
  694. HRESULT hr = S_OK;
  695. lpVarDestObject->vt = VT_I4;
  696. lpVarDestObject->lVal =
  697. lpNdsSrcObject->NdsValue.value_22.Counter;
  698. RRETURN(hr);
  699. }
  700. HRESULT
  701. NdsTypeToVarTypeCopyNDSSynId23(
  702. PNDSOBJECT lpNdsSrcObject,
  703. PVARIANT lpVarDestObject
  704. )
  705. {
  706. IADsBackLink * pBackLink = NULL;
  707. IDispatch * pDispatch = NULL;
  708. HRESULT hr = S_OK;
  709. hr = CBackLink::CreateBackLink(
  710. IID_IADsBackLink,
  711. (void **)&pBackLink
  712. );
  713. BAIL_ON_FAILURE(hr);
  714. hr = pBackLink->put_ObjectName(lpNdsSrcObject->NdsValue.value_23.ObjectName);
  715. BAIL_ON_FAILURE(hr);
  716. hr = pBackLink->put_RemoteID(lpNdsSrcObject->NdsValue.value_23.RemoteID);
  717. BAIL_ON_FAILURE(hr);
  718. hr = pBackLink->QueryInterface(IID_IDispatch, (void**)&pDispatch);
  719. BAIL_ON_FAILURE(hr);
  720. VariantInit(lpVarDestObject);
  721. V_VT(lpVarDestObject) = VT_DISPATCH;
  722. V_DISPATCH(lpVarDestObject) = pDispatch;
  723. error:
  724. if (pBackLink) {
  725. pBackLink->Release();
  726. }
  727. RRETURN(hr);
  728. }
  729. HRESULT
  730. NdsTypeToVarTypeCopyNDSSynId24(
  731. PNDSOBJECT lpNdsSrcObject,
  732. PVARIANT lpVarDestObject
  733. )
  734. {
  735. HRESULT hr = S_OK;
  736. lpVarDestObject->vt = VT_DATE;
  737. hr = NDSConvertDWORDtoDATE(
  738. lpNdsSrcObject->NdsValue.value_24.Time,
  739. &(lpVarDestObject->date)
  740. );
  741. RRETURN(hr);
  742. }
  743. HRESULT
  744. NdsTypeToVarTypeCopyNDSSynId25(
  745. PNDSOBJECT lpNdsSrcObject,
  746. PVARIANT lpVarDestObject
  747. )
  748. {
  749. IADsTypedName * pTypedName = NULL;
  750. IDispatch * pDispatch = NULL;
  751. HRESULT hr = S_OK;
  752. hr = CTypedName::CreateTypedName(
  753. IID_IADsTypedName,
  754. (void **)&pTypedName
  755. );
  756. BAIL_ON_FAILURE(hr);
  757. hr = pTypedName->put_ObjectName(lpNdsSrcObject->NdsValue.value_25.ObjectName);
  758. BAIL_ON_FAILURE(hr);
  759. hr = pTypedName->put_Level(lpNdsSrcObject->NdsValue.value_25.Level);
  760. BAIL_ON_FAILURE(hr);
  761. hr = pTypedName->put_Interval(lpNdsSrcObject->NdsValue.value_25.Interval);
  762. BAIL_ON_FAILURE(hr);
  763. hr = pTypedName->QueryInterface(IID_IDispatch, (void**)&pDispatch);
  764. BAIL_ON_FAILURE(hr);
  765. VariantInit(lpVarDestObject);
  766. V_VT(lpVarDestObject) = VT_DISPATCH;
  767. V_DISPATCH(lpVarDestObject) = pDispatch;
  768. error:
  769. if (pTypedName) {
  770. pTypedName->Release();
  771. }
  772. RRETURN(hr);
  773. }
  774. HRESULT
  775. NdsTypeToVarTypeCopyNDSSynId26(
  776. PNDSOBJECT lpNdsSrcObject,
  777. PVARIANT lpVarDestObject
  778. )
  779. {
  780. IADsHold * pHold = NULL;
  781. IDispatch * pDispatch = NULL;
  782. HRESULT hr = S_OK;
  783. hr = CHold::CreateHold(
  784. IID_IADsHold,
  785. (void **)&pHold
  786. );
  787. BAIL_ON_FAILURE(hr);
  788. hr = pHold->put_ObjectName(lpNdsSrcObject->NdsValue.value_26.ObjectName);
  789. BAIL_ON_FAILURE(hr);
  790. hr = pHold->put_Amount(lpNdsSrcObject->NdsValue.value_26.Amount);
  791. BAIL_ON_FAILURE(hr);
  792. hr = pHold->QueryInterface(IID_IDispatch, (void**)&pDispatch);
  793. BAIL_ON_FAILURE(hr);
  794. VariantInit(lpVarDestObject);
  795. V_VT(lpVarDestObject) = VT_DISPATCH;
  796. V_DISPATCH(lpVarDestObject) = pDispatch;
  797. error:
  798. if (pHold) {
  799. pHold->Release();
  800. }
  801. RRETURN(hr);
  802. }
  803. HRESULT
  804. NdsTypeToVarTypeCopyNDSSynId27(
  805. PNDSOBJECT lpNdsSrcObject,
  806. PVARIANT lpVarDestObject
  807. )
  808. {
  809. HRESULT hr = S_OK;
  810. lpVarDestObject->vt = VT_I4;
  811. lpVarDestObject->lVal =
  812. lpNdsSrcObject->NdsValue.value_27.Interval;
  813. RRETURN(hr);
  814. }
  815. HRESULT
  816. NdsTypeToVarTypeCopy(
  817. PNDSOBJECT lpNdsSrcObject,
  818. PVARIANT lpVarDestObject
  819. )
  820. {
  821. HRESULT hr = S_OK;
  822. switch (lpNdsSrcObject->NdsType) {
  823. case 1:
  824. hr = NdsTypeToVarTypeCopyNDSSynId1(
  825. lpNdsSrcObject,
  826. lpVarDestObject
  827. );
  828. break;
  829. case 2:
  830. hr = NdsTypeToVarTypeCopyNDSSynId2(
  831. lpNdsSrcObject,
  832. lpVarDestObject
  833. );
  834. break;
  835. case 3:
  836. hr = NdsTypeToVarTypeCopyNDSSynId3(
  837. lpNdsSrcObject,
  838. lpVarDestObject
  839. );
  840. break;
  841. case 4:
  842. hr = NdsTypeToVarTypeCopyNDSSynId4(
  843. lpNdsSrcObject,
  844. lpVarDestObject
  845. );
  846. break;
  847. case 5:
  848. hr = NdsTypeToVarTypeCopyNDSSynId5(
  849. lpNdsSrcObject,
  850. lpVarDestObject
  851. );
  852. break;
  853. case 6:
  854. hr = NdsTypeToVarTypeCopyNDSSynId6(
  855. lpNdsSrcObject,
  856. lpVarDestObject
  857. );
  858. break;
  859. case 7:
  860. hr = NdsTypeToVarTypeCopyNDSSynId7(
  861. lpNdsSrcObject,
  862. lpVarDestObject
  863. );
  864. break;
  865. case 8:
  866. hr = NdsTypeToVarTypeCopyNDSSynId8(
  867. lpNdsSrcObject,
  868. lpVarDestObject
  869. );
  870. break;
  871. case 9:
  872. hr = NdsTypeToVarTypeCopyNDSSynId9(
  873. lpNdsSrcObject,
  874. lpVarDestObject
  875. );
  876. break;
  877. case 10:
  878. hr = NdsTypeToVarTypeCopyNDSSynId10(
  879. lpNdsSrcObject,
  880. lpVarDestObject
  881. );
  882. break;
  883. case 11:
  884. hr = NdsTypeToVarTypeCopyNDSSynId11(
  885. lpNdsSrcObject,
  886. lpVarDestObject
  887. );
  888. break;
  889. case 12:
  890. hr = NdsTypeToVarTypeCopyNDSSynId12(
  891. lpNdsSrcObject,
  892. lpVarDestObject
  893. );
  894. break;
  895. case 13:
  896. hr = NdsTypeToVarTypeCopyNDSSynId13(
  897. lpNdsSrcObject,
  898. lpVarDestObject
  899. );
  900. break;
  901. case 14:
  902. hr = NdsTypeToVarTypeCopyNDSSynId14(
  903. lpNdsSrcObject,
  904. lpVarDestObject
  905. );
  906. break;
  907. case 15:
  908. hr = NdsTypeToVarTypeCopyNDSSynId15(
  909. lpNdsSrcObject,
  910. lpVarDestObject
  911. );
  912. break;
  913. case 16:
  914. hr = NdsTypeToVarTypeCopyNDSSynId16(
  915. lpNdsSrcObject,
  916. lpVarDestObject
  917. );
  918. break;
  919. case 17:
  920. hr = NdsTypeToVarTypeCopyNDSSynId17(
  921. lpNdsSrcObject,
  922. lpVarDestObject
  923. );
  924. break;
  925. case 18:
  926. hr = NdsTypeToVarTypeCopyNDSSynId18(
  927. lpNdsSrcObject,
  928. lpVarDestObject
  929. );
  930. break;
  931. case 19:
  932. hr = NdsTypeToVarTypeCopyNDSSynId19(
  933. lpNdsSrcObject,
  934. lpVarDestObject
  935. );
  936. break;
  937. case 20:
  938. hr = NdsTypeToVarTypeCopyNDSSynId20(
  939. lpNdsSrcObject,
  940. lpVarDestObject
  941. );
  942. break;
  943. case 21:
  944. hr = NdsTypeToVarTypeCopyNDSSynId21(
  945. lpNdsSrcObject,
  946. lpVarDestObject
  947. );
  948. break;
  949. case 22:
  950. hr = NdsTypeToVarTypeCopyNDSSynId22(
  951. lpNdsSrcObject,
  952. lpVarDestObject
  953. );
  954. break;
  955. case 23:
  956. hr = NdsTypeToVarTypeCopyNDSSynId23(
  957. lpNdsSrcObject,
  958. lpVarDestObject
  959. );
  960. break;
  961. case 24:
  962. hr = NdsTypeToVarTypeCopyNDSSynId24(
  963. lpNdsSrcObject,
  964. lpVarDestObject
  965. );
  966. break;
  967. case 25:
  968. hr = NdsTypeToVarTypeCopyNDSSynId25(
  969. lpNdsSrcObject,
  970. lpVarDestObject
  971. );
  972. break;
  973. case 26:
  974. hr = NdsTypeToVarTypeCopyNDSSynId26(
  975. lpNdsSrcObject,
  976. lpVarDestObject
  977. );
  978. break;
  979. case 27:
  980. hr = NdsTypeToVarTypeCopyNDSSynId27(
  981. lpNdsSrcObject,
  982. lpVarDestObject
  983. );
  984. break;
  985. default:
  986. hr = E_FAIL;
  987. break;
  988. }
  989. RRETURN(hr);
  990. }
  991. HRESULT
  992. NdsTypeToVarTypeCopyConstruct(
  993. LPNDSOBJECT pNdsSrcObjects,
  994. DWORD dwNumObjects,
  995. PVARIANT pVarDestObjects,
  996. BOOLEAN bReturnArrayAlways
  997. )
  998. {
  999. long i = 0;
  1000. HRESULT hr = S_OK;
  1001. VARIANT VarDestObjectsTemp;
  1002. SAFEARRAY *aList = NULL;
  1003. SAFEARRAY *aListTmp = NULL;
  1004. if ((pNdsSrcObjects->NdsType == 17) || (dwNumObjects > 1) || bReturnArrayAlways) {
  1005. VariantInit(pVarDestObjects);
  1006. //
  1007. // The following are for handling are multi-value properties
  1008. //
  1009. SAFEARRAYBOUND aBound;
  1010. aBound.lLbound = 0;
  1011. aBound.cElements = dwNumObjects;
  1012. aList = SafeArrayCreate( VT_VARIANT, 1, &aBound );
  1013. if ( aList == NULL )
  1014. {
  1015. hr = E_OUTOFMEMORY;
  1016. BAIL_ON_FAILURE(hr);
  1017. }
  1018. for ( i = 0; i < (long) dwNumObjects; i++ )
  1019. {
  1020. VARIANT v;
  1021. VariantInit(&v);
  1022. hr = NdsTypeToVarTypeCopy( pNdsSrcObjects + i,
  1023. &v );
  1024. BAIL_ON_FAILURE(hr);
  1025. hr = SafeArrayPutElement( aList, &i, &v );
  1026. VariantClear(&v);
  1027. BAIL_ON_FAILURE(hr);
  1028. }
  1029. V_VT(pVarDestObjects) = VT_ARRAY | VT_VARIANT;
  1030. V_ARRAY(pVarDestObjects) = aList;
  1031. //
  1032. // If it is an NDS ACL, we will convert it into an
  1033. // NT Security Descriptor
  1034. //
  1035. if (pNdsSrcObjects->NdsType == 17) {
  1036. hr = ConvertNDSAclVArrayToSecDesVar(pVarDestObjects,
  1037. &VarDestObjectsTemp);
  1038. SafeArrayDestroy( aList );
  1039. if (!bReturnArrayAlways) {
  1040. V_VT(pVarDestObjects) = V_VT(&VarDestObjectsTemp);
  1041. V_DISPATCH(pVarDestObjects) = V_DISPATCH(&VarDestObjectsTemp);
  1042. }
  1043. else {
  1044. //
  1045. // Pack SecDescriptor into a one-element array
  1046. //
  1047. SAFEARRAYBOUND aBoundTmp;
  1048. long j = 0;
  1049. aBoundTmp.lLbound = 0;
  1050. aBoundTmp.cElements = 1;
  1051. aListTmp = SafeArrayCreate( VT_VARIANT, 1, &aBoundTmp);
  1052. if ( aListTmp == NULL )
  1053. {
  1054. hr = E_OUTOFMEMORY;
  1055. BAIL_ON_FAILURE(hr);
  1056. }
  1057. hr = SafeArrayPutElement( aListTmp, &j, &VarDestObjectsTemp);
  1058. BAIL_ON_FAILURE(hr);
  1059. V_VT(pVarDestObjects) = VT_ARRAY | VT_VARIANT;
  1060. V_ARRAY(pVarDestObjects) = aListTmp;
  1061. }
  1062. }
  1063. }
  1064. else {
  1065. hr = NdsTypeToVarTypeCopy(
  1066. pNdsSrcObjects,
  1067. pVarDestObjects
  1068. );
  1069. }
  1070. BAIL_ON_FAILURE(hr);
  1071. RRETURN(hr);
  1072. error:
  1073. if ( aList ) {
  1074. SafeArrayDestroy( aList );
  1075. }
  1076. if ( aListTmp ) {
  1077. SafeArrayDestroy( aListTmp );
  1078. }
  1079. RRETURN(hr);
  1080. }