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.

1624 lines
38 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. // File: var2nds.cxx
  7. //
  8. // Contents: NDS Object to Variant Copy Routines
  9. //
  10. // Functions:
  11. //
  12. // History: 25-Apr-96 KrishnaG Created.
  13. //
  14. //
  15. //
  16. //
  17. // NDS_ASN1_TYPE_1
  18. //
  19. // NDS_ASN1_TYPE_2
  20. //
  21. // NDS_ASN1_TYPE_3
  22. //
  23. // NDS_ASN1_TYPE_4
  24. //
  25. // NDS_ASN1_TYPE_5
  26. //
  27. // NDS_ASN1_TYPE_6
  28. //
  29. // NDS_ASN1_TYPE_7
  30. //
  31. // NDS_ASN1_TYPE_8
  32. //
  33. // NDS_ASN1_TYPE_9
  34. //
  35. // NDS_ASN1_TYPE_10
  36. //
  37. // NDS_ASN1_TYPE_11
  38. //
  39. // NDS_ASN1_TYPE_12
  40. //
  41. // NDS_ASN1_TYPE_13
  42. //
  43. // NDS_ASN1_TYPE_14
  44. //
  45. // NDS_ASN1_TYPE_15
  46. //
  47. // NDS_ASN1_TYPE_16
  48. //
  49. // NDS_ASN1_TYPE_17
  50. //
  51. // NDS_ASN1_TYPE_18
  52. //
  53. // NDS_ASN1_TYPE_19
  54. //
  55. // NDS_ASN1_TYPE_20
  56. //
  57. // NDS_ASN1_TYPE_21
  58. //
  59. // NDS_ASN1_TYPE_22
  60. //
  61. // NDS_ASN1_TYPE_23
  62. //
  63. // NDS_ASN1_TYPE_24
  64. //
  65. // NDS_ASN1_TYPE_25
  66. //
  67. // NDS_ASN1_TYPE_26
  68. //
  69. // NDS_ASN1_TYPE_27
  70. //
  71. //
  72. //----------------------------------------------------------------------------
  73. #include "nds.hxx"
  74. //
  75. // NdsType objects copy code
  76. //
  77. HRESULT
  78. VarTypeToNdsTypeCopyNDSSynId1(
  79. PVARIANT lpVarSrcObject,
  80. PNDSOBJECT lpNdsDestObject
  81. )
  82. {
  83. HRESULT hr = S_OK;
  84. if(lpVarSrcObject->vt != VT_BSTR){
  85. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  86. }
  87. lpNdsDestObject->NdsType = NDS_SYNTAX_ID_1;
  88. lpNdsDestObject->NdsValue.value_1.DNString =
  89. AllocADsStr(
  90. lpVarSrcObject->bstrVal
  91. );
  92. if ((!lpNdsDestObject->NdsValue.value_1.DNString) &&
  93. (lpVarSrcObject->bstrVal)) {
  94. RRETURN(E_OUTOFMEMORY);
  95. }
  96. RRETURN(hr);
  97. }
  98. HRESULT
  99. VarTypeToNdsTypeCopyNDSSynId2(
  100. PVARIANT lpVarSrcObject,
  101. PNDSOBJECT lpNdsDestObject
  102. )
  103. {
  104. HRESULT hr = S_OK;
  105. if(lpVarSrcObject->vt != VT_BSTR){
  106. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  107. }
  108. lpNdsDestObject->NdsType = NDS_SYNTAX_ID_2;
  109. lpNdsDestObject->NdsValue.value_2.CaseExactString =
  110. AllocADsStr(
  111. lpVarSrcObject->bstrVal
  112. );
  113. if ((!lpNdsDestObject->NdsValue.value_2.CaseExactString) &&
  114. (lpVarSrcObject->bstrVal)) {
  115. RRETURN(E_OUTOFMEMORY);
  116. }
  117. RRETURN(hr);
  118. }
  119. HRESULT
  120. VarTypeToNdsTypeCopyNDSSynId3(
  121. PVARIANT lpVarSrcObject,
  122. PNDSOBJECT lpNdsDestObject
  123. )
  124. {
  125. HRESULT hr = S_OK;
  126. if(lpVarSrcObject->vt != VT_BSTR){
  127. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  128. }
  129. lpNdsDestObject->NdsType = NDS_SYNTAX_ID_3;
  130. lpNdsDestObject->NdsValue.value_3.CaseIgnoreString =
  131. AllocADsStr(
  132. lpVarSrcObject->bstrVal
  133. );
  134. if ((!lpNdsDestObject->NdsValue.value_3.CaseIgnoreString) &&
  135. (lpVarSrcObject->bstrVal)) {
  136. RRETURN(E_OUTOFMEMORY);
  137. }
  138. RRETURN(hr);
  139. }
  140. HRESULT
  141. VarTypeToNdsTypeCopyNDSSynId4(
  142. PVARIANT lpVarSrcObject,
  143. PNDSOBJECT lpNdsDestObject
  144. )
  145. {
  146. HRESULT hr = S_OK;
  147. if(lpVarSrcObject->vt != VT_BSTR){
  148. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  149. }
  150. lpNdsDestObject->NdsType = NDS_SYNTAX_ID_4;
  151. lpNdsDestObject->NdsValue.value_4.PrintableString =
  152. AllocADsStr(
  153. lpVarSrcObject->bstrVal
  154. );
  155. if ((!lpNdsDestObject->NdsValue.value_4.PrintableString) &&
  156. (lpVarSrcObject->bstrVal)) {
  157. RRETURN(E_OUTOFMEMORY);
  158. }
  159. RRETURN(hr);
  160. }
  161. HRESULT
  162. VarTypeToNdsTypeCopyNDSSynId5(
  163. PVARIANT lpVarSrcObject,
  164. PNDSOBJECT lpNdsDestObject
  165. )
  166. {
  167. HRESULT hr = S_OK;
  168. if(lpVarSrcObject->vt != VT_BSTR){
  169. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  170. }
  171. lpNdsDestObject->NdsType = NDS_SYNTAX_ID_5;
  172. lpNdsDestObject->NdsValue.value_5.NumericString =
  173. AllocADsStr(
  174. lpVarSrcObject->bstrVal
  175. );
  176. if ((!lpNdsDestObject->NdsValue.value_5.NumericString) &&
  177. (lpVarSrcObject->bstrVal)) {
  178. RRETURN(E_OUTOFMEMORY);
  179. }
  180. RRETURN(hr);
  181. }
  182. HRESULT
  183. VarTypeToNdsTypeCopyNDSSynId6(
  184. PVARIANT lpVarSrcObject,
  185. PNDSOBJECT lpNdsDestObject
  186. )
  187. {
  188. HRESULT hr = S_OK;
  189. DWORD dwSLBound = 0;
  190. DWORD dwSUBound = 0;
  191. long i;
  192. LPNDS_ASN1_TYPE_6 pCurrent = NULL;
  193. IADsCaseIgnoreList FAR * pCaseIgnoreList = NULL;
  194. IDispatch FAR * pDispatch = NULL;
  195. BYTE* pbParameter = NULL;
  196. VARIANT varCaseIgnoreList;
  197. VARIANT varElement;
  198. VariantInit(&varCaseIgnoreList);
  199. if (V_VT(lpVarSrcObject) != VT_DISPATCH){
  200. hr = E_FAIL;
  201. BAIL_ON_FAILURE(hr);
  202. }
  203. pDispatch = V_DISPATCH(lpVarSrcObject);
  204. hr = pDispatch->QueryInterface(
  205. IID_IADsCaseIgnoreList,
  206. (void **)&pCaseIgnoreList
  207. );
  208. BAIL_ON_FAILURE(hr);
  209. hr = pCaseIgnoreList->get_CaseIgnoreList(
  210. &varCaseIgnoreList
  211. );
  212. BAIL_ON_FAILURE(hr);
  213. if(!((V_VT(&varCaseIgnoreList) & VT_VARIANT) && V_ISARRAY(&varCaseIgnoreList))) {
  214. return(E_FAIL);
  215. }
  216. if ((V_ARRAY(&varCaseIgnoreList))->cDims != 1) {
  217. hr = E_FAIL;
  218. BAIL_ON_FAILURE(hr);
  219. }
  220. if ((V_ARRAY(&varCaseIgnoreList))->rgsabound[0].cElements <= 0) {
  221. hr = E_FAIL;
  222. BAIL_ON_FAILURE(hr);
  223. }
  224. hr = SafeArrayGetLBound(V_ARRAY(&varCaseIgnoreList),
  225. 1,
  226. (long FAR *)&dwSLBound
  227. );
  228. BAIL_ON_FAILURE(hr);
  229. hr = SafeArrayGetUBound(V_ARRAY(&varCaseIgnoreList),
  230. 1,
  231. (long FAR *)&dwSUBound
  232. );
  233. BAIL_ON_FAILURE(hr);
  234. lpNdsDestObject->NdsType = NDS_SYNTAX_ID_6;
  235. pCurrent = &lpNdsDestObject->NdsValue.value_6;
  236. for (i = dwSLBound; i <= (long)dwSUBound; i++) {
  237. VariantInit(&varElement);
  238. hr = SafeArrayGetElement(V_ARRAY(&varCaseIgnoreList),
  239. (long FAR *)&i,
  240. &varElement
  241. );
  242. BAIL_ON_FAILURE(hr);
  243. pCurrent->String = AllocADsStr(V_BSTR(&varElement));
  244. if ((!pCurrent->String) &&
  245. (V_BSTR(&varElement))) {
  246. RRETURN(E_OUTOFMEMORY);
  247. }
  248. if (i != (long)dwSUBound) {
  249. pCurrent->Next = (LPNDS_ASN1_TYPE_6)AllocADsMem(sizeof(NDS_ASN1_TYPE_6));
  250. if (!pCurrent->Next) {
  251. hr = E_OUTOFMEMORY;
  252. BAIL_ON_FAILURE(hr);
  253. }
  254. pCurrent = pCurrent->Next;
  255. }
  256. VariantClear(&varElement);
  257. }
  258. pCurrent->Next = NULL;
  259. RRETURN(S_OK);
  260. error:
  261. VariantClear(&varCaseIgnoreList);
  262. if (pCaseIgnoreList) {
  263. pCaseIgnoreList->Release();
  264. }
  265. RRETURN(hr);
  266. }
  267. HRESULT
  268. VarTypeToNdsTypeCopyNDSSynId7(
  269. PVARIANT lpVarSrcObject,
  270. PNDSOBJECT lpNdsDestObject
  271. )
  272. {
  273. HRESULT hr = S_OK;
  274. if(lpVarSrcObject->vt != VT_BOOL){
  275. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  276. }
  277. lpNdsDestObject->NdsType = NDS_SYNTAX_ID_7;
  278. lpNdsDestObject->NdsValue.value_7.Boolean =
  279. (lpVarSrcObject->boolVal)? TRUE:FALSE;
  280. RRETURN(hr);
  281. }
  282. HRESULT
  283. VarTypeToNdsTypeCopyNDSSynId8(
  284. PVARIANT lpVarSrcObject,
  285. PNDSOBJECT lpNdsDestObject
  286. )
  287. {
  288. HRESULT hr = S_OK;
  289. lpNdsDestObject->NdsType = NDS_SYNTAX_ID_8;
  290. if (lpVarSrcObject->vt == VT_I4)
  291. lpNdsDestObject->NdsValue.value_8.Integer = lpVarSrcObject->lVal;
  292. else if (lpVarSrcObject->vt == VT_I2)
  293. lpNdsDestObject->NdsValue.value_8.Integer = lpVarSrcObject->iVal;
  294. else
  295. hr = E_ADS_CANT_CONVERT_DATATYPE;
  296. RRETURN(hr);
  297. }
  298. HRESULT
  299. VarTypeToNdsTypeCopyNDSSynId9(
  300. PVARIANT lpVarSrcObject,
  301. PNDSOBJECT lpNdsDestObject
  302. )
  303. {
  304. HRESULT hr;
  305. lpNdsDestObject->NdsType = NDS_SYNTAX_ID_9;
  306. hr = VariantToBinary(
  307. lpVarSrcObject,
  308. &lpNdsDestObject->NdsValue.value_9.Length,
  309. &lpNdsDestObject->NdsValue.value_9.OctetString
  310. );
  311. RRETURN(hr);
  312. }
  313. HRESULT
  314. VarTypeToNdsTypeCopyNDSSynId10(
  315. PVARIANT lpVarSrcObject,
  316. PNDSOBJECT lpNdsDestObject
  317. )
  318. {
  319. HRESULT hr = S_OK;
  320. if(lpVarSrcObject->vt != VT_BSTR){
  321. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  322. }
  323. lpNdsDestObject->NdsType = NDS_SYNTAX_ID_10;
  324. lpNdsDestObject->NdsValue.value_10.TelephoneNumber =
  325. AllocADsStr(
  326. lpVarSrcObject->bstrVal
  327. );
  328. if ((!lpNdsDestObject->NdsValue.value_10.TelephoneNumber) &&
  329. (lpVarSrcObject->bstrVal)) {
  330. RRETURN(E_OUTOFMEMORY);
  331. }
  332. RRETURN(hr);
  333. }
  334. HRESULT
  335. VarTypeToNdsTypeCopyNDSSynId11(
  336. PVARIANT lpVarSrcObject,
  337. PNDSOBJECT lpNdsDestObject
  338. )
  339. {
  340. HRESULT hr = S_OK;
  341. IADsFaxNumber FAR * pFaxNumber = NULL;
  342. IDispatch FAR * pDispatch = NULL;
  343. BYTE* pbParameter = NULL;
  344. VARIANT varParameters;
  345. BSTR bstrVal;
  346. VariantInit(&varParameters);
  347. if (V_VT(lpVarSrcObject) != VT_DISPATCH){
  348. hr = E_FAIL;
  349. BAIL_ON_FAILURE(hr);
  350. }
  351. pDispatch = V_DISPATCH(lpVarSrcObject);
  352. hr = pDispatch->QueryInterface(
  353. IID_IADsFaxNumber,
  354. (void **)&pFaxNumber
  355. );
  356. BAIL_ON_FAILURE(hr);
  357. lpNdsDestObject->NdsType = NDS_SYNTAX_ID_11;
  358. hr = pFaxNumber->get_TelephoneNumber(
  359. &bstrVal
  360. );
  361. BAIL_ON_FAILURE(hr);
  362. lpNdsDestObject->NdsValue.value_11.TelephoneNumber =
  363. AllocADsStr(
  364. bstrVal
  365. );
  366. if ((!lpNdsDestObject->NdsValue.value_11.TelephoneNumber) &&
  367. (bstrVal)) {
  368. RRETURN(E_OUTOFMEMORY);
  369. }
  370. hr = pFaxNumber->get_Parameters(
  371. &varParameters
  372. );
  373. BAIL_ON_FAILURE(hr);
  374. hr = VariantToBinary(
  375. &varParameters,
  376. &lpNdsDestObject->NdsValue.value_11.NumberOfBits,
  377. &lpNdsDestObject->NdsValue.value_11.Parameters
  378. );
  379. BAIL_ON_FAILURE(hr);
  380. error:
  381. VariantClear(&varParameters);
  382. if (pFaxNumber) {
  383. pFaxNumber->Release();
  384. }
  385. RRETURN(hr);
  386. }
  387. HRESULT
  388. VarTypeToNdsTypeCopyNDSSynId12(
  389. PVARIANT lpVarSrcObject,
  390. PNDSOBJECT lpNdsDestObject
  391. )
  392. {
  393. HRESULT hr = S_OK;
  394. IADsNetAddress FAR * pNetAddress = NULL;
  395. IDispatch FAR * pDispatch = NULL;
  396. long dwAddressType = 0;
  397. BYTE* pbAddress = NULL;
  398. VARIANT varAddress;
  399. VariantInit(&varAddress);
  400. if (V_VT(lpVarSrcObject) != VT_DISPATCH){
  401. hr = E_FAIL;
  402. BAIL_ON_FAILURE(hr);
  403. }
  404. pDispatch = V_DISPATCH(lpVarSrcObject);
  405. hr = pDispatch->QueryInterface(
  406. IID_IADsNetAddress,
  407. (void **)&pNetAddress
  408. );
  409. BAIL_ON_FAILURE(hr);
  410. lpNdsDestObject->NdsType = NDS_SYNTAX_ID_12;
  411. hr = pNetAddress->get_AddressType(
  412. &dwAddressType
  413. );
  414. BAIL_ON_FAILURE(hr);
  415. lpNdsDestObject->NdsValue.value_12.AddressType = dwAddressType;
  416. VariantInit(&varAddress);
  417. hr = pNetAddress->get_Address(
  418. &varAddress
  419. );
  420. BAIL_ON_FAILURE(hr);
  421. hr = VariantToBinary(
  422. &varAddress,
  423. &lpNdsDestObject->NdsValue.value_12.AddressLength,
  424. &lpNdsDestObject->NdsValue.value_12.Address
  425. );
  426. BAIL_ON_FAILURE(hr);
  427. error:
  428. VariantClear(&varAddress);
  429. if (pNetAddress) {
  430. pNetAddress->Release();
  431. }
  432. RRETURN(hr);
  433. }
  434. HRESULT
  435. VarTypeToNdsTypeCopyNDSSynId13(
  436. PVARIANT lpVarSrcObject,
  437. PNDSOBJECT lpNdsDestObject
  438. )
  439. {
  440. HRESULT hr = S_OK;
  441. DWORD dwSLBound = 0;
  442. DWORD dwSUBound = 0;
  443. long i;
  444. LPNDS_ASN1_TYPE_13 pCurrent = NULL;
  445. IADsOctetList FAR * pOctetList= NULL;
  446. IDispatch FAR * pDispatch = NULL;
  447. BYTE* pbParameter = NULL;
  448. VARIANT varOctetList;
  449. VARIANT varElement;
  450. VariantInit(&varOctetList);
  451. if (V_VT(lpVarSrcObject) != VT_DISPATCH){
  452. hr = E_FAIL;
  453. BAIL_ON_FAILURE(hr);
  454. }
  455. pDispatch = V_DISPATCH(lpVarSrcObject);
  456. hr = pDispatch->QueryInterface(
  457. IID_IADsOctetList,
  458. (void **)&pOctetList
  459. );
  460. BAIL_ON_FAILURE(hr);
  461. hr = pOctetList->get_OctetList(&varOctetList);
  462. BAIL_ON_FAILURE(hr);
  463. if(!((V_VT(&varOctetList) & VT_VARIANT) && V_ISARRAY(&varOctetList))) {
  464. return(E_FAIL);
  465. }
  466. if ((V_ARRAY(&varOctetList))->cDims != 1) {
  467. hr = E_FAIL;
  468. BAIL_ON_FAILURE(hr);
  469. }
  470. if ((V_ARRAY(&varOctetList))->rgsabound[0].cElements <= 0) {
  471. hr = E_FAIL;
  472. BAIL_ON_FAILURE(hr);
  473. }
  474. hr = SafeArrayGetLBound(V_ARRAY(&varOctetList),
  475. 1,
  476. (long FAR *)&dwSLBound
  477. );
  478. BAIL_ON_FAILURE(hr);
  479. hr = SafeArrayGetUBound(V_ARRAY(&varOctetList),
  480. 1,
  481. (long FAR *)&dwSUBound
  482. );
  483. BAIL_ON_FAILURE(hr);
  484. lpNdsDestObject->NdsType = NDS_SYNTAX_ID_13;
  485. pCurrent = &lpNdsDestObject->NdsValue.value_13;
  486. for (i = dwSLBound; i <= (long)dwSUBound; i++) {
  487. VariantInit(&varElement);
  488. hr = SafeArrayGetElement(V_ARRAY(&varOctetList),
  489. (long FAR *)&i,
  490. &varElement
  491. );
  492. BAIL_ON_FAILURE(hr);
  493. hr = VariantToBinary(
  494. &varElement,
  495. &pCurrent->Length,
  496. &pCurrent->Data
  497. );
  498. BAIL_ON_FAILURE(hr);
  499. if (i != (long)dwSUBound) {
  500. pCurrent->Next = (LPNDS_ASN1_TYPE_13)AllocADsMem(sizeof(NDS_ASN1_TYPE_13));
  501. if (!pCurrent->Next) {
  502. hr = E_OUTOFMEMORY;
  503. BAIL_ON_FAILURE(hr);
  504. }
  505. pCurrent = pCurrent->Next;
  506. }
  507. VariantClear(&varElement);
  508. }
  509. pCurrent->Next = NULL;
  510. error:
  511. VariantClear(&varOctetList);
  512. if (pOctetList) {
  513. pOctetList->Release();
  514. }
  515. RRETURN(hr);
  516. }
  517. HRESULT
  518. VarTypeToNdsTypeCopyNDSSynId14(
  519. PVARIANT lpVarSrcObject,
  520. PNDSOBJECT lpNdsDestObject
  521. )
  522. {
  523. HRESULT hr = S_OK;
  524. IADsEmail FAR * pEmail = NULL;
  525. IDispatch FAR * pDispatch = NULL;
  526. long dwAddressType = 0;
  527. BSTR bstrAddress;
  528. if (V_VT(lpVarSrcObject) != VT_DISPATCH){
  529. hr = E_FAIL;
  530. BAIL_ON_FAILURE(hr);
  531. }
  532. pDispatch = V_DISPATCH(lpVarSrcObject);
  533. hr = pDispatch->QueryInterface(
  534. IID_IADsEmail,
  535. (void **)&pEmail
  536. );
  537. BAIL_ON_FAILURE(hr);
  538. lpNdsDestObject->NdsType = NDS_SYNTAX_ID_14;
  539. hr = pEmail->get_Type(
  540. &dwAddressType
  541. );
  542. BAIL_ON_FAILURE(hr);
  543. lpNdsDestObject->NdsValue.value_14.Type = dwAddressType;
  544. hr = pEmail->get_Address(
  545. &bstrAddress
  546. );
  547. BAIL_ON_FAILURE(hr);
  548. lpNdsDestObject->NdsValue.value_14.Address=
  549. AllocADsStr(
  550. bstrAddress
  551. );
  552. if ((!lpNdsDestObject->NdsValue.value_14.Address) &&
  553. (bstrAddress)) {
  554. RRETURN(E_OUTOFMEMORY);
  555. }
  556. error:
  557. if (pEmail) {
  558. pEmail->Release();
  559. }
  560. RRETURN(hr);
  561. }
  562. HRESULT
  563. VarTypeToNdsTypeCopyNDSSynId15(
  564. PVARIANT lpVarSrcObject,
  565. PNDSOBJECT lpNdsDestObject
  566. )
  567. {
  568. HRESULT hr = S_OK;
  569. IADsPath FAR * pPath = NULL;
  570. IDispatch FAR * pDispatch = NULL;
  571. DWORD dwType = 0;
  572. BSTR bstrVolumeName = NULL;
  573. BSTR bstrPath = NULL;
  574. if (V_VT(lpVarSrcObject) != VT_DISPATCH){
  575. hr = E_FAIL;
  576. BAIL_ON_FAILURE(hr);
  577. }
  578. pDispatch = V_DISPATCH(lpVarSrcObject);
  579. hr = pDispatch->QueryInterface(
  580. IID_IADsPath,
  581. (void **)&pPath
  582. );
  583. BAIL_ON_FAILURE(hr);
  584. lpNdsDestObject->NdsType = NDS_SYNTAX_ID_15;
  585. hr = pPath->get_VolumeName(
  586. &bstrVolumeName
  587. );
  588. BAIL_ON_FAILURE(hr);
  589. lpNdsDestObject->NdsValue.value_15.VolumeName=
  590. AllocADsStr(bstrVolumeName);
  591. if ((!lpNdsDestObject->NdsValue.value_15.VolumeName) &&
  592. (bstrVolumeName)) {
  593. RRETURN(E_OUTOFMEMORY);
  594. }
  595. hr = pPath->get_Path(
  596. &bstrPath
  597. );
  598. BAIL_ON_FAILURE(hr);
  599. lpNdsDestObject->NdsValue.value_15.Path=
  600. AllocADsStr(bstrPath);
  601. if ((!lpNdsDestObject->NdsValue.value_15.Path) &&
  602. (bstrPath)) {
  603. RRETURN(E_OUTOFMEMORY);
  604. }
  605. hr = pPath->get_Type((LONG *)&dwType);
  606. BAIL_ON_FAILURE(hr);
  607. lpNdsDestObject->NdsValue.value_15.Type = dwType;
  608. error:
  609. if (pPath) {
  610. pPath->Release();
  611. }
  612. RRETURN(hr);
  613. }
  614. HRESULT
  615. VarTypeToNdsTypeCopyNDSSynId16(
  616. PVARIANT lpVarSrcObject,
  617. PNDSOBJECT lpNdsDestObject
  618. )
  619. {
  620. HRESULT hr = S_OK;
  621. IADsReplicaPointer FAR * pReplicaPointer = NULL;
  622. IDispatch FAR * pDispatch = NULL;
  623. DWORD dwReplicaType = 0;
  624. DWORD dwReplicaNumber = 0;
  625. DWORD dwCount = 0;
  626. BSTR bstrServerName = NULL;
  627. NDSOBJECT object;
  628. VARIANT varAddress;
  629. VariantInit(&varAddress);
  630. if (V_VT(lpVarSrcObject) != VT_DISPATCH){
  631. hr = E_FAIL;
  632. BAIL_ON_FAILURE(hr);
  633. }
  634. pDispatch = V_DISPATCH(lpVarSrcObject);
  635. hr = pDispatch->QueryInterface(
  636. IID_IADsReplicaPointer,
  637. (void **)&pReplicaPointer
  638. );
  639. BAIL_ON_FAILURE(hr);
  640. lpNdsDestObject->NdsType = NDS_SYNTAX_ID_16;
  641. hr = pReplicaPointer->get_ServerName(
  642. &bstrServerName
  643. );
  644. BAIL_ON_FAILURE(hr);
  645. lpNdsDestObject->NdsValue.value_16.ServerName=
  646. AllocADsStr(bstrServerName);
  647. if ((!lpNdsDestObject->NdsValue.value_16.ServerName) &&
  648. (bstrServerName)) {
  649. RRETURN(E_OUTOFMEMORY);
  650. }
  651. hr = pReplicaPointer->get_ReplicaType((LONG *)&dwReplicaType);
  652. BAIL_ON_FAILURE(hr);
  653. lpNdsDestObject->NdsValue.value_16.ReplicaType= dwReplicaType;
  654. hr = pReplicaPointer->get_ReplicaNumber((LONG *)&dwReplicaNumber);
  655. BAIL_ON_FAILURE(hr);
  656. lpNdsDestObject->NdsValue.value_16.ReplicaNumber= dwReplicaNumber;
  657. hr = pReplicaPointer->get_Count((LONG *)&dwCount);
  658. BAIL_ON_FAILURE(hr);
  659. if (dwCount == 0) {
  660. lpNdsDestObject->NdsValue.value_16.Count = 0;
  661. lpNdsDestObject->NdsValue.value_16.ReplicaAddressHints = NULL;
  662. }
  663. else {
  664. //
  665. // We only support the setting of 1 ReplicaAddressHints in the
  666. // ReplicaPointer. Supporting more than 1 requires the support
  667. // of marshalling an array variant which is more complex.
  668. // Judging that there is no real usage of this interface since
  669. // the Replica Pointer is for NDS internal use only. We have
  670. // decided that we'll postpone this to post W2K and will fix it
  671. // only if there is a need.
  672. //
  673. lpNdsDestObject->NdsValue.value_16.Count = 1;
  674. hr = pReplicaPointer->get_ReplicaAddressHints(&varAddress);
  675. BAIL_ON_FAILURE(hr);
  676. hr = VarTypeToNdsTypeCopyNDSSynId12(
  677. &varAddress,
  678. &object
  679. );
  680. BAIL_ON_FAILURE(hr);
  681. lpNdsDestObject->NdsValue.value_16.ReplicaAddressHints =
  682. (LPNDS_ASN1_TYPE_12)AllocADsMem(sizeof(NDS_ASN1_TYPE_12));
  683. if (lpNdsDestObject->NdsValue.value_16.ReplicaAddressHints == NULL) {
  684. hr = E_OUTOFMEMORY;
  685. BAIL_ON_FAILURE(hr);
  686. }
  687. memcpy(lpNdsDestObject->NdsValue.value_16.ReplicaAddressHints,
  688. &object.NdsValue.value_12,
  689. sizeof(NDS_ASN1_TYPE_12));
  690. }
  691. error:
  692. VariantClear(&varAddress);
  693. if (pReplicaPointer) {
  694. pReplicaPointer->Release();
  695. }
  696. RRETURN(hr);
  697. }
  698. HRESULT
  699. VarTypeToNdsTypeCopyNDSSynId17(
  700. PVARIANT lpVarSrcObject,
  701. PNDSOBJECT lpNdsDestObject
  702. )
  703. {
  704. HRESULT hr = S_OK;
  705. IADsAcl FAR * pSecDes = NULL;
  706. IDispatch FAR * pDispatch = NULL;
  707. DWORD dwPrivileges = 0;
  708. BSTR bstrProtectedAttrName = NULL;
  709. BSTR bstrSubjectName = NULL;
  710. if (V_VT(lpVarSrcObject) != VT_DISPATCH){
  711. hr = E_FAIL;
  712. BAIL_ON_FAILURE(hr);
  713. }
  714. pDispatch = V_DISPATCH(lpVarSrcObject);
  715. hr = pDispatch->QueryInterface(
  716. IID_IADsAcl,
  717. (void **)&pSecDes
  718. );
  719. BAIL_ON_FAILURE(hr);
  720. lpNdsDestObject->NdsType = NDS_SYNTAX_ID_17;
  721. hr = pSecDes->get_ProtectedAttrName(
  722. &bstrProtectedAttrName
  723. );
  724. BAIL_ON_FAILURE(hr);
  725. lpNdsDestObject->NdsValue.value_17.ProtectedAttrName =
  726. AllocADsStr(bstrProtectedAttrName);
  727. if ((!lpNdsDestObject->NdsValue.value_17.ProtectedAttrName) &&
  728. (bstrProtectedAttrName)) {
  729. RRETURN(E_OUTOFMEMORY);
  730. }
  731. hr = pSecDes->get_SubjectName(
  732. &bstrSubjectName
  733. );
  734. BAIL_ON_FAILURE(hr);
  735. lpNdsDestObject->NdsValue.value_17.SubjectName=
  736. AllocADsStr(bstrSubjectName);
  737. if ((!lpNdsDestObject->NdsValue.value_17.SubjectName) &&
  738. (bstrSubjectName)) {
  739. RRETURN(E_OUTOFMEMORY);
  740. }
  741. hr = pSecDes->get_Privileges((LONG *)&dwPrivileges);
  742. BAIL_ON_FAILURE(hr);
  743. lpNdsDestObject->NdsValue.value_17.Privileges= dwPrivileges;
  744. error:
  745. if (pSecDes) {
  746. pSecDes->Release();
  747. }
  748. RRETURN(hr);
  749. }
  750. HRESULT
  751. VarTypeToNdsTypeCopyNDSSynId18(
  752. PVARIANT lpVarSrcObject,
  753. PNDSOBJECT lpNdsDestObject
  754. )
  755. {
  756. HRESULT hr = S_OK;
  757. DWORD dwSLBound = 0;
  758. DWORD dwSUBound = 0;
  759. long i;
  760. IADsPostalAddress FAR * pPostalAddress = NULL;
  761. IDispatch FAR * pDispatch = NULL;
  762. VARIANT varPostalAddress;
  763. VARIANT varElement;
  764. BSTR bstrElement;
  765. VariantInit(&varPostalAddress);
  766. if (V_VT(lpVarSrcObject) != VT_DISPATCH){
  767. hr = E_FAIL;
  768. BAIL_ON_FAILURE(hr);
  769. }
  770. pDispatch = V_DISPATCH(lpVarSrcObject);
  771. hr = pDispatch->QueryInterface(
  772. IID_IADsPostalAddress,
  773. (void **)&pPostalAddress
  774. );
  775. BAIL_ON_FAILURE(hr);
  776. hr = pPostalAddress->get_PostalAddress(
  777. &varPostalAddress
  778. );
  779. BAIL_ON_FAILURE(hr);
  780. if(!((V_VT(&varPostalAddress) & VT_VARIANT) && V_ISARRAY(&varPostalAddress))) {
  781. return(E_FAIL);
  782. }
  783. lpNdsDestObject->NdsType = NDS_SYNTAX_ID_18;
  784. if ((V_ARRAY(&varPostalAddress))->cDims != 1) {
  785. hr = E_FAIL;
  786. BAIL_ON_FAILURE(hr);
  787. }
  788. if ( ((V_ARRAY(&varPostalAddress))->rgsabound[0].cElements <= 0) ||
  789. ((V_ARRAY(&varPostalAddress))->rgsabound[0].cElements >6) ) {
  790. hr = E_FAIL;
  791. BAIL_ON_FAILURE(hr);
  792. }
  793. hr = SafeArrayGetLBound(V_ARRAY(&varPostalAddress),
  794. 1,
  795. (long FAR *)&dwSLBound
  796. );
  797. BAIL_ON_FAILURE(hr);
  798. hr = SafeArrayGetUBound(V_ARRAY(&varPostalAddress),
  799. 1,
  800. (long FAR *)&dwSUBound
  801. );
  802. BAIL_ON_FAILURE(hr);
  803. for (i = dwSLBound; i <= (long)dwSUBound; i++) {
  804. VariantInit(&varElement);
  805. hr = SafeArrayGetElement(V_ARRAY(&varPostalAddress),
  806. (long FAR *)&i,
  807. &varElement
  808. );
  809. BAIL_ON_FAILURE(hr);
  810. lpNdsDestObject->NdsValue.value_18.PostalAddress[i-dwSLBound] =
  811. AllocADsStr(V_BSTR(&varElement));
  812. if ((!lpNdsDestObject->NdsValue.value_18.PostalAddress[i-dwSLBound]) &&
  813. (V_BSTR(&varElement))) {
  814. RRETURN(E_OUTOFMEMORY);
  815. }
  816. VariantClear(&varElement);
  817. }
  818. error:
  819. VariantClear(&varPostalAddress);
  820. if (pPostalAddress) {
  821. pPostalAddress->Release();
  822. }
  823. RRETURN(hr);
  824. }
  825. HRESULT
  826. VarTypeToNdsTypeCopyNDSSynId19(
  827. PVARIANT lpVarSrcObject,
  828. PNDSOBJECT lpNdsDestObject
  829. )
  830. {
  831. HRESULT hr = S_OK;
  832. IADsTimestamp FAR * pTime = NULL;
  833. IDispatch FAR * pDispatch = NULL;
  834. long dwEventID = 0;
  835. long dwWholeSeconds = 0;
  836. if (V_VT(lpVarSrcObject) != VT_DISPATCH){
  837. hr = E_FAIL;
  838. BAIL_ON_FAILURE(hr);
  839. }
  840. pDispatch = V_DISPATCH(lpVarSrcObject);
  841. hr = pDispatch->QueryInterface(
  842. IID_IADsTimestamp,
  843. (void **)&pTime
  844. );
  845. BAIL_ON_FAILURE(hr);
  846. lpNdsDestObject->NdsType = NDS_SYNTAX_ID_19;
  847. hr = pTime->get_WholeSeconds(
  848. &dwWholeSeconds
  849. );
  850. BAIL_ON_FAILURE(hr);
  851. lpNdsDestObject->NdsValue.value_19.WholeSeconds= dwWholeSeconds;
  852. BAIL_ON_FAILURE(hr);
  853. hr = pTime->get_EventID(
  854. &dwEventID
  855. );
  856. BAIL_ON_FAILURE(hr);
  857. lpNdsDestObject->NdsValue.value_19.EventID = dwEventID;
  858. BAIL_ON_FAILURE(hr);
  859. error:
  860. if (pTime) {
  861. pTime->Release();
  862. }
  863. RRETURN(hr);
  864. }
  865. HRESULT
  866. VarTypeToNdsTypeCopyNDSSynId20(
  867. PVARIANT lpVarSrcObject,
  868. PNDSOBJECT lpNdsDestObject
  869. )
  870. {
  871. HRESULT hr = S_OK;
  872. if(lpVarSrcObject->vt != VT_BSTR){
  873. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  874. }
  875. lpNdsDestObject->NdsType = NDS_SYNTAX_ID_20;
  876. lpNdsDestObject->NdsValue.value_20.ClassName =
  877. AllocADsStr(
  878. lpVarSrcObject->bstrVal
  879. );
  880. if ((!lpNdsDestObject->NdsValue.value_20.ClassName) &&
  881. (lpVarSrcObject->bstrVal)) {
  882. RRETURN(E_OUTOFMEMORY);
  883. }
  884. RRETURN(hr);
  885. }
  886. HRESULT
  887. VarTypeToNdsTypeCopyNDSSynId21(
  888. PVARIANT lpVarSrcObject,
  889. PNDSOBJECT lpNdsDestObject
  890. )
  891. {
  892. HRESULT hr;
  893. lpNdsDestObject->NdsType = NDS_SYNTAX_ID_21;
  894. hr = VariantToBinary(
  895. lpVarSrcObject,
  896. &lpNdsDestObject->NdsValue.value_21.Length,
  897. &lpNdsDestObject->NdsValue.value_21.Data
  898. );
  899. RRETURN(hr);
  900. }
  901. HRESULT
  902. VarTypeToNdsTypeCopyNDSSynId22(
  903. PVARIANT lpVarSrcObject,
  904. PNDSOBJECT lpNdsDestObject
  905. )
  906. {
  907. HRESULT hr = S_OK;
  908. if(lpVarSrcObject->vt != VT_I4){
  909. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  910. }
  911. lpNdsDestObject->NdsType = NDS_SYNTAX_ID_22;
  912. lpNdsDestObject->NdsValue.value_22.Counter =
  913. lpVarSrcObject->lVal;
  914. RRETURN(hr);
  915. }
  916. HRESULT
  917. VarTypeToNdsTypeCopyNDSSynId23(
  918. PVARIANT lpVarSrcObject,
  919. PNDSOBJECT lpNdsDestObject
  920. )
  921. {
  922. HRESULT hr = S_OK;
  923. IADsBackLink FAR * pBackLink = NULL;
  924. IDispatch FAR * pDispatch = NULL;
  925. long dwRemoteID = 0;
  926. BSTR bstrObjectName = NULL;
  927. if (V_VT(lpVarSrcObject) != VT_DISPATCH){
  928. hr = E_FAIL;
  929. BAIL_ON_FAILURE(hr);
  930. }
  931. pDispatch = V_DISPATCH(lpVarSrcObject);
  932. hr = pDispatch->QueryInterface(
  933. IID_IADsBackLink,
  934. (void **)&pBackLink
  935. );
  936. BAIL_ON_FAILURE(hr);
  937. lpNdsDestObject->NdsType = NDS_SYNTAX_ID_23;
  938. hr = pBackLink->get_ObjectName(
  939. &bstrObjectName
  940. );
  941. BAIL_ON_FAILURE(hr);
  942. lpNdsDestObject->NdsValue.value_23.ObjectName=
  943. AllocADsStr(bstrObjectName);
  944. if ((!lpNdsDestObject->NdsValue.value_23.ObjectName) &&
  945. (bstrObjectName)) {
  946. RRETURN(E_OUTOFMEMORY);
  947. }
  948. hr = pBackLink->get_RemoteID((LONG *)&dwRemoteID);
  949. BAIL_ON_FAILURE(hr);
  950. lpNdsDestObject->NdsValue.value_23.RemoteID = dwRemoteID;
  951. error:
  952. if (pBackLink) {
  953. pBackLink->Release();
  954. }
  955. RRETURN(hr);
  956. }
  957. HRESULT
  958. VarTypeToNdsTypeCopyNDSSynId24(
  959. PVARIANT lpVarSrcObject,
  960. PNDSOBJECT lpNdsDestObject
  961. )
  962. {
  963. HRESULT hr = S_OK;
  964. if(lpVarSrcObject->vt != VT_DATE){
  965. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  966. }
  967. lpNdsDestObject->NdsType = NDS_SYNTAX_ID_24;
  968. hr = ConvertDATEtoDWORD(
  969. lpVarSrcObject->date,
  970. &(lpNdsDestObject->NdsValue.value_24.Time),
  971. TRUE
  972. );
  973. RRETURN(hr);
  974. }
  975. HRESULT
  976. VarTypeToNdsTypeCopyNDSSynId25(
  977. PVARIANT lpVarSrcObject,
  978. PNDSOBJECT lpNdsDestObject
  979. )
  980. {
  981. HRESULT hr = S_OK;
  982. IADsTypedName FAR * pTypedName = NULL;
  983. IDispatch FAR * pDispatch = NULL;
  984. DWORD dwLevel = 0;
  985. DWORD dwInterval = 0;
  986. BSTR bstrObjectName = NULL;
  987. if (V_VT(lpVarSrcObject) != VT_DISPATCH){
  988. hr = E_FAIL;
  989. BAIL_ON_FAILURE(hr);
  990. }
  991. pDispatch = V_DISPATCH(lpVarSrcObject);
  992. hr = pDispatch->QueryInterface(
  993. IID_IADsTypedName,
  994. (void **)&pTypedName
  995. );
  996. BAIL_ON_FAILURE(hr);
  997. lpNdsDestObject->NdsType = NDS_SYNTAX_ID_25;
  998. hr = pTypedName->get_ObjectName(
  999. &bstrObjectName
  1000. );
  1001. BAIL_ON_FAILURE(hr);
  1002. lpNdsDestObject->NdsValue.value_25.ObjectName=
  1003. AllocADsStr(bstrObjectName);
  1004. if ((!lpNdsDestObject->NdsValue.value_25.ObjectName) &&
  1005. (bstrObjectName)) {
  1006. RRETURN(E_OUTOFMEMORY);
  1007. }
  1008. hr = pTypedName->get_Level((LONG *)&dwLevel);
  1009. BAIL_ON_FAILURE(hr);
  1010. lpNdsDestObject->NdsValue.value_25.Level = dwLevel;
  1011. hr = pTypedName->get_Interval((LONG *)&dwInterval);
  1012. BAIL_ON_FAILURE(hr);
  1013. lpNdsDestObject->NdsValue.value_25.Interval= dwInterval;
  1014. error:
  1015. if (pTypedName) {
  1016. pTypedName->Release();
  1017. }
  1018. RRETURN(hr);
  1019. }
  1020. HRESULT
  1021. VarTypeToNdsTypeCopyNDSSynId26(
  1022. PVARIANT lpVarSrcObject,
  1023. PNDSOBJECT lpNdsDestObject
  1024. )
  1025. {
  1026. HRESULT hr = S_OK;
  1027. IADsHold FAR * pHold = NULL;
  1028. IDispatch FAR * pDispatch = NULL;
  1029. DWORD dwAmount = 0;
  1030. BSTR bstrObjectName = NULL;
  1031. if (V_VT(lpVarSrcObject) != VT_DISPATCH){
  1032. hr = E_FAIL;
  1033. BAIL_ON_FAILURE(hr);
  1034. }
  1035. pDispatch = V_DISPATCH(lpVarSrcObject);
  1036. hr = pDispatch->QueryInterface(
  1037. IID_IADsHold,
  1038. (void **)&pHold
  1039. );
  1040. BAIL_ON_FAILURE(hr);
  1041. lpNdsDestObject->NdsType = NDS_SYNTAX_ID_26;
  1042. hr = pHold->get_ObjectName(
  1043. &bstrObjectName
  1044. );
  1045. BAIL_ON_FAILURE(hr);
  1046. lpNdsDestObject->NdsValue.value_26.ObjectName=
  1047. AllocADsStr(bstrObjectName);
  1048. if ((!lpNdsDestObject->NdsValue.value_26.ObjectName) &&
  1049. (bstrObjectName)) {
  1050. RRETURN(E_OUTOFMEMORY);
  1051. }
  1052. hr = pHold->get_Amount((LONG *)&dwAmount);
  1053. BAIL_ON_FAILURE(hr);
  1054. lpNdsDestObject->NdsValue.value_26.Amount = dwAmount;
  1055. error:
  1056. if (pHold) {
  1057. pHold->Release();
  1058. }
  1059. RRETURN(hr);
  1060. }
  1061. HRESULT
  1062. VarTypeToNdsTypeCopyNDSSynId27(
  1063. PVARIANT lpVarSrcObject,
  1064. PNDSOBJECT lpNdsDestObject
  1065. )
  1066. {
  1067. HRESULT hr = S_OK;
  1068. if(lpVarSrcObject->vt != VT_I4){
  1069. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  1070. }
  1071. lpNdsDestObject->NdsType = NDS_SYNTAX_ID_27;
  1072. lpNdsDestObject->NdsValue.value_27.Interval =
  1073. lpVarSrcObject->lVal;
  1074. RRETURN(hr);
  1075. }
  1076. HRESULT
  1077. VarTypeToNdsTypeCopy(
  1078. DWORD dwNdsType,
  1079. PVARIANT lpVarSrcObject,
  1080. PNDSOBJECT lpNdsDestObject
  1081. )
  1082. {
  1083. HRESULT hr = S_OK;
  1084. switch (dwNdsType){
  1085. case 1:
  1086. hr = VarTypeToNdsTypeCopyNDSSynId1(
  1087. lpVarSrcObject,
  1088. lpNdsDestObject
  1089. );
  1090. break;
  1091. case 2:
  1092. hr = VarTypeToNdsTypeCopyNDSSynId2(
  1093. lpVarSrcObject,
  1094. lpNdsDestObject
  1095. );
  1096. break;
  1097. case 3:
  1098. hr = VarTypeToNdsTypeCopyNDSSynId3(
  1099. lpVarSrcObject,
  1100. lpNdsDestObject
  1101. );
  1102. break;
  1103. case 4:
  1104. hr = VarTypeToNdsTypeCopyNDSSynId4(
  1105. lpVarSrcObject,
  1106. lpNdsDestObject
  1107. );
  1108. break;
  1109. case 5:
  1110. hr = VarTypeToNdsTypeCopyNDSSynId5(
  1111. lpVarSrcObject,
  1112. lpNdsDestObject
  1113. );
  1114. break;
  1115. case 6:
  1116. hr = VarTypeToNdsTypeCopyNDSSynId6(
  1117. lpVarSrcObject,
  1118. lpNdsDestObject
  1119. );
  1120. break;
  1121. case 7:
  1122. hr = VarTypeToNdsTypeCopyNDSSynId7(
  1123. lpVarSrcObject,
  1124. lpNdsDestObject
  1125. );
  1126. break;
  1127. case 8:
  1128. hr = VarTypeToNdsTypeCopyNDSSynId8(
  1129. lpVarSrcObject,
  1130. lpNdsDestObject
  1131. );
  1132. break;
  1133. case 9:
  1134. hr = VarTypeToNdsTypeCopyNDSSynId9(
  1135. lpVarSrcObject,
  1136. lpNdsDestObject
  1137. );
  1138. break;
  1139. case 10:
  1140. hr = VarTypeToNdsTypeCopyNDSSynId10(
  1141. lpVarSrcObject,
  1142. lpNdsDestObject
  1143. );
  1144. break;
  1145. case 11:
  1146. hr = VarTypeToNdsTypeCopyNDSSynId11(
  1147. lpVarSrcObject,
  1148. lpNdsDestObject
  1149. );
  1150. break;
  1151. case 12:
  1152. hr = VarTypeToNdsTypeCopyNDSSynId12(
  1153. lpVarSrcObject,
  1154. lpNdsDestObject
  1155. );
  1156. break;
  1157. case 13:
  1158. hr = VarTypeToNdsTypeCopyNDSSynId13(
  1159. lpVarSrcObject,
  1160. lpNdsDestObject
  1161. );
  1162. break;
  1163. case 14:
  1164. hr = VarTypeToNdsTypeCopyNDSSynId14(
  1165. lpVarSrcObject,
  1166. lpNdsDestObject
  1167. );
  1168. break;
  1169. case 15:
  1170. hr = VarTypeToNdsTypeCopyNDSSynId15(
  1171. lpVarSrcObject,
  1172. lpNdsDestObject
  1173. );
  1174. break;
  1175. case 16:
  1176. hr = VarTypeToNdsTypeCopyNDSSynId16(
  1177. lpVarSrcObject,
  1178. lpNdsDestObject
  1179. );
  1180. break;
  1181. case 17:
  1182. hr = VarTypeToNdsTypeCopyNDSSynId17(
  1183. lpVarSrcObject,
  1184. lpNdsDestObject
  1185. );
  1186. break;
  1187. case 18:
  1188. hr = VarTypeToNdsTypeCopyNDSSynId18(
  1189. lpVarSrcObject,
  1190. lpNdsDestObject
  1191. );
  1192. break;
  1193. case 19:
  1194. hr = VarTypeToNdsTypeCopyNDSSynId19(
  1195. lpVarSrcObject,
  1196. lpNdsDestObject
  1197. );
  1198. break;
  1199. case 20:
  1200. hr = VarTypeToNdsTypeCopyNDSSynId20(
  1201. lpVarSrcObject,
  1202. lpNdsDestObject
  1203. );
  1204. break;
  1205. case 21:
  1206. hr = VarTypeToNdsTypeCopyNDSSynId21(
  1207. lpVarSrcObject,
  1208. lpNdsDestObject
  1209. );
  1210. break;
  1211. case 22:
  1212. hr = VarTypeToNdsTypeCopyNDSSynId22(
  1213. lpVarSrcObject,
  1214. lpNdsDestObject
  1215. );
  1216. break;
  1217. case 23:
  1218. hr = VarTypeToNdsTypeCopyNDSSynId23(
  1219. lpVarSrcObject,
  1220. lpNdsDestObject
  1221. );
  1222. break;
  1223. case 24:
  1224. hr = VarTypeToNdsTypeCopyNDSSynId24(
  1225. lpVarSrcObject,
  1226. lpNdsDestObject
  1227. );
  1228. break;
  1229. case 25:
  1230. hr = VarTypeToNdsTypeCopyNDSSynId25(
  1231. lpVarSrcObject,
  1232. lpNdsDestObject
  1233. );
  1234. break;
  1235. case 26:
  1236. hr = VarTypeToNdsTypeCopyNDSSynId26(
  1237. lpVarSrcObject,
  1238. lpNdsDestObject
  1239. );
  1240. break;
  1241. case 27:
  1242. hr = VarTypeToNdsTypeCopyNDSSynId27(
  1243. lpVarSrcObject,
  1244. lpNdsDestObject
  1245. );
  1246. break;
  1247. default:
  1248. hr = E_FAIL;
  1249. break;
  1250. }
  1251. RRETURN(hr);
  1252. }
  1253. HRESULT
  1254. VarTypeToNdsTypeCopyConstruct(
  1255. DWORD dwNdsType,
  1256. LPVARIANT pVarSrcObjects,
  1257. DWORD *pdwNumObjects,
  1258. LPNDSOBJECT * ppNdsDestObjects
  1259. )
  1260. {
  1261. DWORD i = 0;
  1262. LPNDSOBJECT pNdsDestObjects = NULL;
  1263. HRESULT hr = S_OK;
  1264. VARIANT varNDSAcl;
  1265. IDispatch * pDispatch = NULL;
  1266. IADsSecurityDescriptor * pSecDes = NULL;
  1267. DWORD dwNumObjects = *pdwNumObjects;
  1268. //
  1269. // If it is a security descriptor, do special conversion
  1270. //
  1271. if (dwNdsType == 17) {
  1272. //
  1273. // Bail out if it contains more than 1 object
  1274. //
  1275. if (dwNumObjects != 1) {
  1276. hr = E_FAIL;
  1277. BAIL_ON_FAILURE(hr);
  1278. }
  1279. if (V_VT(pVarSrcObjects) != VT_DISPATCH){
  1280. hr = E_FAIL;
  1281. BAIL_ON_FAILURE(hr);
  1282. }
  1283. pDispatch = V_DISPATCH(pVarSrcObjects);
  1284. hr = pDispatch->QueryInterface(
  1285. IID_IADsSecurityDescriptor,
  1286. (void **)&pSecDes
  1287. );
  1288. BAIL_ON_FAILURE(hr);
  1289. hr = ConvertSecDesToNDSAclVarArray(
  1290. pSecDes,
  1291. &varNDSAcl
  1292. );
  1293. BAIL_ON_FAILURE(hr);
  1294. hr = ConvertSafeArrayToVariantArray(
  1295. varNDSAcl,
  1296. &pVarSrcObjects,
  1297. &dwNumObjects
  1298. );
  1299. BAIL_ON_FAILURE(hr);
  1300. pNdsDestObjects = (LPNDSOBJECT)AllocADsMem(
  1301. dwNumObjects * sizeof(NDSOBJECT)
  1302. );
  1303. if (!pNdsDestObjects) {
  1304. RRETURN(E_FAIL);
  1305. }
  1306. *pdwNumObjects = dwNumObjects;
  1307. }
  1308. else {
  1309. pNdsDestObjects = (LPNDSOBJECT)AllocADsMem(
  1310. dwNumObjects * sizeof(NDSOBJECT)
  1311. );
  1312. if (!pNdsDestObjects) {
  1313. RRETURN(E_FAIL);
  1314. }
  1315. }
  1316. for (i = 0; i < dwNumObjects; i++ ) {
  1317. hr = VarTypeToNdsTypeCopy(
  1318. dwNdsType,
  1319. pVarSrcObjects + i,
  1320. pNdsDestObjects + i
  1321. );
  1322. BAIL_ON_FAILURE(hr);
  1323. }
  1324. *ppNdsDestObjects = pNdsDestObjects;
  1325. if (pSecDes) {
  1326. pSecDes->Release();
  1327. }
  1328. RRETURN(S_OK);
  1329. error:
  1330. if (pNdsDestObjects) {
  1331. NdsTypeFreeNdsObjects(
  1332. pNdsDestObjects,
  1333. dwNumObjects
  1334. );
  1335. }
  1336. if (pSecDes) {
  1337. pSecDes->Release();
  1338. }
  1339. *ppNdsDestObjects = NULL;
  1340. RRETURN(hr);
  1341. }