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.

4612 lines
114 KiB

  1. #include "stdafx.h"
  2. //#include "inds.h"
  3. #include <limits.h>
  4. #include "ole2.h"
  5. #include "csyntax.h"
  6. #define NDS_SEPARATOR _T('&')
  7. #define NDS_SEPARATOR_S _T(" & ")
  8. #define NDS_SEPARATOR_W L'&'
  9. #define NDS_SEPARATOR_A '&'
  10. /***********************************************************
  11. Function: GetSyntaxHandler
  12. Arguments:
  13. Return:
  14. Purpose:
  15. Author(s):
  16. Revision:
  17. Date:
  18. ***********************************************************/
  19. COleDsSyntax* GetSyntaxHandler( WCHAR* pszSyntax )
  20. {
  21. ADSTYPE eType;
  22. CString strText;
  23. eType = ADsTypeFromSyntaxString( pszSyntax );
  24. return GetSyntaxHandler( eType, strText );
  25. }
  26. /***********************************************************
  27. Function: GetSyntaxHandler
  28. Arguments:
  29. Return:
  30. Purpose:
  31. Author(s):
  32. Revision:
  33. Date:
  34. ***********************************************************/
  35. COleDsSyntax* GetSyntaxHandler( ADSTYPE eType, CString& rText )
  36. {
  37. COleDsSyntax* pSyntax = NULL;
  38. switch( eType )
  39. {
  40. case ADSTYPE_INVALID:
  41. ASSERT( FALSE );
  42. rText = _T("ERROR: ADSTYPE_INVALID");
  43. break;
  44. case ADSTYPE_DN_STRING:
  45. case ADSTYPE_CASE_EXACT_STRING:
  46. case ADSTYPE_CASE_IGNORE_STRING:
  47. case ADSTYPE_PRINTABLE_STRING:
  48. case ADSTYPE_NUMERIC_STRING:
  49. case ADSTYPE_OBJECT_CLASS:
  50. pSyntax = new COleDsBSTR( );
  51. break;
  52. case ADSTYPE_BOOLEAN:
  53. pSyntax = new COleDsBOOL( );
  54. break;
  55. case ADSTYPE_CASEIGNORE_LIST:
  56. pSyntax = new COleDsNDSCaseIgnoreList( );
  57. break;
  58. case ADSTYPE_OCTET_LIST:
  59. pSyntax = new COleDsNDSOctetList( );
  60. break;
  61. case ADSTYPE_PATH:
  62. pSyntax = new COleDsNDSPath( );
  63. break;
  64. case ADSTYPE_NETADDRESS:
  65. pSyntax = new COleDsNDSNetAddress( );
  66. break;
  67. case ADSTYPE_BACKLINK:
  68. pSyntax = new COleDsNDSBackLink( );
  69. break;
  70. case ADSTYPE_HOLD:
  71. pSyntax = new COleDsNDSHold( );
  72. break;
  73. case ADSTYPE_TYPEDNAME:
  74. pSyntax = new COleDsNDSTypedName( );
  75. break;
  76. case ADSTYPE_INTEGER:
  77. pSyntax = new COleDsLONG( );
  78. break;
  79. case ADSTYPE_LARGE_INTEGER:
  80. pSyntax = new COleDsLargeInteger( );
  81. break;
  82. case ADSTYPE_POSTALADDRESS:
  83. pSyntax = new COleDsNDSPostalAddress( );
  84. break;
  85. case ADSTYPE_OCTET_STRING:
  86. pSyntax = new COleDsOctetString( );
  87. break;
  88. case ADSTYPE_UTC_TIME:
  89. pSyntax = new COleDsDATE( );
  90. break;
  91. case ADSTYPE_TIMESTAMP:
  92. pSyntax = new COleDsNDSTimeStamp;
  93. break;
  94. case ADSTYPE_EMAIL:
  95. pSyntax = new COleDsNDSEMail;
  96. break;
  97. case ADSTYPE_FAXNUMBER:
  98. pSyntax = new COleDsNDSFaxNumber;
  99. break;
  100. case ADSTYPE_PROV_SPECIFIC:
  101. ASSERT( FALSE );
  102. rText = _T("ADSTYPE_PROV_SPECIFIC");
  103. break;
  104. default:
  105. ASSERT( FALSE );
  106. rText = _T("ERROR Unknown ADSTYPE");
  107. break;
  108. }
  109. return pSyntax;
  110. }
  111. /***********************************************************
  112. Function:
  113. Arguments:
  114. Return:
  115. Purpose:
  116. Author(s):
  117. Revision:
  118. Date:
  119. ***********************************************************/
  120. COleDsSyntax::COleDsSyntax( )
  121. {
  122. m_lType = VT_BSTR;
  123. m_dwSyntaxID = ADSTYPE_DN_STRING;
  124. }
  125. /***********************************************************
  126. Function:
  127. Arguments:
  128. Return:
  129. Purpose:
  130. Author(s):
  131. Revision:
  132. Date:
  133. ***********************************************************/
  134. CString COleDsSyntax::VarToDisplayStringEx( VARIANT& var, BOOL bMultiValued )
  135. {
  136. VARIANT aVar;
  137. HRESULT hResult;
  138. CString strText = _T("ERROR");
  139. VariantInit( &aVar );
  140. if( !bMultiValued )
  141. {
  142. SAFEARRAY* pSafeArray;
  143. TCHAR szText[ 8096 ];
  144. VARIANT varString;
  145. long lBound, uBound, lItem;
  146. CString strResult;
  147. ASSERT( VT_ARRAY & V_VT(&var ) );
  148. if( !(VT_ARRAY & V_VT(&var) ) )
  149. {
  150. ERROR_HERE( szText );
  151. }
  152. else
  153. {
  154. VariantInit( &varString );
  155. pSafeArray = V_ARRAY( &var );
  156. hResult = SafeArrayGetLBound(pSafeArray, 1, &lBound);
  157. hResult = SafeArrayGetUBound(pSafeArray, 1, &uBound);
  158. ASSERT( lBound == uBound );
  159. szText[ 0 ] = _T('\0');
  160. lItem = lBound;
  161. hResult = SafeArrayGetElement( pSafeArray, &lItem, &aVar );
  162. if( FAILED( hResult ) )
  163. {
  164. ASSERT(FALSE);
  165. }
  166. if( !ConvertFromPropertyValue( aVar, szText ) )
  167. {
  168. hResult = VariantChangeType( &varString, &aVar, VARIANT_NOVALUEPROP, VT_BSTR );
  169. ASSERT( SUCCEEDED( hResult ) );
  170. if( FAILED( hResult ) )
  171. {
  172. ERROR_HERE( szText );
  173. }
  174. else
  175. {
  176. Convert( szText, V_BSTR( &varString ) );
  177. VariantClear( &varString );
  178. }
  179. VariantClear( &aVar );
  180. }
  181. }
  182. return CString( szText );
  183. }
  184. else
  185. {
  186. strText = FromVariantArrayToString( var );
  187. }
  188. return strText;
  189. }
  190. /***********************************************************
  191. Function:
  192. Arguments:
  193. Return:
  194. Purpose:
  195. Author(s):
  196. Revision:
  197. Date:
  198. ***********************************************************/
  199. CString COleDsSyntax::VarToDisplayString( VARIANT& var, BOOL bMultiValued, BOOL bUseGetEx )
  200. {
  201. VARIANT aVar;
  202. HRESULT hResult;
  203. CString strText;
  204. // we have to use GetEx style
  205. if( bUseGetEx )
  206. return VarToDisplayStringEx( var, bMultiValued );
  207. // we're using Get
  208. VariantInit( &aVar );
  209. if( !bMultiValued )
  210. {
  211. hResult = VariantChangeType( &aVar, &var, VARIANT_NOVALUEPROP, VT_BSTR );
  212. if( SUCCEEDED( hResult ) )
  213. {
  214. strText = V_BSTR( &aVar );
  215. }
  216. else
  217. {
  218. strText = _T("ERROR on conversion");
  219. }
  220. hResult = VariantClear( &aVar );
  221. }
  222. else
  223. {
  224. strText = FromVariantArrayToString( var );
  225. }
  226. return strText;
  227. }
  228. /***********************************************************
  229. Function: COleDsSyntax::DisplayStringToDispParamsEx
  230. Arguments:
  231. Return:
  232. Purpose:
  233. Author(s):
  234. Revision:
  235. Date:
  236. ***********************************************************/
  237. BOOL COleDsSyntax::DisplayStringToDispParamsEx( CString& rText,
  238. DISPPARAMS& dispParams,
  239. BOOL bMultiValued )
  240. {
  241. HRESULT hResult;
  242. dispParams.rgdispidNamedArgs[ 0 ] = DISPID_PROPERTYPUT;
  243. dispParams.cArgs = 1;
  244. dispParams.cNamedArgs = 1;
  245. hResult = BuildVariantArray( m_lType, rText, dispParams.rgvarg[0] );
  246. return SUCCEEDED( hResult );
  247. }
  248. /***********************************************************
  249. Function:
  250. Arguments:
  251. Return:
  252. Purpose:
  253. Author(s):
  254. Revision:
  255. Date:
  256. ***********************************************************/
  257. BOOL COleDsSyntax::DisplayStringToDispParams( CString& rText, DISPPARAMS& dispParams,
  258. BOOL bMultiValued, BOOL bUseGetEx )
  259. {
  260. HRESULT hResult;
  261. if( bUseGetEx )
  262. {
  263. return DisplayStringToDispParamsEx( rText, dispParams, bMultiValued );
  264. }
  265. dispParams.rgdispidNamedArgs[ 0 ] = DISPID_PROPERTYPUT;
  266. dispParams.cArgs = 1;
  267. dispParams.cNamedArgs = 1;
  268. if( bMultiValued )
  269. {
  270. hResult = BuildVariantArray( m_lType, rText, dispParams.rgvarg[0] );
  271. }
  272. else
  273. {
  274. VARIANT vStr;
  275. VariantInit( &vStr );
  276. VariantInit( &dispParams.rgvarg[0] );
  277. V_VT( &vStr ) = VT_BSTR;
  278. V_BSTR( &vStr ) = AllocBSTR( rText.GetBuffer( 1024 ) );
  279. hResult = VariantChangeType( &dispParams.rgvarg[0], &vStr, VARIANT_NOVALUEPROP, m_lType );
  280. VariantClear( &vStr );
  281. }
  282. return SUCCEEDED( hResult );
  283. }
  284. /***********************************************************
  285. Function:
  286. Arguments:
  287. Return:
  288. Purpose:
  289. Author(s):
  290. Revision:
  291. Date:
  292. ***********************************************************/
  293. HRESULT COleDsSyntax::Native2Value( ADSVALUE* pADsObject, CString& rVal )
  294. {
  295. ASSERT( FALSE );
  296. return E_FAIL;
  297. }
  298. /***********************************************************
  299. Function:
  300. Arguments:
  301. Return:
  302. Purpose:
  303. Author(s):
  304. Revision:
  305. Date:
  306. ***********************************************************/
  307. HRESULT COleDsSyntax::Value2Native( ADSVALUE* pADsObject, CString& rVal )
  308. {
  309. ASSERT( FALSE );
  310. return E_FAIL;
  311. }
  312. /***********************************************************
  313. Function:
  314. Arguments:
  315. Return:
  316. Purpose:
  317. Author(s):
  318. Revision:
  319. Date:
  320. ***********************************************************/
  321. void COleDsSyntax::FreeAttrValue ( ADSVALUE* pADsValue )
  322. {
  323. return;
  324. }
  325. /***********************************************************
  326. Function:
  327. Arguments:
  328. Return:
  329. Purpose:
  330. Author(s):
  331. Revision:
  332. Date:
  333. ***********************************************************/
  334. void COleDsSyntax::FreeAttrInfo( ADS_ATTR_INFO* pAttrInfo )
  335. {
  336. DWORD dwIter;
  337. ASSERT( NULL != pAttrInfo->pszAttrName );
  338. FREE_MEMORY( pAttrInfo->pszAttrName );
  339. if( ADS_ATTR_CLEAR == pAttrInfo->dwControlCode )
  340. return;
  341. for( dwIter = 0;
  342. NULL != pAttrInfo->pADsValues && dwIter < pAttrInfo->dwNumValues ;
  343. dwIter++ )
  344. {
  345. FreeAttrValue( pAttrInfo->pADsValues + dwIter );
  346. }
  347. FREE_MEMORY( pAttrInfo->pADsValues );
  348. }
  349. /***********************************************************
  350. Function:
  351. Arguments:
  352. Return:
  353. Purpose:
  354. Author(s):
  355. Revision:
  356. Date:
  357. ***********************************************************/
  358. HRESULT COleDsSyntax::Native2Value( ADS_ATTR_INFO* pAttr, CString& rVal )
  359. {
  360. HRESULT hResult = E_FAIL;
  361. CString strItem;
  362. ADSVALUE* pAdsValue;
  363. rVal.Empty( );
  364. while( TRUE )
  365. {
  366. ASSERT( pAttr );
  367. if( !pAttr )
  368. break;
  369. ASSERT( pAttr->pADsValues );
  370. if( !pAttr->pADsValues )
  371. break;
  372. for( DWORD dwIdx = 0L; dwIdx < pAttr->dwNumValues ; dwIdx++ )
  373. {
  374. if( dwIdx )
  375. rVal = rVal + SEPARATOR_S;
  376. pAdsValue = pAttr->pADsValues + dwIdx;
  377. if( ADSTYPE_INVALID != pAdsValue->dwType )
  378. {
  379. hResult = Native2Value( pAdsValue, strItem );
  380. }
  381. else
  382. {
  383. strItem = _T("ERROR: ADSTYPE_INVALID");
  384. TRACE( _T("ERROR: Got ADSTYPE_INVALID!!!\n") );
  385. }
  386. rVal = rVal + strItem;
  387. }
  388. break;
  389. }
  390. return hResult;
  391. }
  392. /***********************************************************
  393. Function:
  394. Arguments:
  395. Return:
  396. Purpose:
  397. Author(s):
  398. Revision:
  399. Date:
  400. ***********************************************************/
  401. HRESULT COleDsSyntax::Value2Native( ADS_ATTR_INFO* pAttr, CString& rVal )
  402. {
  403. HRESULT hResult = E_FAIL;
  404. CString strItem;
  405. ADSVALUE* pCurrentADsObject;
  406. DWORD dwValues;
  407. DWORD dwIdx;
  408. pAttr->dwADsType = (ADSTYPE)m_dwSyntaxID;
  409. while( TRUE )
  410. {
  411. ASSERT( pAttr );
  412. if( !pAttr )
  413. break;
  414. dwValues = GetValuesCount( rVal, SEPARATOR_C );
  415. pAttr->dwNumValues = dwValues;
  416. pAttr->pADsValues = (ADSVALUE*)AllocADsMem( sizeof( ADSVALUE ) * dwValues );
  417. pCurrentADsObject = pAttr->pADsValues;
  418. for( dwIdx = 0L; dwIdx < dwValues ; dwIdx++ )
  419. {
  420. strItem = GetValueByIndex( rVal, SEPARATOR_C, dwIdx );
  421. pCurrentADsObject->dwType = (ADSTYPE)m_dwSyntaxID;
  422. hResult = Value2Native( pCurrentADsObject, strItem );
  423. pCurrentADsObject++;
  424. }
  425. break;
  426. }
  427. return hResult;
  428. }
  429. /***********************************************************
  430. Function:
  431. Arguments:
  432. Return:
  433. Purpose:
  434. Author(s):
  435. Revision:
  436. Date:
  437. ***********************************************************/
  438. DWORD COleDsSyntax::GetValuesCount( CString& rString, TCHAR cSeparator )
  439. {
  440. DWORD dwValues;
  441. DWORD dwIdx;
  442. dwValues = 1L;
  443. for( dwIdx = 0L; dwIdx < (DWORD)rString.GetLength( ) ; dwIdx++ )
  444. {
  445. TCHAR cCurrent;
  446. cCurrent = rString.GetAt( dwIdx );
  447. if( cCurrent == cSeparator )
  448. {
  449. dwValues++;
  450. }
  451. }
  452. return dwValues;
  453. }
  454. /***********************************************************
  455. Function:
  456. Arguments:
  457. Return:
  458. Purpose:
  459. Author(s):
  460. Revision:
  461. Date:
  462. ***********************************************************/
  463. CString COleDsSyntax::GetValueByIndex( CString& rVal, TCHAR cSeparator, DWORD dwIndex )
  464. {
  465. DWORD dwParsed = 0L;
  466. DWORD dwIter = 0L;
  467. DWORD dwSize;
  468. CString strItem;
  469. dwSize = rVal.GetLength( );
  470. while( dwIter < dwSize && dwParsed < dwIndex && rVal.GetAt(dwIter) )
  471. {
  472. if( cSeparator == rVal.GetAt(dwIter++) )
  473. dwParsed++;
  474. }
  475. while( dwIter < dwSize && cSeparator != rVal.GetAt(dwIter) )
  476. {
  477. strItem += rVal.GetAt(dwIter++);
  478. }
  479. strItem.TrimLeft( );
  480. return strItem;
  481. }
  482. /***********************************************************
  483. Function:
  484. Arguments:
  485. Return:
  486. Purpose:
  487. Author(s):
  488. Revision:
  489. Date:
  490. ***********************************************************/
  491. COleDsBSTR::COleDsBSTR( )
  492. {
  493. m_lType = VT_BSTR;
  494. m_dwSyntaxID = ADSTYPE_DN_STRING;
  495. }
  496. /***********************************************************
  497. Function:
  498. Arguments:
  499. Return:
  500. Purpose:
  501. Author(s):
  502. Revision:
  503. Date:
  504. ***********************************************************/
  505. HRESULT COleDsBSTR::Native2Value( ADSVALUE* pAdsValue, CString& rVal )
  506. {
  507. TCHAR szBuffer[ 1024 ];
  508. if( pAdsValue->DNString )
  509. {
  510. Convert( szBuffer, pAdsValue->DNString );
  511. }
  512. else
  513. {
  514. _tcscpy( szBuffer, _T("NULL value") );
  515. }
  516. rVal = szBuffer;
  517. return S_OK;
  518. }
  519. /***********************************************************
  520. Function:
  521. Arguments:
  522. Return:
  523. Purpose:
  524. Author(s):
  525. Revision:
  526. Date:
  527. ***********************************************************/
  528. HRESULT COleDsBSTR::Value2Native( ADSVALUE* pADsObject, CString& rVal )
  529. {
  530. LPWSTR lpwszValue;
  531. lpwszValue = (LPWSTR) AllocADsMem( sizeof(WCHAR) * ( rVal.GetLength( ) + 1 ) );
  532. Convert( lpwszValue, rVal.GetBuffer( 1024 ) );
  533. pADsObject->DNString = lpwszValue;
  534. return S_OK;
  535. }
  536. /***********************************************************
  537. Function: COleDsBSTR::FreeAttrValue
  538. Arguments:
  539. Return:
  540. Purpose:
  541. Author(s):
  542. Revision:
  543. Date:
  544. ***********************************************************/
  545. void COleDsBSTR::FreeAttrValue ( ADSVALUE* pADsValue )
  546. {
  547. ASSERT( NULL != pADsValue->DNString );
  548. FREE_MEMORY( pADsValue->DNString );
  549. }
  550. /***********************************************************
  551. Function:
  552. Arguments:
  553. Return:
  554. Purpose:
  555. Author(s):
  556. Revision:
  557. Date:
  558. ***********************************************************/
  559. COleDsBOOL::COleDsBOOL( )
  560. {
  561. m_lType = VT_BOOL;
  562. m_dwSyntaxID = ADSTYPE_BOOLEAN;
  563. }
  564. /***********************************************************
  565. Function:
  566. Arguments:
  567. Return:
  568. Purpose:
  569. Author(s):
  570. Revision:
  571. Date:
  572. ***********************************************************/
  573. HRESULT COleDsBOOL::Native2Value( ADSVALUE* pADsObject, CString& rVal )
  574. {
  575. BOOL bVal;
  576. bVal = pADsObject->Boolean;
  577. rVal = ( bVal ? _T("1") : _T("0") );
  578. return S_OK;
  579. }
  580. /***********************************************************
  581. Function:
  582. Arguments:
  583. Return:
  584. Purpose:
  585. Author(s):
  586. Revision:
  587. Date:
  588. ***********************************************************/
  589. HRESULT COleDsBOOL::Value2Native( ADSVALUE* pADsObject, CString& rVal )
  590. {
  591. pADsObject->Boolean =
  592. rVal.Compare( _T("0") ) ? TRUE : FALSE;
  593. return S_OK;
  594. }
  595. /***********************************************************
  596. Function:
  597. Arguments:
  598. Return:
  599. Purpose:
  600. Author(s):
  601. Revision:
  602. Date:
  603. ***********************************************************/
  604. COleDsLONG::COleDsLONG( )
  605. {
  606. m_lType = VT_I4;
  607. m_dwSyntaxID = ADSTYPE_INTEGER;
  608. }
  609. /***********************************************************
  610. Function: COleDsLONG::Native2Value
  611. Arguments:
  612. Return:
  613. Purpose:
  614. Author(s):
  615. Revision:
  616. Date:
  617. ***********************************************************/
  618. HRESULT COleDsLONG::Native2Value( ADSVALUE* pADsObject, CString& rVal )
  619. {
  620. DWORD dwVal;
  621. TCHAR szText[ 16 ];
  622. dwVal = pADsObject->Integer;
  623. _ultot( dwVal, szText, 10 );
  624. rVal = szText;
  625. return S_OK;
  626. }
  627. /***********************************************************
  628. Function:
  629. Arguments:
  630. Return:
  631. Purpose:
  632. Author(s):
  633. Revision:
  634. Date:
  635. ***********************************************************/
  636. HRESULT COleDsLONG::Value2Native( ADSVALUE* pADsObject, CString& rVal )
  637. {
  638. DWORD dwVal;
  639. dwVal = (DWORD)_ttol( rVal.GetBuffer( 128 ) );
  640. pADsObject->Integer = dwVal ;
  641. return S_OK;
  642. }
  643. /***********************************************************
  644. Function:
  645. Arguments:
  646. Return:
  647. Purpose:
  648. Author(s):
  649. Revision:
  650. Date:
  651. ***********************************************************/
  652. COleDsLargeInteger::COleDsLargeInteger( )
  653. {
  654. m_lType = VT_I8;
  655. m_dwSyntaxID = ADSTYPE_LARGE_INTEGER;
  656. }
  657. /******************************************************************************
  658. Function:
  659. Arguments:
  660. Return:
  661. Purpose:
  662. Author(s):
  663. Revision:
  664. Date:
  665. ******************************************************************************/
  666. HRESULT COleDsLargeInteger::Native2Value( ADSVALUE* pValue, CString& rValue)
  667. {
  668. HRESULT hResult;
  669. TCHAR szValue[ 32 ];
  670. hResult = LARGE_INTEGERToString( szValue, &pValue->LargeInteger );
  671. ASSERT( SUCCEEDED( hResult ) );
  672. if( SUCCEEDED( hResult ) )
  673. {
  674. rValue = szValue;
  675. }
  676. return hResult;
  677. }
  678. /******************************************************************************
  679. Function: COleDsLargeInteger::Value2Native
  680. Arguments:
  681. Return:
  682. Purpose:
  683. Author(s):
  684. Revision:
  685. Date:
  686. ******************************************************************************/
  687. HRESULT COleDsLargeInteger::Value2Native( ADSVALUE* pValue, CString& rValue )
  688. {
  689. HRESULT hResult;
  690. hResult = LARGE_INTEGERToString( rValue.GetBuffer( 128 ), &pValue->LargeInteger );
  691. return hResult;
  692. }
  693. /***********************************************************
  694. Function: COleDsLargeInteger::DisplayStringToDispParamsEx
  695. Arguments:
  696. Return:
  697. Purpose:
  698. Author(s):
  699. Revision:
  700. Date:
  701. ***********************************************************/
  702. BOOL COleDsLargeInteger::DisplayStringToDispParamsEx( CString& rText,
  703. DISPPARAMS& dispParams,
  704. BOOL bMultiValued )
  705. {
  706. SAFEARRAY* pSArray;
  707. SAFEARRAYBOUND saBound;
  708. HRESULT hResult;
  709. LONG lIdx = LBOUND;
  710. DisplayStringToDispParams( rText, dispParams, bMultiValued, FALSE );
  711. if( !bMultiValued )
  712. {
  713. saBound.lLbound = LBOUND;
  714. saBound.cElements = 1;
  715. pSArray = SafeArrayCreate( VT_VARIANT, 1, &saBound );
  716. hResult = SafeArrayPutElement( pSArray, &lIdx, &dispParams.rgvarg[0] );
  717. VariantClear( &dispParams.rgvarg[0] );
  718. V_VT( &dispParams.rgvarg[0] ) = VT_ARRAY | VT_VARIANT;
  719. V_ARRAY( &dispParams.rgvarg[0] ) = pSArray;
  720. }
  721. return TRUE;
  722. }
  723. /***********************************************************
  724. Function:
  725. Arguments:
  726. Return:
  727. Purpose:
  728. Author(s):
  729. Revision:
  730. Date:
  731. ***********************************************************/
  732. BOOL COleDsLargeInteger::DisplayStringToDispParams( CString& rText,
  733. DISPPARAMS& dispParams,
  734. BOOL bMultiValued,
  735. BOOL bUseEx )
  736. {
  737. HRESULT hResult = E_FAIL;
  738. int x= 0;
  739. if( bUseEx )
  740. {
  741. return DisplayStringToDispParamsEx( rText, dispParams, bMultiValued );
  742. }
  743. dispParams.rgdispidNamedArgs[ 0 ] = DISPID_PROPERTYPUT;
  744. dispParams.cArgs = 1;
  745. dispParams.cNamedArgs = 1;
  746. if( bMultiValued )
  747. {
  748. SAFEARRAY* psa;
  749. SAFEARRAYBOUND sab;
  750. long lItems = 0;
  751. int lIdx;
  752. HRESULT hResult;
  753. rText.MakeUpper( );
  754. lItems = GetValuesCount( rText, SEPARATOR_C );
  755. sab.cElements = lItems;
  756. sab.lLbound = LBOUND;
  757. psa = SafeArrayCreate( VT_VARIANT, 1, &sab );
  758. ASSERT( NULL != psa );
  759. if ( psa )
  760. {
  761. for( lIdx = LBOUND; lIdx < ( LBOUND + lItems ) ; lIdx++ )
  762. {
  763. VARIANT var;
  764. CString strTemp;
  765. strTemp = GetValueAt( rText, SEPARATOR_C, lIdx - LBOUND );
  766. V_VT( &var ) = VT_DISPATCH;
  767. V_DISPATCH( &var ) = CreateLargeInteger( strTemp );
  768. hResult = SafeArrayPutElement( psa, (long FAR *)&lIdx, &var );
  769. VariantClear( &var );
  770. }
  771. V_VT( &dispParams.rgvarg[0] ) = VT_VARIANT | VT_ARRAY;
  772. V_ARRAY( &dispParams.rgvarg[0] ) = psa;
  773. }
  774. }
  775. else
  776. {
  777. IDispatch* pDisp = NULL;
  778. hResult = S_OK;
  779. pDisp = CreateLargeInteger( rText );
  780. V_VT( &dispParams.rgvarg[0] ) = VT_DISPATCH;
  781. V_DISPATCH( &dispParams.rgvarg[0] ) = pDisp;
  782. }
  783. return SUCCEEDED( hResult );
  784. }
  785. /***********************************************************
  786. Function:
  787. Arguments:
  788. Return:
  789. Purpose:
  790. Author(s):
  791. Revision:
  792. Date:
  793. ***********************************************************/
  794. CString COleDsLargeInteger::VarToDisplayStringEx( VARIANT& var,
  795. BOOL bMultiValued )
  796. {
  797. SAFEARRAY* pSArray;
  798. HRESULT hResult;
  799. LONG uLow, uHigh, uIndex;
  800. VARIANT vItem;
  801. CString strVal;
  802. CString strTemp;
  803. pSArray = V_ARRAY( &var );
  804. hResult = SafeArrayGetLBound( pSArray, 1, &uLow );
  805. hResult = SafeArrayGetUBound( pSArray, 1, &uHigh );
  806. if( !bMultiValued )
  807. {
  808. ASSERT( uLow == uHigh );
  809. }
  810. for( uIndex = uLow; uIndex <= uHigh; uIndex++ )
  811. {
  812. if( uIndex != uLow )
  813. {
  814. strVal += SEPARATOR_S;
  815. }
  816. VariantInit( &vItem );
  817. hResult = SafeArrayGetElement( pSArray, &uIndex, &vItem );
  818. ASSERT( SUCCEEDED( hResult ) );
  819. strTemp = FromLargeInteger( V_DISPATCH( &vItem ) );
  820. VariantClear( &vItem );
  821. strVal += strTemp;
  822. if( strVal.GetLength( ) > 8096 )
  823. break;
  824. }
  825. return strVal;
  826. }
  827. /***********************************************************
  828. Function:
  829. Arguments:
  830. Return:
  831. Purpose:
  832. Author(s):
  833. Revision:
  834. Date:
  835. ***********************************************************/
  836. CString COleDsLargeInteger::VarToDisplayString( VARIANT& var,
  837. BOOL bMultiValued,
  838. BOOL bUseEx )
  839. {
  840. if( bUseEx )
  841. {
  842. return VarToDisplayStringEx( var, bMultiValued );
  843. }
  844. if( bMultiValued )
  845. {
  846. return VarToDisplayStringEx( var, TRUE );
  847. }
  848. else
  849. {
  850. return FromLargeInteger( V_DISPATCH( &var ) );
  851. }
  852. }
  853. /******************************************************************************
  854. Function: COleDsDATE::COleDsDATE
  855. Arguments:
  856. Return:
  857. Purpose:
  858. Author(s):
  859. Revision:
  860. Date:
  861. ******************************************************************************/
  862. COleDsDATE::COleDsDATE( )
  863. {
  864. m_lType = VT_DATE;
  865. m_dwSyntaxID = ADSTYPE_UTC_TIME;
  866. }
  867. /******************************************************************************
  868. Function:
  869. Arguments:
  870. Return:
  871. Purpose:
  872. Author(s):
  873. Revision:
  874. Date:
  875. ******************************************************************************/
  876. HRESULT COleDsDATE::Native2Value( ADSVALUE* pADsObject, CString& rVal )
  877. {
  878. DATE aDate;
  879. ADS_UTC_TIME aUTCTime;
  880. HRESULT hResult;
  881. aUTCTime = pADsObject->UTCTime;
  882. hResult = SystemTimeToVariantTime( (SYSTEMTIME*) &aUTCTime, &aDate );
  883. if( SUCCEEDED( hResult ) )
  884. {
  885. VARIANT aVar;
  886. VARIANT vText;
  887. VariantInit( &aVar );
  888. VariantInit( &vText );
  889. V_VT( &aVar ) = VT_DATE;
  890. V_DATE( &aVar ) = aDate;
  891. hResult = VariantChangeType( &vText, &aVar, VARIANT_NOVALUEPROP, VT_BSTR );
  892. if( SUCCEEDED( hResult ) )
  893. {
  894. TCHAR szText[ 128 ];
  895. Convert( szText, V_BSTR( &vText ) );
  896. rVal = szText;
  897. VariantClear( &vText );
  898. }
  899. }
  900. return hResult;
  901. }
  902. /***********************************************************
  903. Function:
  904. Arguments:
  905. Return:
  906. Purpose:
  907. Author(s):
  908. Revision:
  909. Date:
  910. ***********************************************************/
  911. HRESULT COleDsDATE::Value2Native( ADSVALUE* pADsObject, CString& rVal )
  912. {
  913. DATE aDate;
  914. ADS_UTC_TIME aUTCTime;
  915. HRESULT hResult;
  916. VARIANT vDate;
  917. VARIANT vText;
  918. VariantInit( &vText );
  919. VariantInit( &vDate );
  920. V_VT( &vText ) = VT_BSTR;
  921. V_BSTR( &vText ) = AllocBSTR( rVal.GetBuffer( 128 ) );
  922. hResult = VariantChangeType( &vDate, &vText, VARIANT_NOVALUEPROP, VT_DATE );
  923. VariantClear( &vText );
  924. if( SUCCEEDED( hResult ) )
  925. {
  926. aDate = V_DATE( &vDate );
  927. hResult = VariantTimeToSystemTime( aDate, (SYSTEMTIME*) &aUTCTime );
  928. pADsObject->UTCTime = aUTCTime;
  929. }
  930. return hResult;
  931. }
  932. /***********************************************************
  933. Function: COleDsNDSOctetList::COleDsNDSOctetList
  934. Arguments:
  935. Return:
  936. Purpose:
  937. Author(s):
  938. Revision:
  939. Date:
  940. ***********************************************************/
  941. COleDsNDSCaseIgnoreList::COleDsNDSCaseIgnoreList( )
  942. {
  943. m_dwSyntaxID = ADSTYPE_CASEIGNORE_LIST;
  944. }
  945. /***********************************************************
  946. Function: COleDsNDSCaseIgnoreList::Native2Value
  947. Arguments:
  948. Return:
  949. Purpose:
  950. Author(s):
  951. Revision:
  952. Date:
  953. ***********************************************************/
  954. HRESULT COleDsNDSCaseIgnoreList::Native2Value( ADSVALUE* pValue,
  955. CString& rText )
  956. {
  957. ADS_CASEIGNORE_LIST* pStringList;
  958. int nIdx;
  959. ASSERT( ADSTYPE_CASEIGNORE_LIST == pValue->dwType );
  960. if( ADSTYPE_CASEIGNORE_LIST != pValue->dwType )
  961. {
  962. rText = _T("ERROR: ADSTYPE_CASEIGNORE_LIST != pValue->dwType");
  963. return E_FAIL;
  964. }
  965. nIdx = 0;
  966. pStringList = pValue->pCaseIgnoreList;
  967. while( NULL != pStringList && NULL != pStringList->String )
  968. {
  969. TCHAR* pszText;
  970. if( 0 != nIdx )
  971. rText = rText + NDS_SEPARATOR;
  972. nIdx = 1;
  973. pszText = AllocTCHAR( pStringList->String );
  974. if( NULL != pszText )
  975. {
  976. rText = rText + pszText;
  977. FreeADsMem( pszText );
  978. }
  979. pStringList = pStringList->Next;
  980. }
  981. return S_OK;
  982. }
  983. /***********************************************************
  984. Function: COleDsNDSCaseIgnoreList::Value2Native
  985. Arguments:
  986. Return:
  987. Purpose:
  988. Author(s):
  989. Revision:
  990. Date:
  991. ***********************************************************/
  992. HRESULT COleDsNDSCaseIgnoreList::Value2Native( ADSVALUE* pValue,
  993. CString& rText )
  994. {
  995. HRESULT hResult = E_FAIL;
  996. DWORD dwValues, dwItem;
  997. CString strItem;
  998. ADS_CASEIGNORE_LIST** ppItem;
  999. pValue->dwType = ADSTYPE_CASEIGNORE_LIST;
  1000. pValue->pCaseIgnoreList = NULL;
  1001. dwValues = GetValuesCount( rText, NDS_SEPARATOR );
  1002. ppItem = &(pValue->pCaseIgnoreList);
  1003. for( dwItem = 0; dwItem < dwValues ; dwItem++ )
  1004. {
  1005. strItem = GetValueByIndex( rText, NDS_SEPARATOR, dwItem );
  1006. *ppItem = (ADS_CASEIGNORE_LIST*) AllocADsMem( sizeof( ADS_CASEIGNORE_LIST ) );
  1007. (*ppItem)->String = AllocWCHAR( strItem.GetBuffer( strItem.GetLength( ) ) );
  1008. (*ppItem)->Next = NULL;
  1009. ppItem = &((*ppItem)->Next );
  1010. }
  1011. if( dwValues == 0 )
  1012. {
  1013. pValue->pCaseIgnoreList = (ADS_CASEIGNORE_LIST*) AllocADsMem( sizeof( ADS_CASEIGNORE_LIST ) );
  1014. pValue->pCaseIgnoreList->String = NULL;
  1015. pValue->pCaseIgnoreList->Next = NULL;
  1016. }
  1017. return S_OK;
  1018. }
  1019. /***********************************************************
  1020. Function: COleDsNDSCaseIgnoreList::FreeAttrValue
  1021. Arguments:
  1022. Return:
  1023. Purpose:
  1024. Author(s):
  1025. Revision:
  1026. Date:
  1027. ***********************************************************/
  1028. void COleDsNDSCaseIgnoreList::FreeAttrValue( ADSVALUE* pValue )
  1029. {
  1030. ADS_CASEIGNORE_LIST* pStringList;
  1031. ADS_CASEIGNORE_LIST* pSaveStringList;
  1032. pStringList = pValue->pCaseIgnoreList;
  1033. while( NULL != pStringList )
  1034. {
  1035. FREE_MEMORY( pStringList->String );
  1036. pSaveStringList = pStringList;
  1037. pStringList = pStringList->Next;
  1038. FREE_MEMORY( pSaveStringList );
  1039. }
  1040. }
  1041. /***********************************************************
  1042. Function: COleDsNDSCaseIgnoreList::String_2_VARIANT
  1043. Arguments:
  1044. Return:
  1045. Purpose:
  1046. Author(s):
  1047. Revision:
  1048. Date:
  1049. ***********************************************************/
  1050. HRESULT COleDsNDSCaseIgnoreList::String_2_VARIANT( TCHAR* pszText,
  1051. VARIANT& rValue )
  1052. {
  1053. HRESULT hResult = E_FAIL;
  1054. CString strItem;
  1055. VARIANT vVal;
  1056. IADsCaseIgnoreList* pCaseIgnoreList = NULL;
  1057. IDispatch* pDisp = NULL;
  1058. VariantInit( &vVal );
  1059. VariantInit( &rValue );
  1060. while( TRUE )
  1061. {
  1062. hResult = CoCreateInstance(
  1063. CLSID_CaseIgnoreList,
  1064. NULL,
  1065. CLSCTX_ALL,
  1066. IID_IADsCaseIgnoreList,
  1067. (void **)&pCaseIgnoreList );
  1068. ASSERT( SUCCEEDED( hResult ) );
  1069. if( FAILED( hResult ) )
  1070. break;
  1071. strItem = pszText;
  1072. hResult = BuildVariantArray( VT_BSTR,
  1073. strItem,
  1074. vVal,
  1075. NDS_SEPARATOR );
  1076. ASSERT( SUCCEEDED( hResult ) );
  1077. if( FAILED( hResult ) )
  1078. break;
  1079. hResult = pCaseIgnoreList->put_CaseIgnoreList( vVal );
  1080. ASSERT( SUCCEEDED( hResult ) );
  1081. if( FAILED( hResult ) )
  1082. break;
  1083. hResult = pCaseIgnoreList->QueryInterface( IID_IDispatch, (void**)&pDisp );
  1084. ASSERT( SUCCEEDED( hResult ) );
  1085. if( FAILED( hResult ) )
  1086. break;
  1087. V_VT( &rValue ) = VT_DISPATCH;
  1088. V_DISPATCH( &rValue ) = pDisp;
  1089. break;
  1090. }
  1091. VariantClear( &vVal );
  1092. RELEASE( pCaseIgnoreList );
  1093. return hResult;
  1094. }
  1095. /***********************************************************
  1096. Function: COleDsNDSCaseIgnoreList::VARIANT_2_String
  1097. Arguments:
  1098. Return:
  1099. Purpose:
  1100. Author(s):
  1101. Revision:
  1102. Date:
  1103. ***********************************************************/
  1104. HRESULT COleDsNDSCaseIgnoreList::VARIANT_2_String( TCHAR* pszText,
  1105. VARIANT& rValue )
  1106. {
  1107. IADsCaseIgnoreList* pCaseIgnoreList = NULL;
  1108. HRESULT hResult;
  1109. VARIANT vValue;
  1110. CString strText;
  1111. VariantInit( &vValue );
  1112. while( TRUE )
  1113. {
  1114. hResult = V_DISPATCH( &rValue )->QueryInterface( IID_IADsCaseIgnoreList,
  1115. (void**)&pCaseIgnoreList );
  1116. ASSERT( SUCCEEDED( hResult ) );
  1117. if( FAILED( hResult ) )
  1118. break;
  1119. hResult = pCaseIgnoreList->get_CaseIgnoreList( &vValue );
  1120. ASSERT( SUCCEEDED( hResult ) );
  1121. if( FAILED( hResult ) )
  1122. break;
  1123. strText = FromVariantArrayToString( vValue, NDS_SEPARATOR_S );
  1124. _tcscpy( pszText, (LPCTSTR)strText );
  1125. break;
  1126. }
  1127. RELEASE( pCaseIgnoreList );
  1128. VariantClear( &vValue );
  1129. return hResult;
  1130. }
  1131. /***********************************************************
  1132. Function: COleDsNDSNetAddress::COleDsNDSNetAddress
  1133. Arguments:
  1134. Return:
  1135. Purpose:
  1136. Author(s):
  1137. Revision:
  1138. Date:
  1139. ***********************************************************/
  1140. COleDsNDSNetAddress::COleDsNDSNetAddress( )
  1141. {
  1142. m_dwSyntaxID = ADSTYPE_NETADDRESS;
  1143. }
  1144. /***********************************************************
  1145. Function: COleDsNDSNetAddress::Native2Value
  1146. Arguments:
  1147. Return:
  1148. Purpose:
  1149. Author(s):
  1150. Revision:
  1151. Date:
  1152. ***********************************************************/
  1153. HRESULT COleDsNDSNetAddress::Native2Value( ADSVALUE* pValue, CString& rText )
  1154. {
  1155. ADS_NETADDRESS* pNetAddress;
  1156. TCHAR szText[ 16 ];
  1157. ASSERT( ADSTYPE_NETADDRESS == pValue->dwType );
  1158. if( ADSTYPE_NETADDRESS != pValue->dwType )
  1159. {
  1160. rText = _T("ERROR: ADSTYPE_NETADDRESS != pValue->dwType");
  1161. return E_FAIL;
  1162. }
  1163. if( NULL == pValue->pNetAddress )
  1164. {
  1165. rText = _T("ERROR: pValue->pNetAddress is NULL");
  1166. return E_FAIL;
  1167. }
  1168. pNetAddress = pValue->pNetAddress;
  1169. _ultot( pNetAddress->AddressType, szText, 10 );
  1170. rText = rText + SEPARATOR_S;
  1171. if( NULL != pNetAddress->Address )
  1172. {
  1173. rText = rText + Blob2String( pNetAddress->Address, pNetAddress->AddressLength );
  1174. }
  1175. else
  1176. {
  1177. rText = rText + _T("NULL");
  1178. }
  1179. return S_OK;
  1180. }
  1181. /***********************************************************
  1182. Function: COleDsNDSNetAddress::Value2Native
  1183. Arguments:
  1184. Return:
  1185. Purpose:
  1186. Author(s):
  1187. Revision:
  1188. Date:
  1189. ***********************************************************/
  1190. HRESULT COleDsNDSNetAddress::Value2Native( ADSVALUE* pValue,
  1191. CString& rText )
  1192. {
  1193. HRESULT hResult = E_FAIL;
  1194. DWORD dwValues;
  1195. CString strAddressType;
  1196. CString strAddress;
  1197. pValue->dwType = ADSTYPE_NETADDRESS;
  1198. pValue->pNetAddress = NULL;
  1199. while( TRUE )
  1200. {
  1201. dwValues = GetValuesCount( rText, NDS_SEPARATOR );
  1202. if( 2 != dwValues )
  1203. {
  1204. ASSERT( FALSE );
  1205. break;
  1206. }
  1207. pValue->pNetAddress = (ADS_NETADDRESS*) AllocADsMem( sizeof(ADS_NETADDRESS) );
  1208. if( NULL == pValue->pNetAddress )
  1209. break;
  1210. strAddressType = GetValueByIndex( rText, NDS_SEPARATOR, 0L );
  1211. strAddress = GetValueByIndex( rText, NDS_SEPARATOR, 1L );
  1212. hResult = String2Blob( strAddress.GetBuffer( strAddress.GetLength( ) ),
  1213. (void**) &(pValue->pNetAddress->Address),
  1214. &(pValue->pNetAddress->AddressLength) );
  1215. pValue->pNetAddress->AddressType = (DWORD)_ttol( (LPCTSTR)strAddressType );
  1216. break;
  1217. }
  1218. return S_OK;
  1219. }
  1220. /***********************************************************
  1221. Function: COleDsNDSNetAddress::FreeAttrValue
  1222. Arguments:
  1223. Return:
  1224. Purpose:
  1225. Author(s):
  1226. Revision:
  1227. Date:
  1228. ***********************************************************/
  1229. void COleDsNDSNetAddress::FreeAttrValue( ADSVALUE* pValue )
  1230. {
  1231. if( NULL != pValue->pNetAddress )
  1232. {
  1233. FREE_MEMORY( pValue->pNetAddress->Address );
  1234. }
  1235. FREE_MEMORY( pValue->pNetAddress );
  1236. }
  1237. /***********************************************************
  1238. Function: COleDsNDSNetAddress::String_2_VARIANT
  1239. Arguments:
  1240. Return:
  1241. Purpose:
  1242. Author(s):
  1243. Revision:
  1244. Date:
  1245. ***********************************************************/
  1246. HRESULT COleDsNDSNetAddress::String_2_VARIANT( TCHAR* pszText,
  1247. VARIANT& rValue )
  1248. {
  1249. HRESULT hResult = E_FAIL;
  1250. CString strItem;
  1251. CString strAddressType;
  1252. CString strAddress;
  1253. DWORD dwValues;
  1254. VARIANT vVal, vBlob;
  1255. IADsNetAddress* pNetAddress = NULL;
  1256. IDispatch* pDisp = NULL;
  1257. VariantInit( &vVal );
  1258. VariantInit( &vBlob );
  1259. VariantInit( &rValue );
  1260. strItem = pszText;
  1261. while( TRUE )
  1262. {
  1263. hResult = CoCreateInstance(
  1264. CLSID_NetAddress,
  1265. NULL,
  1266. CLSCTX_ALL,
  1267. IID_IADsNetAddress,
  1268. (void **)&pNetAddress );
  1269. ASSERT( SUCCEEDED( hResult ) );
  1270. if( FAILED( hResult ) )
  1271. break;
  1272. dwValues = GetValuesCount( strItem, NDS_SEPARATOR );
  1273. if( 2 != dwValues )
  1274. {
  1275. ASSERT( FALSE );
  1276. break;
  1277. }
  1278. strAddressType = GetValueByIndex( strItem, NDS_SEPARATOR, 0L );
  1279. strAddress = GetValueByIndex( strItem, NDS_SEPARATOR, 1L );
  1280. pNetAddress->put_AddressType( _ttol( (LPCTSTR)strAddressType ) );
  1281. ASSERT( SUCCEEDED( hResult ) );
  1282. if( FAILED( hResult ) )
  1283. break;
  1284. hResult = CreateBlobArray( strAddress, vBlob );
  1285. ASSERT( SUCCEEDED( hResult ) );
  1286. if( FAILED( hResult ) )
  1287. break;
  1288. pNetAddress->put_Address( vBlob );
  1289. ASSERT( SUCCEEDED( hResult ) );
  1290. if( FAILED( hResult ) )
  1291. break;
  1292. hResult = pNetAddress->QueryInterface( IID_IDispatch, (void**)&pDisp );
  1293. ASSERT( SUCCEEDED( hResult ) );
  1294. if( FAILED( hResult ) )
  1295. break;
  1296. V_VT( &rValue ) = VT_DISPATCH;
  1297. V_DISPATCH( &rValue ) = pDisp;
  1298. break;
  1299. }
  1300. VariantClear( &vVal );
  1301. VariantClear( &vBlob );
  1302. RELEASE( pNetAddress );
  1303. return hResult;
  1304. }
  1305. /***********************************************************
  1306. Function: COleDsNDSNetAddress::VARIANT_2_String
  1307. Arguments:
  1308. Return:
  1309. Purpose:
  1310. Author(s):
  1311. Revision:
  1312. Date:
  1313. ***********************************************************/
  1314. HRESULT COleDsNDSNetAddress::VARIANT_2_String( TCHAR* pszText,
  1315. VARIANT& rValue )
  1316. {
  1317. IADsNetAddress* pNetAddress= NULL;
  1318. HRESULT hResult;
  1319. CString strText;
  1320. LONG lAddressType;
  1321. VARIANT vItem;
  1322. VariantInit( &vItem );
  1323. while( TRUE )
  1324. {
  1325. hResult = V_DISPATCH( &rValue )->QueryInterface( IID_IADsNetAddress,
  1326. (void**)&pNetAddress );
  1327. ASSERT( SUCCEEDED( hResult ) );
  1328. if( FAILED( hResult ) )
  1329. break;
  1330. hResult = pNetAddress->get_Address( &vItem );
  1331. ASSERT( SUCCEEDED( hResult ) );
  1332. if( FAILED( hResult ) )
  1333. break;
  1334. hResult = pNetAddress->get_AddressType( &lAddressType );
  1335. ASSERT( SUCCEEDED( hResult ) );
  1336. if( FAILED( hResult ) )
  1337. break;
  1338. strText = FromVariantToString( vItem );
  1339. _ltot( lAddressType, pszText, 10 );
  1340. _tcscat( pszText, NDS_SEPARATOR_S ) ;
  1341. _tcscat( pszText, (LPCTSTR)strText );
  1342. break;
  1343. }
  1344. RELEASE( pNetAddress );
  1345. VariantClear( &vItem );
  1346. return hResult;
  1347. }
  1348. /***********************************************************
  1349. Function: COleDsNDSOctetList::COleDsNDSOctetList
  1350. Arguments:
  1351. Return:
  1352. Purpose:
  1353. Author(s):
  1354. Revision:
  1355. Date:
  1356. ***********************************************************/
  1357. COleDsNDSOctetList::COleDsNDSOctetList( )
  1358. {
  1359. m_dwSyntaxID = ADSTYPE_OCTET_LIST;
  1360. }
  1361. /***********************************************************
  1362. Function: COleDsNDSOctetList::Native2Value
  1363. Arguments:
  1364. Return:
  1365. Purpose:
  1366. Author(s):
  1367. Revision:
  1368. Date:
  1369. ***********************************************************/
  1370. HRESULT COleDsNDSOctetList::Native2Value( ADSVALUE* pValue, CString& rText )
  1371. {
  1372. ADS_OCTET_LIST* pOctetString;
  1373. int nIdx;
  1374. ASSERT( ADSTYPE_OCTET_LIST == pValue->dwType );
  1375. if( ADSTYPE_OCTET_LIST != pValue->dwType )
  1376. {
  1377. rText = _T("ERROR: ADSTYPE_OCTET_LIST != pValue->dwType");
  1378. return E_FAIL;
  1379. }
  1380. nIdx = 0;
  1381. pOctetString = pValue->pOctetList;
  1382. while( NULL != pOctetString && NULL != pOctetString->Data )
  1383. {
  1384. if( 0 != nIdx )
  1385. rText = rText + SEPARATOR_S;
  1386. nIdx = 1;
  1387. rText = rText + Blob2String( pOctetString->Data, (DWORD)pOctetString->Length );
  1388. pOctetString = pOctetString->Next;
  1389. }
  1390. return S_OK;
  1391. }
  1392. /***********************************************************
  1393. Function: COleDsNDSOctetList::Value2Native
  1394. Arguments:
  1395. Return:
  1396. Purpose:
  1397. Author(s):
  1398. Revision:
  1399. Date:
  1400. ***********************************************************/
  1401. HRESULT COleDsNDSOctetList::Value2Native( ADSVALUE* pValue,
  1402. CString& rText )
  1403. {
  1404. HRESULT hResult = E_FAIL;
  1405. DWORD dwValues, dwItem;
  1406. CString strItem;
  1407. ADS_OCTET_LIST** ppItem;
  1408. pValue->dwType = ADSTYPE_OCTET_LIST;
  1409. pValue->pOctetList = NULL;
  1410. dwValues = GetValuesCount( rText, NDS_SEPARATOR );
  1411. ppItem = &(pValue->pOctetList);
  1412. for( dwItem = 0; dwItem < dwValues ; dwItem++ )
  1413. {
  1414. strItem = GetValueByIndex( rText, NDS_SEPARATOR, dwItem );
  1415. *ppItem = (ADS_OCTET_LIST*) AllocADsMem( sizeof( ADS_OCTET_LIST ) );
  1416. hResult = String2Blob( strItem.GetBuffer( strItem.GetLength( ) ),
  1417. (void**) &((*ppItem)->Data),
  1418. &((*ppItem)->Length) );
  1419. ASSERT( SUCCEEDED( hResult ) );
  1420. (*ppItem)->Next = NULL;
  1421. ppItem = &((*ppItem)->Next );
  1422. }
  1423. if( dwValues == 0 )
  1424. {
  1425. pValue->pOctetList = (ADS_OCTET_LIST*) AllocADsMem( sizeof( ADS_OCTET_LIST ) );
  1426. pValue->pOctetList->Data = NULL;
  1427. pValue->pOctetList->Next = NULL;
  1428. }
  1429. return S_OK;
  1430. }
  1431. /***********************************************************
  1432. Function: COleDsNDSOctetList::FreeAttrValue
  1433. Arguments:
  1434. Return:
  1435. Purpose:
  1436. Author(s):
  1437. Revision:
  1438. Date:
  1439. ***********************************************************/
  1440. void COleDsNDSOctetList::FreeAttrValue( ADSVALUE* pValue )
  1441. {
  1442. ADS_OCTET_LIST* pOctetList;
  1443. ADS_OCTET_LIST* pSaveOctetList;
  1444. BOOL bMark;
  1445. pOctetList = pValue->pOctetList;
  1446. bMark = FALSE;
  1447. while( NULL != pOctetList )
  1448. {
  1449. FREE_MEMORY( pOctetList->Data );
  1450. pSaveOctetList = pOctetList;
  1451. pOctetList = pOctetList->Next;
  1452. FREE_MEMORY( pSaveOctetList );
  1453. }
  1454. }
  1455. /***********************************************************
  1456. Function: COleDsNDSOctetList::String_2_VARIANT
  1457. Arguments:
  1458. Return:
  1459. Purpose:
  1460. Author(s):
  1461. Revision:
  1462. Date:
  1463. ***********************************************************/
  1464. HRESULT COleDsNDSOctetList::String_2_VARIANT( TCHAR* pszText,
  1465. VARIANT& rValue )
  1466. {
  1467. HRESULT hResult = E_FAIL;
  1468. CString strItem;
  1469. VARIANT vVal;
  1470. IADsOctetList* pOctetList = NULL;
  1471. IDispatch* pDisp = NULL;
  1472. VariantInit( &vVal );
  1473. VariantInit( &rValue );
  1474. while( TRUE )
  1475. {
  1476. hResult = CoCreateInstance(
  1477. CLSID_OctetList,
  1478. NULL,
  1479. CLSCTX_ALL,
  1480. IID_IADsOctetList,
  1481. (void **)&pOctetList );
  1482. ASSERT( SUCCEEDED( hResult ) );
  1483. if( FAILED( hResult ) )
  1484. break;
  1485. strItem = pszText;
  1486. hResult = CreateBlobArrayEx( strItem, vVal, NDS_SEPARATOR );
  1487. ASSERT( SUCCEEDED( hResult ) );
  1488. if( FAILED( hResult ) )
  1489. break;
  1490. hResult = pOctetList->put_OctetList( vVal );
  1491. ASSERT( SUCCEEDED( hResult ) );
  1492. if( FAILED( hResult ) )
  1493. break;
  1494. hResult = pOctetList->QueryInterface( IID_IDispatch, (void**)&pDisp );
  1495. ASSERT( SUCCEEDED( hResult ) );
  1496. if( FAILED( hResult ) )
  1497. break;
  1498. V_VT( &rValue ) = VT_DISPATCH;
  1499. V_DISPATCH( &rValue ) = pDisp;
  1500. break;
  1501. }
  1502. VariantClear( &vVal );
  1503. RELEASE( pOctetList );
  1504. return hResult;
  1505. }
  1506. /***********************************************************
  1507. Function: COleDsNDSOctetList::VARIANT_2_String
  1508. Arguments:
  1509. Return:
  1510. Purpose:
  1511. Author(s):
  1512. Revision:
  1513. Date:
  1514. ***********************************************************/
  1515. HRESULT COleDsNDSOctetList::VARIANT_2_String( TCHAR* pszText,
  1516. VARIANT& rValue )
  1517. {
  1518. IADsOctetList* pOctetList= NULL;
  1519. HRESULT hResult;
  1520. VARIANT vValue;
  1521. CString strText;
  1522. LONG lItems, lIdx;
  1523. VARIANT vItem;
  1524. VariantInit( &vValue );
  1525. *pszText = '\0';
  1526. while( TRUE )
  1527. {
  1528. hResult = V_DISPATCH( &rValue )->QueryInterface( IID_IADsOctetList,
  1529. (void**)&pOctetList );
  1530. ASSERT( SUCCEEDED( hResult ) );
  1531. if( FAILED( hResult ) )
  1532. break;
  1533. hResult = pOctetList->get_OctetList( &vValue );
  1534. ASSERT( SUCCEEDED( hResult ) );
  1535. if( FAILED( hResult ) )
  1536. break;
  1537. lItems = GetVARIANTSize ( vValue );
  1538. for( lIdx = 0; lIdx < lItems ; lIdx++ )
  1539. {
  1540. hResult = GetVARIANTAt( lIdx, vValue, vItem );
  1541. strText = FromVariantToString( vItem );
  1542. if( lIdx != 0 )
  1543. {
  1544. _tcscat( pszText, NDS_SEPARATOR_S );
  1545. }
  1546. _tcscat( pszText, (LPCTSTR)strText );
  1547. VariantClear( &vItem );
  1548. }
  1549. break;
  1550. }
  1551. RELEASE( pOctetList );
  1552. VariantClear( &vValue );
  1553. return hResult;
  1554. }
  1555. /***********************************************************
  1556. Function: COleDsNDSPostalAddress::COleDsNDSPostalAddress
  1557. Arguments:
  1558. Return:
  1559. Purpose:
  1560. Author(s):
  1561. Revision:
  1562. Date:
  1563. ***********************************************************/
  1564. COleDsNDSPostalAddress::COleDsNDSPostalAddress ( )
  1565. {
  1566. m_dwSyntaxID = ADSTYPE_POSTALADDRESS;
  1567. }
  1568. /***********************************************************
  1569. Function: COleDsNDSPostalAddress::Native2Value
  1570. Arguments:
  1571. Return:
  1572. Purpose:
  1573. Author(s):
  1574. Revision:
  1575. Date:
  1576. ***********************************************************/
  1577. HRESULT COleDsNDSPostalAddress::Native2Value( ADSVALUE* pValue,
  1578. CString& rString )
  1579. {
  1580. int nIdx;
  1581. ASSERT( ADSTYPE_POSTALADDRESS == pValue->dwType );
  1582. if( ADSTYPE_POSTALADDRESS != pValue->dwType )
  1583. {
  1584. rString = _T("ERROR: ADSTYPE_POSTALADDRESS != pValue->dwType");
  1585. return E_FAIL;
  1586. }
  1587. nIdx = 0;
  1588. rString = _T("");
  1589. for( nIdx = 0 ; nIdx < 6 ; nIdx++ )
  1590. {
  1591. LPWSTR lpszPostalAddress;
  1592. lpszPostalAddress = pValue->pPostalAddress->PostalAddress[ nIdx ];
  1593. if( NULL != lpszPostalAddress )
  1594. {
  1595. TCHAR* pszTemp;
  1596. if( 0 != nIdx )
  1597. {
  1598. rString = rString + NDS_SEPARATOR;
  1599. }
  1600. pszTemp = (TCHAR*) AllocADsMem( sizeof(TCHAR) * ( 1 + wcslen( lpszPostalAddress ) ) );
  1601. Convert( pszTemp, lpszPostalAddress );
  1602. rString = rString + pszTemp;
  1603. FreeADsMem( pszTemp );
  1604. }
  1605. else
  1606. {
  1607. ASSERT( 0 != nIdx );
  1608. break;
  1609. }
  1610. }
  1611. return S_OK;
  1612. }
  1613. /***********************************************************
  1614. Function: COleDsNDSPostalAddress::Value2Native
  1615. Arguments:
  1616. Return:
  1617. Purpose:
  1618. Author(s):
  1619. Revision:
  1620. Date:
  1621. ***********************************************************/
  1622. HRESULT COleDsNDSPostalAddress::Value2Native( ADSVALUE* pValue,
  1623. CString& rString )
  1624. {
  1625. DWORD dwIdx;
  1626. DWORD dwValues;
  1627. pValue->dwType = ADSTYPE_POSTALADDRESS;
  1628. pValue->pPostalAddress = (ADS_POSTALADDRESS*) AllocADsMem( sizeof(ADS_POSTALADDRESS) );
  1629. for( dwIdx = 0; dwIdx < 6 ; dwIdx++ )
  1630. {
  1631. pValue->pPostalAddress->PostalAddress[ dwIdx ] = NULL;
  1632. }
  1633. dwValues = GetValuesCount( rString, NDS_SEPARATOR );
  1634. if( 0 == dwValues )
  1635. return S_OK;
  1636. for( dwIdx = 0; dwIdx < dwValues && dwIdx < 6; dwIdx++ )
  1637. {
  1638. CString strItem;
  1639. LPWSTR lpszPostalAddress;
  1640. strItem = GetValueByIndex( rString, NDS_SEPARATOR, dwIdx );
  1641. lpszPostalAddress = (LPWSTR) AllocADsMem( sizeof(TCHAR) * (strItem.GetLength( ) + 1 ) );
  1642. Convert( lpszPostalAddress, strItem.GetBuffer( strItem.GetLength( ) ) );
  1643. pValue->pPostalAddress->PostalAddress[ dwIdx ] = lpszPostalAddress;
  1644. }
  1645. return S_OK;
  1646. }
  1647. /***********************************************************
  1648. Function: COleDsNDSPostalAddress::FreeAttrValue
  1649. Arguments:
  1650. Return:
  1651. Purpose:
  1652. Author(s):
  1653. Revision:
  1654. Date:
  1655. ***********************************************************/
  1656. void COleDsNDSPostalAddress::FreeAttrValue( ADSVALUE* pValue )
  1657. {
  1658. DWORD dwIdx;
  1659. for( dwIdx = 0; dwIdx < 6 ; dwIdx++ )
  1660. {
  1661. FREE_MEMORY( pValue->pPostalAddress->PostalAddress[ dwIdx ] );
  1662. }
  1663. FreeADsMem( pValue->pPostalAddress );
  1664. }
  1665. /***********************************************************
  1666. Function: COleDsNDSPostalAddress::String_2_VARIANT
  1667. Arguments:
  1668. Return:
  1669. Purpose:
  1670. Author(s):
  1671. Revision:
  1672. Date:
  1673. ***********************************************************/
  1674. HRESULT COleDsNDSPostalAddress::String_2_VARIANT( TCHAR* pszText,
  1675. VARIANT& rVar )
  1676. {
  1677. CString strData;
  1678. CString strItem;
  1679. DWORD dwIdx;
  1680. DWORD dwValues;
  1681. HRESULT hResult;
  1682. VARIANT vArray;
  1683. SAFEARRAY* pSArray;
  1684. SAFEARRAYBOUND saBound;
  1685. LONG lIdx;
  1686. IADsPostalAddress* pPostalAddress;
  1687. IDispatch* pDisp;
  1688. hResult = CoCreateInstance(
  1689. CLSID_PostalAddress,
  1690. NULL,
  1691. CLSCTX_ALL,
  1692. IID_IADsPostalAddress,
  1693. (void **)&pPostalAddress );
  1694. if( FAILED( hResult ) )
  1695. return hResult;
  1696. strData = pszText;
  1697. dwValues = GetValuesCount( strData, NDS_SEPARATOR );
  1698. saBound.lLbound = LBOUND;
  1699. saBound.cElements = dwValues;
  1700. pSArray = SafeArrayCreate( VT_VARIANT, 1, &saBound );
  1701. if( NULL == pSArray )
  1702. {
  1703. ASSERT( FALSE );
  1704. pPostalAddress->Release( );
  1705. return E_FAIL;
  1706. }
  1707. for( dwIdx = 0; dwIdx < dwValues ; dwIdx++ )
  1708. {
  1709. VARIANT vTemp;
  1710. VariantInit( &vTemp );
  1711. strItem = GetValueByIndex( strData, NDS_SEPARATOR, dwIdx );
  1712. V_VT( &vTemp ) = VT_BSTR;
  1713. V_BSTR( &vTemp ) = AllocBSTR( strItem.GetBuffer( strItem.GetLength( ) ) );
  1714. lIdx = (long)dwIdx + LBOUND;
  1715. hResult = SafeArrayPutElement( pSArray, &lIdx, &vTemp );
  1716. VariantClear( &vTemp );
  1717. ASSERT( SUCCEEDED( hResult ) );
  1718. }
  1719. VariantInit( &vArray );
  1720. V_VT( &vArray ) = VT_ARRAY | VT_VARIANT;
  1721. V_ARRAY( &vArray ) = pSArray;
  1722. hResult = pPostalAddress->put_PostalAddress( vArray );
  1723. ASSERT( SUCCEEDED( hResult ) );
  1724. VariantClear( &vArray );
  1725. hResult = pPostalAddress->QueryInterface( IID_IDispatch, (void**)&pDisp );
  1726. VariantInit( &rVar );
  1727. V_VT( &rVar ) = VT_DISPATCH;
  1728. V_DISPATCH( &rVar ) = pDisp;
  1729. RELEASE( pPostalAddress );
  1730. return hResult;
  1731. }
  1732. /***********************************************************
  1733. Function: COleDsNDSPostalAddress::VARIANT_2_String
  1734. Arguments:
  1735. Return:
  1736. Purpose:
  1737. Author(s):
  1738. Revision:
  1739. Date:
  1740. ***********************************************************/
  1741. HRESULT COleDsNDSPostalAddress::VARIANT_2_String( TCHAR* pszText,
  1742. VARIANT& rVar )
  1743. {
  1744. HRESULT hResult = E_FAIL;
  1745. IADsPostalAddress* pPostalAddress = NULL;
  1746. VARIANT varData;
  1747. CString strText;
  1748. while( TRUE )
  1749. {
  1750. ASSERT( VT_DISPATCH == V_VT( &rVar ) );
  1751. if( VT_DISPATCH != V_VT( &rVar ) )
  1752. break;
  1753. hResult = V_DISPATCH( &rVar )->QueryInterface( IID_IADsPostalAddress,
  1754. (void**)&pPostalAddress );
  1755. ASSERT( SUCCEEDED( hResult ) );
  1756. if( FAILED( hResult) )
  1757. break;
  1758. hResult = pPostalAddress->get_PostalAddress( &varData );
  1759. ASSERT( SUCCEEDED( hResult ) );
  1760. if( FAILED( hResult) )
  1761. break;
  1762. strText = FromVariantArrayToString( varData, NDS_SEPARATOR_S );
  1763. _tcscpy( pszText, (LPCTSTR)strText );
  1764. VariantClear( &varData );
  1765. break;
  1766. }
  1767. RELEASE( pPostalAddress )
  1768. return hResult;
  1769. }
  1770. /***********************************************************
  1771. Function: COleDsNDSFaxNumber::COleDsNDSFaxNumber
  1772. Arguments:
  1773. Return:
  1774. Purpose:
  1775. Author(s):
  1776. Revision:
  1777. Date:
  1778. ***********************************************************/
  1779. COleDsNDSFaxNumber::COleDsNDSFaxNumber ( )
  1780. {
  1781. m_dwSyntaxID = ADSTYPE_FAXNUMBER;
  1782. }
  1783. /***********************************************************
  1784. Function: COleDsNDSFaxNumber::Native2Value
  1785. Arguments:
  1786. Return:
  1787. Purpose:
  1788. Author(s):
  1789. Revision:
  1790. Date:
  1791. ***********************************************************/
  1792. HRESULT COleDsNDSFaxNumber::Native2Value( ADSVALUE* pValue,
  1793. CString& rString )
  1794. {
  1795. int nIdx;
  1796. TCHAR szText[ 256 ];
  1797. ASSERT( ADSTYPE_FAXNUMBER == pValue->dwType );
  1798. if( ADSTYPE_FAXNUMBER != pValue->dwType )
  1799. {
  1800. rString = _T("ERROR: ADSTYPE_FAXNUMBER != pValue->dwType");
  1801. return E_FAIL;
  1802. }
  1803. if( NULL == pValue->pFaxNumber )
  1804. {
  1805. ASSERT( FALSE );
  1806. rString = _T("ERROR: pValue->pFaxNumber Is NULL");
  1807. return E_FAIL;
  1808. }
  1809. nIdx = 0;
  1810. if( NULL != pValue->pFaxNumber->TelephoneNumber )
  1811. {
  1812. _stprintf( szText,
  1813. _T("%S"),
  1814. pValue->pFaxNumber->TelephoneNumber );
  1815. }
  1816. else
  1817. {
  1818. _tcscpy( szText, _T("NULL") );
  1819. }
  1820. _tcscat( szText, NDS_SEPARATOR_S );
  1821. rString = szText;
  1822. if( NULL != pValue->pFaxNumber->Parameters )
  1823. {
  1824. rString = rString + Blob2String( pValue->pFaxNumber->Parameters,
  1825. pValue->pFaxNumber->NumberOfBits );
  1826. }
  1827. else
  1828. {
  1829. rString = rString + _T("NULL");
  1830. }
  1831. return S_OK;
  1832. }
  1833. /***********************************************************
  1834. Function: COleDsNDSFaxNumber::Value2Native
  1835. Arguments:
  1836. Return:
  1837. Purpose:
  1838. Author(s):
  1839. Revision:
  1840. Date:
  1841. ***********************************************************/
  1842. HRESULT COleDsNDSFaxNumber::Value2Native( ADSVALUE* pValue,
  1843. CString& rString )
  1844. {
  1845. DWORD dwValues;
  1846. CString strTelephoneNumber;
  1847. CString strParameters;
  1848. pValue->dwType = ADSTYPE_FAXNUMBER;
  1849. dwValues = GetValuesCount( rString, NDS_SEPARATOR );
  1850. if( 2 != dwValues )
  1851. {
  1852. ASSERT( FALSE );
  1853. return E_FAIL;
  1854. }
  1855. strTelephoneNumber = GetValueByIndex( rString, NDS_SEPARATOR, 0L );
  1856. strParameters = GetValueByIndex( rString, NDS_SEPARATOR, 1L );
  1857. pValue->pFaxNumber = (ADS_FAXNUMBER*) AllocADsMem( sizeof(ADS_FAXNUMBER) );
  1858. ASSERT( NULL != pValue->pFaxNumber );
  1859. if( NULL == pValue->pFaxNumber )
  1860. {
  1861. return E_FAIL;
  1862. }
  1863. pValue->pFaxNumber->TelephoneNumber = AllocWCHAR( (LPTSTR)(LPCTSTR)strTelephoneNumber );
  1864. String2Blob( strParameters.GetBuffer( strParameters.GetLength( ) ),
  1865. (void**) (pValue->pFaxNumber->Parameters),
  1866. &(pValue->pFaxNumber->NumberOfBits) );
  1867. return S_OK;
  1868. }
  1869. /***********************************************************
  1870. Function: COleDsNDSFaxNumber::FreeAttrValue
  1871. Arguments:
  1872. Return:
  1873. Purpose:
  1874. Author(s):
  1875. Revision:
  1876. Date:
  1877. ***********************************************************/
  1878. void COleDsNDSFaxNumber::FreeAttrValue( ADSVALUE* pValue )
  1879. {
  1880. if( NULL != pValue->pFaxNumber )
  1881. {
  1882. FREE_MEMORY( pValue->pFaxNumber->TelephoneNumber );
  1883. FREE_MEMORY( pValue->pFaxNumber->Parameters );
  1884. }
  1885. FREE_MEMORY( pValue->pFaxNumber );
  1886. }
  1887. /***********************************************************
  1888. Function: COleDsNDSFaxNumber::String_2_VARIANT
  1889. Arguments:
  1890. Return:
  1891. Purpose:
  1892. Author(s):
  1893. Revision:
  1894. Date:
  1895. ***********************************************************/
  1896. HRESULT COleDsNDSFaxNumber::String_2_VARIANT( TCHAR* pszText,
  1897. VARIANT& rVar )
  1898. {
  1899. DWORD dwValues;
  1900. CString strTelephoneNumber, strVal;
  1901. CString strParameters;
  1902. HRESULT hResult;
  1903. IADsFaxNumber* pFaxNumber = NULL;
  1904. IDispatch* pDisp = NULL;
  1905. BSTR bstrVal = NULL;
  1906. VARIANT vVal;
  1907. VariantInit( &vVal );
  1908. while( TRUE )
  1909. {
  1910. hResult = CoCreateInstance(
  1911. CLSID_FaxNumber,
  1912. NULL,
  1913. CLSCTX_ALL,
  1914. IID_IADsFaxNumber,
  1915. (void **)&pFaxNumber);
  1916. ASSERT( SUCCEEDED( hResult ) );
  1917. if( FAILED( hResult ) )
  1918. break;
  1919. strVal = pszText;
  1920. dwValues = GetValuesCount( strVal, NDS_SEPARATOR );
  1921. if( 2 != dwValues )
  1922. {
  1923. hResult = E_FAIL;
  1924. ASSERT( FALSE );
  1925. break;
  1926. }
  1927. strTelephoneNumber= GetValueByIndex( strVal, NDS_SEPARATOR, 0L );
  1928. strParameters = GetValueByIndex( strVal, NDS_SEPARATOR, 1L );
  1929. bstrVal = AllocBSTR( strTelephoneNumber.GetBuffer( strTelephoneNumber.GetLength( ) ) );
  1930. hResult = pFaxNumber->put_TelephoneNumber( bstrVal );
  1931. ASSERT( SUCCEEDED( hResult ) );
  1932. hResult = CreateBlobArray( strParameters, vVal );
  1933. ASSERT( SUCCEEDED( hResult ) );
  1934. hResult = pFaxNumber->put_Parameters( vVal );
  1935. ASSERT( SUCCEEDED( hResult ) );
  1936. hResult = pFaxNumber->QueryInterface( IID_IDispatch, (void**)&pDisp );
  1937. ASSERT( SUCCEEDED( hResult ) );
  1938. V_VT( &rVar ) = VT_DISPATCH;
  1939. V_DISPATCH( &rVar ) = pDisp;
  1940. break;
  1941. }
  1942. SysFreeString( bstrVal );
  1943. VariantClear( &vVal );
  1944. RELEASE( pFaxNumber );
  1945. return hResult;
  1946. }
  1947. /***********************************************************
  1948. Function: COleDsNDSFaxNumber::VARIANT_2_String
  1949. Arguments:
  1950. Return:
  1951. Purpose:
  1952. Author(s):
  1953. Revision:
  1954. Date:
  1955. ***********************************************************/
  1956. HRESULT COleDsNDSFaxNumber::VARIANT_2_String( TCHAR* pszText,
  1957. VARIANT& rVar )
  1958. {
  1959. HRESULT hResult = E_FAIL;
  1960. IADsFaxNumber* pFaxNumber = NULL;
  1961. VARIANT vParameters;
  1962. BSTR bstrTelephoneNumber = NULL;
  1963. CString strText;
  1964. VariantInit( &vParameters );
  1965. while( TRUE )
  1966. {
  1967. ASSERT( VT_DISPATCH == V_VT( &rVar ) );
  1968. if( VT_DISPATCH != V_VT( &rVar ) )
  1969. break;
  1970. hResult = V_DISPATCH( &rVar )->QueryInterface( IID_IADsFaxNumber,
  1971. (void**)&pFaxNumber );
  1972. ASSERT( SUCCEEDED( hResult ) );
  1973. if( FAILED( hResult) )
  1974. break;
  1975. hResult = pFaxNumber->get_TelephoneNumber( &bstrTelephoneNumber );
  1976. ASSERT( SUCCEEDED( hResult ) );
  1977. if( FAILED( hResult) )
  1978. break;
  1979. hResult = pFaxNumber->get_Parameters( &vParameters );
  1980. ASSERT( SUCCEEDED( hResult ) );
  1981. if( FAILED( hResult) )
  1982. break;
  1983. Convert( pszText, bstrTelephoneNumber );
  1984. _tcscat( pszText, NDS_SEPARATOR_S );
  1985. strText = FromVariantToString( vParameters );
  1986. _tcscat( pszText, (LPCTSTR)strText );
  1987. break;
  1988. }
  1989. SysFreeString( bstrTelephoneNumber );
  1990. VariantClear( &vParameters );
  1991. RELEASE( pFaxNumber );
  1992. return hResult;
  1993. }
  1994. /***********************************************************
  1995. Function: COleDsNDSEMail::COleDsNDSEMail
  1996. Arguments:
  1997. Return:
  1998. Purpose:
  1999. Author(s):
  2000. Revision:
  2001. Date:
  2002. ***********************************************************/
  2003. COleDsNDSEMail::COleDsNDSEMail ( )
  2004. {
  2005. m_dwSyntaxID = ADSTYPE_EMAIL;
  2006. }
  2007. /***********************************************************
  2008. Function: COleDsNDSEMail::Native2Value
  2009. Arguments:
  2010. Return:
  2011. Purpose:
  2012. Author(s):
  2013. Revision:
  2014. Date:
  2015. ***********************************************************/
  2016. HRESULT COleDsNDSEMail::Native2Value( ADSVALUE* pValue,
  2017. CString& rString )
  2018. {
  2019. int nIdx;
  2020. TCHAR szText[ 256 ];
  2021. ASSERT( ADSTYPE_EMAIL == pValue->dwType );
  2022. if( ADSTYPE_EMAIL != pValue->dwType )
  2023. {
  2024. rString = _T("ERROR: ADSTYPE_EMAIL != pValue->dwType");
  2025. return E_FAIL;
  2026. }
  2027. nIdx = 0;
  2028. if( NULL != pValue->Email.Address )
  2029. {
  2030. _stprintf( szText,
  2031. _T("%ld & %S"),
  2032. pValue->Email.Type,
  2033. pValue->Email.Address );
  2034. }
  2035. else
  2036. {
  2037. _stprintf( szText,
  2038. _T("%ld & NULL"),
  2039. pValue->Email.Type );
  2040. }
  2041. rString = szText;
  2042. return S_OK;
  2043. }
  2044. /***********************************************************
  2045. Function: COleDsNDSEMail::Value2Native
  2046. Arguments:
  2047. Return:
  2048. Purpose:
  2049. Author(s):
  2050. Revision:
  2051. Date:
  2052. ***********************************************************/
  2053. HRESULT COleDsNDSEMail::Value2Native( ADSVALUE* pValue,
  2054. CString& rString )
  2055. {
  2056. DWORD dwValues, dwSize;
  2057. CString strNumber;
  2058. CString strAddress;
  2059. pValue->dwType = ADSTYPE_EMAIL;
  2060. dwValues = GetValuesCount( rString, NDS_SEPARATOR );
  2061. if( 2 != dwValues )
  2062. {
  2063. ASSERT( FALSE );
  2064. return E_FAIL;
  2065. }
  2066. strNumber = GetValueByIndex( rString, NDS_SEPARATOR, 0L );
  2067. strAddress = GetValueByIndex( rString, NDS_SEPARATOR, 1L );
  2068. pValue->Email.Type = (DWORD)_ttol( (LPCTSTR) strNumber );
  2069. dwSize = strAddress.GetLength( ) + 1;
  2070. dwSize = dwSize * sizeof(WCHAR);
  2071. pValue->Email.Address = (LPWSTR) AllocADsMem( dwSize );
  2072. Convert( pValue->Email.Address, strAddress.GetBuffer( strAddress.GetLength( ) ) );
  2073. return S_OK;
  2074. }
  2075. /***********************************************************
  2076. Function: COleDsNDSEMail::FreeAttrValue
  2077. Arguments:
  2078. Return:
  2079. Purpose:
  2080. Author(s):
  2081. Revision:
  2082. Date:
  2083. ***********************************************************/
  2084. void COleDsNDSEMail::FreeAttrValue( ADSVALUE* pValue )
  2085. {
  2086. FREE_MEMORY( pValue->Email.Address );
  2087. }
  2088. /***********************************************************
  2089. Function: COleDsNDSEMail::String_2_VARIANT
  2090. Arguments:
  2091. Return:
  2092. Purpose:
  2093. Author(s):
  2094. Revision:
  2095. Date:
  2096. ***********************************************************/
  2097. HRESULT COleDsNDSEMail::String_2_VARIANT( TCHAR* pszText,
  2098. VARIANT& rVar )
  2099. {
  2100. DWORD dwValues;
  2101. CString strNumber, strVal;
  2102. CString strAddress;
  2103. HRESULT hResult;
  2104. IADsEmail* pEMail = NULL;
  2105. IDispatch* pDisp = NULL;
  2106. BSTR bstrVal = NULL;
  2107. while( TRUE )
  2108. {
  2109. hResult = CoCreateInstance(
  2110. CLSID_Email,
  2111. NULL,
  2112. CLSCTX_ALL,
  2113. IID_IADsEmail,
  2114. (void **)&pEMail);
  2115. ASSERT( SUCCEEDED( hResult ) );
  2116. if( FAILED( hResult ) )
  2117. break;
  2118. strVal = pszText;
  2119. dwValues = GetValuesCount( strVal, NDS_SEPARATOR );
  2120. if( 2 != dwValues )
  2121. {
  2122. hResult = E_FAIL;
  2123. ASSERT( FALSE );
  2124. break;
  2125. }
  2126. strNumber = GetValueByIndex( strVal, NDS_SEPARATOR, 0L );
  2127. strAddress = GetValueByIndex( strVal, NDS_SEPARATOR, 1L );
  2128. hResult = pEMail->put_Type( _ttol( (LPCTSTR) strNumber ) );
  2129. ASSERT( SUCCEEDED( hResult ) );
  2130. bstrVal = AllocBSTR( strAddress.GetBuffer( strAddress.GetLength( ) ) );
  2131. hResult = pEMail->put_Address( bstrVal );
  2132. ASSERT( SUCCEEDED( hResult ) );
  2133. hResult = pEMail->QueryInterface( IID_IDispatch, (void**)&pDisp );
  2134. ASSERT( SUCCEEDED( hResult ) );
  2135. V_VT( &rVar ) = VT_DISPATCH;
  2136. V_DISPATCH( &rVar ) = pDisp;
  2137. break;
  2138. }
  2139. SysFreeString( bstrVal );
  2140. RELEASE( pEMail );
  2141. return hResult;
  2142. }
  2143. /***********************************************************
  2144. Function: COleDsNDSEMail::VARIANT_2_String
  2145. Arguments:
  2146. Return:
  2147. Purpose:
  2148. Author(s):
  2149. Revision:
  2150. Date:
  2151. ***********************************************************/
  2152. HRESULT COleDsNDSEMail::VARIANT_2_String( TCHAR* pszText,
  2153. VARIANT& rVar )
  2154. {
  2155. HRESULT hResult = E_FAIL;
  2156. IADsEmail* pEmail = NULL;
  2157. LONG lType;
  2158. BSTR bstrVal = NULL;
  2159. while( TRUE )
  2160. {
  2161. ASSERT( VT_DISPATCH == V_VT( &rVar ) );
  2162. if( VT_DISPATCH != V_VT( &rVar ) )
  2163. break;
  2164. hResult = V_DISPATCH( &rVar )->QueryInterface( IID_IADsEmail,
  2165. (void**)&pEmail );
  2166. ASSERT( SUCCEEDED( hResult ) );
  2167. if( FAILED( hResult) )
  2168. break;
  2169. hResult = pEmail->get_Type( &lType );
  2170. ASSERT( SUCCEEDED( hResult ) );
  2171. if( FAILED( hResult) )
  2172. break;
  2173. hResult = pEmail->get_Address( &bstrVal );
  2174. ASSERT( SUCCEEDED( hResult ) );
  2175. if( FAILED( hResult) )
  2176. break;
  2177. _ltot( lType, pszText, 10 );
  2178. _tcscat( pszText, NDS_SEPARATOR_S );
  2179. Convert( pszText + _tcslen(pszText), bstrVal );
  2180. break;
  2181. }
  2182. SysFreeString( bstrVal );
  2183. RELEASE( pEmail );
  2184. return hResult;
  2185. }
  2186. /***********************************************************
  2187. Function: COleDsNDSTypedName::COleDsNDSTypedName
  2188. Arguments:
  2189. Return:
  2190. Purpose:
  2191. Author(s):
  2192. Revision:
  2193. Date:
  2194. ***********************************************************/
  2195. COleDsNDSTypedName::COleDsNDSTypedName( )
  2196. {
  2197. m_dwSyntaxID = ADSTYPE_TYPEDNAME;
  2198. }
  2199. /***********************************************************
  2200. Function: COleDsNDSTypedName::Native2Value
  2201. Arguments:
  2202. Return:
  2203. Purpose:
  2204. Author(s):
  2205. Revision:
  2206. Date:
  2207. ***********************************************************/
  2208. HRESULT COleDsNDSTypedName::Native2Value( ADSVALUE* pValue,
  2209. CString& rString )
  2210. {
  2211. int nIdx;
  2212. TCHAR szText[ 256 ];
  2213. ASSERT( ADSTYPE_TYPEDNAME == pValue->dwType );
  2214. if( ADSTYPE_TYPEDNAME != pValue->dwType )
  2215. {
  2216. rString = _T("ERROR: ADSTYPE_TYPEDNAME != pValue->dwType");
  2217. return E_FAIL;
  2218. }
  2219. if( NULL == pValue->pTypedName )
  2220. {
  2221. ASSERT( FALSE );
  2222. return E_FAIL;
  2223. }
  2224. nIdx = 0;
  2225. if( NULL != pValue->pTypedName->ObjectName )
  2226. {
  2227. _stprintf( szText,
  2228. _T("%S & %ld & %ld"),
  2229. pValue->pTypedName->ObjectName,
  2230. pValue->pTypedName->Level,
  2231. pValue->pTypedName->Interval );
  2232. }
  2233. else
  2234. {
  2235. _stprintf( szText,
  2236. _T("NULL & %ld & %ld"),
  2237. pValue->pTypedName->Level,
  2238. pValue->pTypedName->Interval );
  2239. }
  2240. rString = szText;
  2241. return S_OK;
  2242. }
  2243. /***********************************************************
  2244. Function: COleDsNDSTypedName::Value2Native
  2245. Arguments:
  2246. Return:
  2247. Purpose:
  2248. Author(s):
  2249. Revision:
  2250. Date:
  2251. ***********************************************************/
  2252. HRESULT COleDsNDSTypedName::Value2Native( ADSVALUE* pValue,
  2253. CString& rString )
  2254. {
  2255. DWORD dwValues;
  2256. CString strLevel;
  2257. CString strInterval;
  2258. CString strObjectName;
  2259. pValue->dwType = ADSTYPE_TYPEDNAME;
  2260. dwValues = GetValuesCount( rString, NDS_SEPARATOR );
  2261. if( 3 != dwValues )
  2262. {
  2263. ASSERT( FALSE );
  2264. return E_FAIL;
  2265. }
  2266. pValue->pTypedName = (ADS_TYPEDNAME*) AllocADsMem( sizeof(ADS_TYPEDNAME) );
  2267. strObjectName = GetValueByIndex( rString, NDS_SEPARATOR, 0L );
  2268. strLevel = GetValueByIndex( rString, NDS_SEPARATOR, 1L );
  2269. strInterval = GetValueByIndex( rString, NDS_SEPARATOR, 2L );
  2270. pValue->pTypedName->Level = (DWORD)_ttol( (LPCTSTR) strLevel );
  2271. pValue->pTypedName->Interval = (DWORD)_ttol( (LPCTSTR) strInterval );
  2272. pValue->pTypedName->ObjectName= AllocWCHAR( (TCHAR*)(LPCTSTR)strObjectName );
  2273. return S_OK;
  2274. }
  2275. /***********************************************************
  2276. Function: COleDsNDSTypedName::FreeAttrValue
  2277. Arguments:
  2278. Return:
  2279. Purpose:
  2280. Author(s):
  2281. Revision:
  2282. Date:
  2283. ***********************************************************/
  2284. void COleDsNDSTypedName::FreeAttrValue( ADSVALUE* pValue )
  2285. {
  2286. FREE_MEMORY( pValue->pTypedName->ObjectName );
  2287. FREE_MEMORY( pValue->pTypedName );
  2288. }
  2289. /***********************************************************
  2290. Function: COleDsNDSEMail::String_2_VARIANT
  2291. Arguments:
  2292. Return:
  2293. Purpose:
  2294. Author(s):
  2295. Revision:
  2296. Date:
  2297. ***********************************************************/
  2298. HRESULT COleDsNDSTypedName::String_2_VARIANT( TCHAR* pszText,
  2299. VARIANT& rVar )
  2300. {
  2301. DWORD dwValues;
  2302. CString strLevel, strVal;
  2303. CString strInterval;
  2304. CString strObjectName;
  2305. HRESULT hResult;
  2306. IADsTypedName* pTypedName = NULL;
  2307. IDispatch* pDisp = NULL;
  2308. BSTR bstrObjectName = NULL;
  2309. while( TRUE )
  2310. {
  2311. hResult = CoCreateInstance(
  2312. CLSID_TypedName,
  2313. NULL,
  2314. CLSCTX_ALL,
  2315. IID_IADsTypedName,
  2316. (void **)&pTypedName );
  2317. ASSERT( SUCCEEDED( hResult ) );
  2318. if( FAILED( hResult ) )
  2319. break;
  2320. strVal = pszText;
  2321. dwValues = GetValuesCount( strVal, NDS_SEPARATOR );
  2322. if( 3 != dwValues )
  2323. {
  2324. hResult = E_FAIL;
  2325. ASSERT( FALSE );
  2326. break;
  2327. }
  2328. strObjectName = GetValueByIndex( strVal, NDS_SEPARATOR, 0L );
  2329. strLevel = GetValueByIndex( strVal, NDS_SEPARATOR, 1L );
  2330. strInterval = GetValueByIndex( strVal, NDS_SEPARATOR, 2L );
  2331. hResult = pTypedName->put_Level( _ttol( (LPCTSTR) strLevel ) );
  2332. ASSERT( SUCCEEDED( hResult ) );
  2333. hResult = pTypedName->put_Interval( _ttol( (LPCTSTR) strInterval ) );
  2334. ASSERT( SUCCEEDED( hResult ) );
  2335. bstrObjectName = AllocBSTR( strObjectName.GetBuffer( strObjectName.GetLength( ) ) );
  2336. hResult = pTypedName->put_ObjectName( bstrObjectName );
  2337. ASSERT( SUCCEEDED( hResult ) );
  2338. hResult = pTypedName->QueryInterface( IID_IDispatch, (void**)&pDisp );
  2339. ASSERT( SUCCEEDED( hResult ) );
  2340. V_VT( &rVar ) = VT_DISPATCH;
  2341. V_DISPATCH( &rVar ) = pDisp;
  2342. break;
  2343. }
  2344. SysFreeString( bstrObjectName );
  2345. RELEASE( pTypedName );
  2346. return hResult;
  2347. }
  2348. /***********************************************************
  2349. Function: COleDsNDSTypedName::VARIANT_2_String
  2350. Arguments:
  2351. Return:
  2352. Purpose:
  2353. Author(s):
  2354. Revision:
  2355. Date:
  2356. ***********************************************************/
  2357. HRESULT COleDsNDSTypedName::VARIANT_2_String( TCHAR* pszText,
  2358. VARIANT& rVar )
  2359. {
  2360. HRESULT hResult = E_FAIL;
  2361. IADsTypedName* pTypedName = NULL;
  2362. LONG lLevel, lInterval;
  2363. BSTR bstrObjectName = NULL;
  2364. while( TRUE )
  2365. {
  2366. ASSERT( VT_DISPATCH == V_VT( &rVar ) );
  2367. if( VT_DISPATCH != V_VT( &rVar ) )
  2368. break;
  2369. hResult = V_DISPATCH( &rVar )->QueryInterface( IID_IADsTypedName,
  2370. (void**)&pTypedName );
  2371. ASSERT( SUCCEEDED( hResult ) );
  2372. if( FAILED( hResult) )
  2373. break;
  2374. hResult = pTypedName->get_Level( &lLevel );
  2375. ASSERT( SUCCEEDED( hResult ) );
  2376. if( FAILED( hResult) )
  2377. break;
  2378. hResult = pTypedName->get_Interval( &lInterval );
  2379. ASSERT( SUCCEEDED( hResult ) );
  2380. if( FAILED( hResult) )
  2381. break;
  2382. hResult = pTypedName->get_ObjectName( &bstrObjectName );
  2383. ASSERT( SUCCEEDED( hResult ) );
  2384. if( FAILED( hResult) )
  2385. break;
  2386. Convert( pszText, bstrObjectName );
  2387. _tcscat( pszText, NDS_SEPARATOR_S );
  2388. _ltot( lLevel, pszText + _tcslen( pszText), 10 );
  2389. _tcscat( pszText, NDS_SEPARATOR_S );
  2390. _ltot( lInterval, pszText + _tcslen( pszText), 10 );
  2391. break;
  2392. }
  2393. SysFreeString( bstrObjectName );
  2394. RELEASE( pTypedName );
  2395. return hResult;
  2396. }
  2397. /***********************************************************
  2398. Function: COleDsNDSHold::COleDsNDSHold
  2399. Arguments:
  2400. Return:
  2401. Purpose:
  2402. Author(s):
  2403. Revision:
  2404. Date:
  2405. ***********************************************************/
  2406. COleDsNDSHold::COleDsNDSHold( )
  2407. {
  2408. m_dwSyntaxID = ADSTYPE_HOLD;
  2409. }
  2410. /***********************************************************
  2411. Function: COleDsNDSHold::Native2Value
  2412. Arguments:
  2413. Return:
  2414. Purpose:
  2415. Author(s):
  2416. Revision:
  2417. Date:
  2418. ***********************************************************/
  2419. HRESULT COleDsNDSHold::Native2Value( ADSVALUE* pValue,
  2420. CString& rString )
  2421. {
  2422. int nIdx;
  2423. TCHAR szText[ 256 ];
  2424. ASSERT( ADSTYPE_HOLD == pValue->dwType );
  2425. if( ADSTYPE_HOLD != pValue->dwType )
  2426. {
  2427. rString = _T("ERROR: ADSTYPE_HOLD != pValue->dwType");
  2428. return E_FAIL;
  2429. }
  2430. nIdx = 0;
  2431. if( NULL != pValue->Hold.ObjectName )
  2432. {
  2433. _stprintf( szText,
  2434. _T("%ld & %S"),
  2435. pValue->Hold.Amount,
  2436. pValue->Hold.ObjectName );
  2437. }
  2438. else
  2439. {
  2440. _stprintf( szText,
  2441. _T("NULL & %ld "),
  2442. pValue->Hold.Amount );
  2443. }
  2444. rString = szText;
  2445. return S_OK;
  2446. }
  2447. /***********************************************************
  2448. Function: COleDsNDSHold::Value2Native
  2449. Arguments:
  2450. Return:
  2451. Purpose:
  2452. Author(s):
  2453. Revision:
  2454. Date:
  2455. ***********************************************************/
  2456. HRESULT COleDsNDSHold::Value2Native( ADSVALUE* pValue,
  2457. CString& rString )
  2458. {
  2459. DWORD dwValues;
  2460. CString strAmount;
  2461. CString strObjectName;
  2462. pValue->dwType = ADSTYPE_HOLD;
  2463. dwValues = GetValuesCount( rString, NDS_SEPARATOR );
  2464. if( 2 != dwValues )
  2465. {
  2466. ASSERT( FALSE );
  2467. return E_FAIL;
  2468. }
  2469. strAmount = GetValueByIndex( rString, NDS_SEPARATOR, 1L );
  2470. strObjectName = GetValueByIndex( rString, NDS_SEPARATOR, 0L );
  2471. pValue->Hold.Amount = (DWORD)_ttol( (LPCTSTR) strAmount );
  2472. pValue->Hold.ObjectName = AllocWCHAR( (TCHAR*)(LPCTSTR)strObjectName );
  2473. return S_OK;
  2474. }
  2475. /***********************************************************
  2476. Function: COleDsNDSHold::FreeAttrValue
  2477. Arguments:
  2478. Return:
  2479. Purpose:
  2480. Author(s):
  2481. Revision:
  2482. Date:
  2483. ***********************************************************/
  2484. void COleDsNDSHold::FreeAttrValue( ADSVALUE* pValue )
  2485. {
  2486. FREE_MEMORY( pValue->Hold.ObjectName );
  2487. }
  2488. /***********************************************************
  2489. Function: COleDsNDSEMail::String_2_VARIANT
  2490. Arguments:
  2491. Return:
  2492. Purpose:
  2493. Author(s):
  2494. Revision:
  2495. Date:
  2496. ***********************************************************/
  2497. HRESULT COleDsNDSHold::String_2_VARIANT( TCHAR* pszText,
  2498. VARIANT& rVar )
  2499. {
  2500. DWORD dwValues;
  2501. CString strAmount, strVal;
  2502. CString strObjectName;
  2503. HRESULT hResult;
  2504. IADsHold* pHold = NULL;
  2505. IDispatch* pDisp = NULL;
  2506. BSTR bstrObjectName = NULL;
  2507. while( TRUE )
  2508. {
  2509. hResult = CoCreateInstance(
  2510. CLSID_Hold,
  2511. NULL,
  2512. CLSCTX_ALL,
  2513. IID_IADsHold,
  2514. (void **)&pHold );
  2515. ASSERT( SUCCEEDED( hResult ) );
  2516. if( FAILED( hResult ) )
  2517. break;
  2518. strVal = pszText;
  2519. dwValues = GetValuesCount( strVal, NDS_SEPARATOR );
  2520. if( 2 != dwValues )
  2521. {
  2522. hResult = E_FAIL;
  2523. ASSERT( FALSE );
  2524. break;
  2525. }
  2526. strAmount = GetValueByIndex( strVal, NDS_SEPARATOR, 1L );
  2527. strObjectName = GetValueByIndex( strVal, NDS_SEPARATOR, 0L );
  2528. hResult = pHold->put_Amount( _ttol( (LPCTSTR) strAmount ) );
  2529. ASSERT( SUCCEEDED( hResult ) );
  2530. bstrObjectName = AllocBSTR( strObjectName.GetBuffer( strObjectName.GetLength( ) ) );
  2531. hResult = pHold->put_ObjectName( bstrObjectName );
  2532. ASSERT( SUCCEEDED( hResult ) );
  2533. hResult = pHold->QueryInterface( IID_IDispatch, (void**)&pDisp );
  2534. ASSERT( SUCCEEDED( hResult ) );
  2535. V_VT( &rVar ) = VT_DISPATCH;
  2536. V_DISPATCH( &rVar ) = pDisp;
  2537. break;
  2538. }
  2539. SysFreeString( bstrObjectName );
  2540. RELEASE( pHold );
  2541. return hResult;
  2542. }
  2543. /***********************************************************
  2544. Function: COleDsNDSHold::VARIANT_2_String
  2545. Arguments:
  2546. Return:
  2547. Purpose:
  2548. Author(s):
  2549. Revision:
  2550. Date:
  2551. ***********************************************************/
  2552. HRESULT COleDsNDSHold::VARIANT_2_String( TCHAR* pszText,
  2553. VARIANT& rVar )
  2554. {
  2555. HRESULT hResult = E_FAIL;
  2556. IADsHold* pHold = NULL;
  2557. LONG lAmount;
  2558. BSTR bstrObjectName = NULL;
  2559. while( TRUE )
  2560. {
  2561. ASSERT( VT_DISPATCH == V_VT( &rVar ) );
  2562. if( VT_DISPATCH != V_VT( &rVar ) )
  2563. break;
  2564. hResult = V_DISPATCH( &rVar )->QueryInterface( IID_IADsHold,
  2565. (void**)&pHold );
  2566. ASSERT( SUCCEEDED( hResult ) );
  2567. if( FAILED( hResult) )
  2568. break;
  2569. hResult = pHold->get_Amount( &lAmount );
  2570. ASSERT( SUCCEEDED( hResult ) );
  2571. if( FAILED( hResult) )
  2572. break;
  2573. hResult = pHold->get_ObjectName( &bstrObjectName );
  2574. ASSERT( SUCCEEDED( hResult ) );
  2575. if( FAILED( hResult) )
  2576. break;
  2577. Convert( pszText, bstrObjectName );
  2578. _tcscat( pszText, NDS_SEPARATOR_S );
  2579. _ltot( lAmount, pszText + _tcslen( pszText), 10 );
  2580. break;
  2581. }
  2582. SysFreeString( bstrObjectName );
  2583. RELEASE( pHold );
  2584. return hResult;
  2585. }
  2586. /***********************************************************
  2587. Function: COleDsNDSBackLink::COleDsNDSBackLink
  2588. Arguments:
  2589. Return:
  2590. Purpose:
  2591. Author(s):
  2592. Revision:
  2593. Date:
  2594. ***********************************************************/
  2595. COleDsNDSBackLink::COleDsNDSBackLink( )
  2596. {
  2597. m_dwSyntaxID = ADSTYPE_BACKLINK;
  2598. }
  2599. /***********************************************************
  2600. Function: COleDsNDSBackLink::Native2Value
  2601. Arguments:
  2602. Return:
  2603. Purpose:
  2604. Author(s):
  2605. Revision:
  2606. Date:
  2607. ***********************************************************/
  2608. HRESULT COleDsNDSBackLink::Native2Value( ADSVALUE* pValue,
  2609. CString& rString )
  2610. {
  2611. int nIdx;
  2612. TCHAR szText[ 256 ];
  2613. ASSERT( ADSTYPE_BACKLINK == pValue->dwType );
  2614. if( ADSTYPE_BACKLINK != pValue->dwType )
  2615. {
  2616. rString = _T("ERROR: ADSTYPE_BACKLINK != pValue->dwType");
  2617. return E_FAIL;
  2618. }
  2619. nIdx = 0;
  2620. if( NULL != pValue->BackLink.ObjectName )
  2621. {
  2622. _stprintf( szText,
  2623. _T("%ld & %S"),
  2624. pValue->BackLink.RemoteID,
  2625. pValue->BackLink.ObjectName );
  2626. }
  2627. else
  2628. {
  2629. _stprintf( szText,
  2630. _T("%ld & NULL"),
  2631. pValue->BackLink.RemoteID );
  2632. }
  2633. rString = szText;
  2634. return S_OK;
  2635. }
  2636. /***********************************************************
  2637. Function: COleDsNDSBackLink::Value2Native
  2638. Arguments:
  2639. Return:
  2640. Purpose:
  2641. Author(s):
  2642. Revision:
  2643. Date:
  2644. ***********************************************************/
  2645. HRESULT COleDsNDSBackLink::Value2Native( ADSVALUE* pValue,
  2646. CString& rString )
  2647. {
  2648. DWORD dwValues;
  2649. CString strRemoteID;
  2650. CString strObjectName;
  2651. pValue->dwType = ADSTYPE_BACKLINK;
  2652. dwValues = GetValuesCount( rString, NDS_SEPARATOR );
  2653. if( 2 != dwValues )
  2654. {
  2655. ASSERT( FALSE );
  2656. return E_FAIL;
  2657. }
  2658. strRemoteID = GetValueByIndex( rString, NDS_SEPARATOR, 0L );
  2659. strObjectName = GetValueByIndex( rString, NDS_SEPARATOR, 1L );
  2660. pValue->BackLink.RemoteID = (DWORD)_ttol( (LPCTSTR) strRemoteID );
  2661. pValue->BackLink.ObjectName = AllocWCHAR( (TCHAR*)(LPCTSTR)strObjectName );
  2662. return S_OK;
  2663. }
  2664. /***********************************************************
  2665. Function: COleDsNDSBackLink::FreeAttrValue
  2666. Arguments:
  2667. Return:
  2668. Purpose:
  2669. Author(s):
  2670. Revision:
  2671. Date:
  2672. ***********************************************************/
  2673. void COleDsNDSBackLink::FreeAttrValue( ADSVALUE* pValue )
  2674. {
  2675. FREE_MEMORY( pValue->BackLink.ObjectName );
  2676. }
  2677. /***********************************************************
  2678. Function: COleDsNDSEMail::String_2_VARIANT
  2679. Arguments:
  2680. Return:
  2681. Purpose:
  2682. Author(s):
  2683. Revision:
  2684. Date:
  2685. ***********************************************************/
  2686. HRESULT COleDsNDSBackLink::String_2_VARIANT( TCHAR* pszText,
  2687. VARIANT& rVar )
  2688. {
  2689. DWORD dwValues;
  2690. CString strRemoteID, strVal;
  2691. CString strObjectName;
  2692. HRESULT hResult;
  2693. IADsBackLink* pBackLink = NULL;
  2694. IDispatch* pDisp = NULL;
  2695. BSTR bstrObjectName = NULL;
  2696. while( TRUE )
  2697. {
  2698. hResult = CoCreateInstance(
  2699. CLSID_BackLink,
  2700. NULL,
  2701. CLSCTX_ALL,
  2702. IID_IADsBackLink,
  2703. (void **)&pBackLink );
  2704. ASSERT( SUCCEEDED( hResult ) );
  2705. if( FAILED( hResult ) )
  2706. break;
  2707. strVal = pszText;
  2708. dwValues = GetValuesCount( strVal, NDS_SEPARATOR );
  2709. if( 2 != dwValues )
  2710. {
  2711. hResult = E_FAIL;
  2712. ASSERT( FALSE );
  2713. break;
  2714. }
  2715. strRemoteID = GetValueByIndex( strVal, NDS_SEPARATOR, 0L );
  2716. strObjectName = GetValueByIndex( strVal, NDS_SEPARATOR, 1L );
  2717. hResult = pBackLink->put_RemoteID( _ttol( (LPCTSTR) strRemoteID ) );
  2718. ASSERT( SUCCEEDED( hResult ) );
  2719. bstrObjectName = AllocBSTR( strObjectName.GetBuffer( strObjectName.GetLength( ) ) );
  2720. hResult = pBackLink->put_ObjectName( bstrObjectName );
  2721. ASSERT( SUCCEEDED( hResult ) );
  2722. hResult = pBackLink->QueryInterface( IID_IDispatch, (void**)&pDisp );
  2723. ASSERT( SUCCEEDED( hResult ) );
  2724. V_VT( &rVar ) = VT_DISPATCH;
  2725. V_DISPATCH( &rVar ) = pDisp;
  2726. break;
  2727. }
  2728. SysFreeString( bstrObjectName );
  2729. RELEASE( pBackLink );
  2730. return hResult;
  2731. }
  2732. /***********************************************************
  2733. Function: COleDsNDSBackLink::VARIANT_2_String
  2734. Arguments:
  2735. Return:
  2736. Purpose:
  2737. Author(s):
  2738. Revision:
  2739. Date:
  2740. ***********************************************************/
  2741. HRESULT COleDsNDSBackLink::VARIANT_2_String( TCHAR* pszText,
  2742. VARIANT& rVar )
  2743. {
  2744. HRESULT hResult = E_FAIL;
  2745. IADsBackLink* pBackLink = NULL;
  2746. LONG lRemoteID;
  2747. BSTR bstrObjectName = NULL;
  2748. while( TRUE )
  2749. {
  2750. ASSERT( VT_DISPATCH == V_VT( &rVar ) );
  2751. if( VT_DISPATCH != V_VT( &rVar ) )
  2752. break;
  2753. hResult = V_DISPATCH( &rVar )->QueryInterface( IID_IADsBackLink,
  2754. (void**)&pBackLink );
  2755. ASSERT( SUCCEEDED( hResult ) );
  2756. if( FAILED( hResult) )
  2757. break;
  2758. hResult = pBackLink->get_RemoteID( &lRemoteID );
  2759. ASSERT( SUCCEEDED( hResult ) );
  2760. if( FAILED( hResult) )
  2761. break;
  2762. hResult = pBackLink->get_ObjectName( &bstrObjectName );
  2763. ASSERT( SUCCEEDED( hResult ) );
  2764. if( FAILED( hResult) )
  2765. break;
  2766. _ltot( lRemoteID, pszText, 10 );
  2767. _tcscat( pszText, NDS_SEPARATOR_S );
  2768. Convert( pszText + _tcslen(pszText), bstrObjectName );
  2769. break;
  2770. }
  2771. SysFreeString( bstrObjectName );
  2772. RELEASE( pBackLink );
  2773. return hResult;
  2774. }
  2775. /***********************************************************
  2776. Function: COleDsNDSPostalAddress::COleDsNDSPostalAddress
  2777. Arguments:
  2778. Return:
  2779. Purpose:
  2780. Author(s):
  2781. Revision:
  2782. Date:
  2783. ***********************************************************/
  2784. COleDsNDSPath::COleDsNDSPath ( )
  2785. {
  2786. m_dwSyntaxID = ADSTYPE_PATH;
  2787. }
  2788. /***********************************************************
  2789. Function: COleDsNDSPath::Native2Value
  2790. Arguments:
  2791. Return:
  2792. Purpose:
  2793. Author(s):
  2794. Revision:
  2795. Date:
  2796. ***********************************************************/
  2797. HRESULT COleDsNDSPath::Native2Value( ADSVALUE* pValue,
  2798. CString& rString )
  2799. {
  2800. int nIdx;
  2801. TCHAR szText[ 256 ];
  2802. ASSERT( ADSTYPE_PATH == pValue->dwType );
  2803. if( ADSTYPE_PATH != pValue->dwType )
  2804. {
  2805. rString = _T("ERROR: ADSTYPE_PATH != pValue->dwType");
  2806. return E_FAIL;
  2807. }
  2808. nIdx = 0;
  2809. if( NULL != pValue->pPath )
  2810. {
  2811. _stprintf( szText,
  2812. _T("%ld & %S & %S"),
  2813. pValue->pPath->Type,
  2814. pValue->pPath->VolumeName,
  2815. pValue->pPath->Path);
  2816. }
  2817. else
  2818. {
  2819. _stprintf( szText,
  2820. _T("%ld & NULL & NULL"),
  2821. pValue->pPath->Type );
  2822. }
  2823. rString = szText;
  2824. return S_OK;
  2825. }
  2826. /***********************************************************
  2827. Function: COleDsNDSPath::Value2Native
  2828. Arguments:
  2829. Return:
  2830. Purpose:
  2831. Author(s):
  2832. Revision:
  2833. Date:
  2834. ***********************************************************/
  2835. HRESULT COleDsNDSPath::Value2Native( ADSVALUE* pValue,
  2836. CString& rString )
  2837. {
  2838. DWORD dwValues;
  2839. CString strType;
  2840. CString strVolName;
  2841. CString strPath;
  2842. pValue->pPath = (ADS_PATH*) AllocADsMem( sizeof(ADS_PATH) );
  2843. if( NULL == pValue->pPath )
  2844. return E_FAIL;
  2845. pValue->pPath->VolumeName = NULL;
  2846. pValue->pPath->Path = NULL;
  2847. pValue->dwType = ADSTYPE_PATH;
  2848. dwValues = GetValuesCount( rString, NDS_SEPARATOR );
  2849. if( 3 != dwValues )
  2850. {
  2851. ASSERT( FALSE );
  2852. return E_FAIL;
  2853. }
  2854. strType = GetValueByIndex( rString, NDS_SEPARATOR, 0L );
  2855. strVolName = GetValueByIndex( rString, NDS_SEPARATOR, 1L );
  2856. strPath = GetValueByIndex( rString, NDS_SEPARATOR, 2L );
  2857. pValue->pPath->Type = (DWORD)_ttol( (LPCTSTR) strType );
  2858. pValue->pPath->VolumeName = AllocWCHAR( strVolName.GetBuffer( strVolName.GetLength( ) ) );
  2859. pValue->pPath->Path = AllocWCHAR( strPath.GetBuffer( strPath.GetLength( ) ) );
  2860. return S_OK;
  2861. }
  2862. /***********************************************************
  2863. Function: COleDsNDSEMail::FreeAttrValue
  2864. Arguments:
  2865. Return:
  2866. Purpose:
  2867. Author(s):
  2868. Revision:
  2869. Date:
  2870. ***********************************************************/
  2871. void COleDsNDSPath::FreeAttrValue( ADSVALUE* pValue )
  2872. {
  2873. FREE_MEMORY( pValue->pPath->VolumeName );
  2874. FREE_MEMORY( pValue->pPath->Path );
  2875. FREE_MEMORY( pValue->pPath );
  2876. }
  2877. /***********************************************************
  2878. Function: COleDsNDSPath::String_2_VARIANT
  2879. Arguments:
  2880. Return:
  2881. Purpose:
  2882. Author(s):
  2883. Revision:
  2884. Date:
  2885. ***********************************************************/
  2886. HRESULT COleDsNDSPath::String_2_VARIANT( TCHAR* pszText,
  2887. VARIANT& rVar )
  2888. {
  2889. DWORD dwValues;
  2890. CString strType, strVal;
  2891. CString strVolName;
  2892. CString strPath;
  2893. HRESULT hResult;
  2894. IADsPath* pPath = NULL;
  2895. IDispatch* pDisp = NULL;
  2896. BSTR bstrVal = NULL;
  2897. while( TRUE )
  2898. {
  2899. hResult = CoCreateInstance(
  2900. CLSID_Path,
  2901. NULL,
  2902. CLSCTX_ALL,
  2903. IID_IADsPath,
  2904. (void **)&pPath );
  2905. ASSERT( SUCCEEDED( hResult ) );
  2906. if( FAILED( hResult ) )
  2907. break;
  2908. strVal = pszText;
  2909. dwValues = GetValuesCount( strVal, NDS_SEPARATOR );
  2910. if( 3 != dwValues )
  2911. {
  2912. hResult = E_FAIL;
  2913. ASSERT( FALSE );
  2914. break;
  2915. }
  2916. strType = GetValueByIndex( strVal, NDS_SEPARATOR, 0L );
  2917. strVolName = GetValueByIndex( strVal, NDS_SEPARATOR, 1L );
  2918. strPath = GetValueByIndex( strVal, NDS_SEPARATOR, 2L );
  2919. hResult = pPath->put_Type( _ttol( (LPCTSTR) strType ) );
  2920. ASSERT( SUCCEEDED( hResult ) );
  2921. bstrVal = AllocBSTR( strVolName.GetBuffer( strVolName.GetLength( ) ) );
  2922. hResult = pPath->put_VolumeName( bstrVal );
  2923. ASSERT( SUCCEEDED( hResult ) );
  2924. SysFreeString( bstrVal );
  2925. bstrVal = AllocBSTR( strPath.GetBuffer( strPath.GetLength( ) ) );
  2926. hResult = pPath->put_Path( bstrVal );
  2927. ASSERT( SUCCEEDED( hResult ) );
  2928. SysFreeString( bstrVal );
  2929. hResult = pPath->QueryInterface( IID_IDispatch, (void**)&pDisp );
  2930. ASSERT( SUCCEEDED( hResult ) );
  2931. V_VT( &rVar ) = VT_DISPATCH;
  2932. V_DISPATCH( &rVar ) = pDisp;
  2933. break;
  2934. }
  2935. RELEASE( pPath );
  2936. return hResult;
  2937. }
  2938. /***********************************************************
  2939. Function: COleDsNDSPath::VARIANT_2_String
  2940. Arguments:
  2941. Return:
  2942. Purpose:
  2943. Author(s):
  2944. Revision:
  2945. Date:
  2946. ***********************************************************/
  2947. HRESULT COleDsNDSPath::VARIANT_2_String( TCHAR* pszText,
  2948. VARIANT& rVar )
  2949. {
  2950. HRESULT hResult = E_FAIL;
  2951. IADsPath* pPath = NULL;
  2952. LONG lType;
  2953. BSTR bstrVolName = NULL;
  2954. BSTR bstrPath = NULL;
  2955. while( TRUE )
  2956. {
  2957. ASSERT( VT_DISPATCH == V_VT( &rVar ) );
  2958. if( VT_DISPATCH != V_VT( &rVar ) )
  2959. break;
  2960. hResult = V_DISPATCH( &rVar )->QueryInterface( IID_IADsPath,
  2961. (void**)&pPath );
  2962. ASSERT( SUCCEEDED( hResult ) );
  2963. if( FAILED( hResult) )
  2964. break;
  2965. hResult = pPath->get_Type( &lType );
  2966. ASSERT( SUCCEEDED( hResult ) );
  2967. if( FAILED( hResult) )
  2968. break;
  2969. hResult = pPath->get_VolumeName( &bstrVolName );
  2970. ASSERT( SUCCEEDED( hResult ) );
  2971. if( FAILED( hResult) )
  2972. break;
  2973. hResult = pPath->get_Path( &bstrPath );
  2974. ASSERT( SUCCEEDED( hResult ) );
  2975. if( FAILED( hResult) )
  2976. break;
  2977. _ltot( lType, pszText, 10 );
  2978. _tcscat( pszText, NDS_SEPARATOR_S );
  2979. Convert( pszText + _tcslen(pszText), bstrVolName );
  2980. _tcscat( pszText, NDS_SEPARATOR_S );
  2981. Convert( pszText + _tcslen(pszText), bstrPath );
  2982. break;
  2983. }
  2984. SysFreeString( bstrVolName );
  2985. SysFreeString( bstrPath );
  2986. RELEASE( pPath );
  2987. return hResult;
  2988. }
  2989. /***********************************************************
  2990. Function: COleDsNDSTimeStamp::COleDsNDSTimeStamp
  2991. Arguments:
  2992. Return:
  2993. Purpose:
  2994. Author(s):
  2995. Revision:
  2996. Date:
  2997. ***********************************************************/
  2998. COleDsNDSTimeStamp::COleDsNDSTimeStamp( )
  2999. {
  3000. m_dwSyntaxID = ADSTYPE_TIMESTAMP;
  3001. }
  3002. /***********************************************************
  3003. Function: COleDsNDSTimeStamp::GenerateString
  3004. Arguments:
  3005. Return:
  3006. Purpose:
  3007. Author(s):
  3008. Revision:
  3009. Date:
  3010. ***********************************************************/
  3011. HRESULT COleDsNDSTimeStamp::GenerateString( TCHAR* szText,
  3012. DWORD dwWholeSeconds,
  3013. DWORD dwEventID )
  3014. {
  3015. _tcscpy( szText, _T("WholeSeconds: ") );
  3016. _ultot( dwWholeSeconds,
  3017. szText + _tcslen(szText),
  3018. 10 );
  3019. _tcscat( szText, _T("EventID: ") );
  3020. _ultot( dwEventID,
  3021. szText + _tcslen(szText),
  3022. 10 );
  3023. return S_OK;
  3024. }
  3025. /***********************************************************
  3026. Function: COleDsNDSTimeStamp::GetComponents
  3027. Arguments:
  3028. Return:
  3029. Purpose:
  3030. Author(s):
  3031. Revision:
  3032. Date:
  3033. ***********************************************************/
  3034. HRESULT COleDsNDSTimeStamp::GetComponents( TCHAR* pszString,
  3035. DWORD* pdwWholeSeconds,
  3036. DWORD* pdwEventID )
  3037. {
  3038. TCHAR szText1[ 128 ];
  3039. TCHAR szText2[ 128 ];
  3040. *pdwWholeSeconds = 0xAABBCCDD;
  3041. *pdwEventID = 0xAABBCCDD;
  3042. _stscanf( pszString, _T("%s%d%s%d"), szText1,
  3043. pdwWholeSeconds, szText2, pdwWholeSeconds );
  3044. return ( (*pdwWholeSeconds == 0xAABBCCDD) && (*pdwEventID == 0xAABBCCDD) ) ?
  3045. S_OK : E_FAIL;
  3046. }
  3047. /***********************************************************
  3048. Function: COleDsNDSTimeStamp::Value2Native
  3049. Arguments:
  3050. Return:
  3051. Purpose:
  3052. Author(s):
  3053. Revision:
  3054. Date:
  3055. ***********************************************************/
  3056. HRESULT COleDsNDSTimeStamp::Value2Native ( ADSVALUE* pValue,
  3057. CString& rString )
  3058. {
  3059. DWORD dwValues;
  3060. CString strWholeSeconds;
  3061. CString strEventID;
  3062. pValue->dwType = ADSTYPE_TIMESTAMP;
  3063. dwValues = GetValuesCount( rString, NDS_SEPARATOR );
  3064. if( 2 != dwValues )
  3065. {
  3066. ASSERT( FALSE );
  3067. return E_FAIL;
  3068. }
  3069. strWholeSeconds= GetValueByIndex( rString, NDS_SEPARATOR, 0L );
  3070. strEventID = GetValueByIndex( rString, NDS_SEPARATOR, 1L );
  3071. pValue->Timestamp.WholeSeconds= (DWORD)_ttol( (LPCTSTR) strWholeSeconds );
  3072. pValue->Timestamp.EventID = (DWORD)_ttol( (LPCTSTR) strEventID );
  3073. return S_OK;
  3074. }
  3075. /***********************************************************
  3076. Function: COleDsNDSTimeStamp::Native2Value
  3077. Arguments:
  3078. Return:
  3079. Purpose:
  3080. Author(s):
  3081. Revision:
  3082. Date:
  3083. ***********************************************************/
  3084. HRESULT COleDsNDSTimeStamp::Native2Value( ADSVALUE* pValue,
  3085. CString& rString)
  3086. {
  3087. TCHAR szText[ 128 ];
  3088. ASSERT( ADSTYPE_TIMESTAMP != pValue->dwType );
  3089. if( ADSTYPE_TIMESTAMP != pValue->dwType )
  3090. {
  3091. rString = _T("ERROR: ADSTYPE_TIMESTAMP != pValue->dwType");
  3092. return E_FAIL;
  3093. }
  3094. _ultot( pValue->Timestamp.WholeSeconds,
  3095. szText,
  3096. 10 );
  3097. _tcscat( szText, NDS_SEPARATOR_S );
  3098. _ultot( pValue->Timestamp.EventID,
  3099. szText + _tcslen(szText),
  3100. 10 );
  3101. rString = szText;
  3102. return S_OK;
  3103. }
  3104. /***********************************************************
  3105. Function: COleDsNDSTimeStamp::String_2_VARIANT
  3106. Arguments:
  3107. Return:
  3108. Purpose:
  3109. Author(s):
  3110. Revision:
  3111. Date:
  3112. ***********************************************************/
  3113. HRESULT COleDsNDSTimeStamp::String_2_VARIANT( TCHAR* pszText,
  3114. VARIANT& rVar )
  3115. {
  3116. HRESULT hResult;
  3117. IADsTimestamp* pTimeStamp;
  3118. DWORD dwValues;
  3119. CString strWholeSeconds;
  3120. CString strEventID;
  3121. CString rString;
  3122. rString = pszText;
  3123. dwValues = GetValuesCount( rString, NDS_SEPARATOR );
  3124. if( 2 != dwValues )
  3125. {
  3126. ASSERT( FALSE );
  3127. return E_FAIL;
  3128. }
  3129. strWholeSeconds= GetValueByIndex( rString, NDS_SEPARATOR, 0L );
  3130. strEventID = GetValueByIndex( rString, NDS_SEPARATOR, 1L );
  3131. hResult = hResult = CoCreateInstance(
  3132. CLSID_Timestamp,
  3133. NULL,
  3134. CLSCTX_INPROC_SERVER,
  3135. IID_IADsTimestamp,
  3136. (void **)&pTimeStamp );
  3137. ASSERT( SUCCEEDED( hResult ) );
  3138. if( FAILED( hResult ) )
  3139. return hResult;
  3140. hResult = pTimeStamp->put_WholeSeconds( _ttol( (LPCTSTR) strWholeSeconds ) );
  3141. ASSERT( SUCCEEDED( hResult ) );
  3142. hResult = pTimeStamp->put_EventID( _ttol( (LPCTSTR) strEventID ) );
  3143. ASSERT( SUCCEEDED( hResult ) );
  3144. if( SUCCEEDED( hResult ) )
  3145. {
  3146. IDispatch* pDisp = NULL;
  3147. V_VT( &rVar ) = VT_DISPATCH;
  3148. hResult = pTimeStamp->QueryInterface( IID_IDispatch, (void**)&pDisp );
  3149. ASSERT( SUCCEEDED( hResult ) );
  3150. V_DISPATCH( &rVar ) = pDisp;
  3151. }
  3152. pTimeStamp->Release( );
  3153. return hResult;
  3154. }
  3155. /***********************************************************
  3156. Function: COleDsNDSTimeStamp::VARIANT_2_String
  3157. Arguments:
  3158. Return:
  3159. Purpose:
  3160. Author(s):
  3161. Revision:
  3162. Date:
  3163. ***********************************************************/
  3164. HRESULT COleDsNDSTimeStamp::VARIANT_2_String( TCHAR* pszText, VARIANT& rVar )
  3165. {
  3166. IADsTimestamp* pTimeStamp = NULL;
  3167. HRESULT hResult;
  3168. long lWholeSeconds, lEventID;
  3169. ASSERT( VT_DISPATCH == V_VT( &rVar) );
  3170. if( VT_DISPATCH != V_VT( &rVar) )
  3171. {
  3172. _tcscpy( pszText, _T("ERROR: VT_DISPATCH != V_VT( &rVar)") );
  3173. return E_FAIL;
  3174. }
  3175. hResult = V_DISPATCH( &rVar )->QueryInterface( IID_IADsTimestamp,
  3176. (void**)&pTimeStamp );
  3177. ASSERT( SUCCEEDED( hResult ) );
  3178. if( FAILED( hResult ) )
  3179. {
  3180. _tcscpy( pszText, _T("ERROR: QI for IID_IADsTimeStamp fails") );
  3181. return hResult;
  3182. }
  3183. hResult = pTimeStamp->get_WholeSeconds( &lWholeSeconds );
  3184. ASSERT( SUCCEEDED( hResult ) );
  3185. hResult = pTimeStamp->get_EventID( &lEventID );
  3186. ASSERT( SUCCEEDED( hResult ) );
  3187. pTimeStamp->Release( );
  3188. _ultot( lWholeSeconds,
  3189. pszText,
  3190. 10 );
  3191. _tcscat( pszText, NDS_SEPARATOR_S );
  3192. _ultot( lEventID,
  3193. pszText + _tcslen(pszText),
  3194. 10 );
  3195. return hResult;
  3196. }
  3197. /***********************************************************
  3198. Function: COleDsNDSComplexType::COleDsNDSComplexType
  3199. Arguments:
  3200. Return:
  3201. Purpose:
  3202. Author(s):
  3203. Revision:
  3204. Date:
  3205. ***********************************************************/
  3206. COleDsNDSComplexType::COleDsNDSComplexType( )
  3207. {
  3208. }
  3209. /***********************************************************
  3210. Function:
  3211. Arguments:
  3212. Return:
  3213. Purpose:
  3214. Author(s):
  3215. Revision:
  3216. Date:
  3217. ***********************************************************/
  3218. CString COleDsNDSComplexType::VarToDisplayStringEx( VARIANT& var,
  3219. BOOL bMultiValued )
  3220. {
  3221. SAFEARRAY* pSArray;
  3222. HRESULT hResult;
  3223. LONG uLow, uHigh, uIndex;
  3224. VARIANT vItem;
  3225. CString strVal;
  3226. CString strTemp;
  3227. pSArray = V_ARRAY( &var );
  3228. hResult = SafeArrayGetLBound( pSArray, 1, &uLow );
  3229. hResult = SafeArrayGetUBound( pSArray, 1, &uHigh );
  3230. if( !bMultiValued )
  3231. {
  3232. ASSERT( uLow == uHigh );
  3233. }
  3234. for( uIndex = uLow; uIndex <= uHigh; uIndex++ )
  3235. {
  3236. if( uIndex != uLow )
  3237. {
  3238. strVal += SEPARATOR_S;
  3239. }
  3240. VariantInit( &vItem );
  3241. hResult = SafeArrayGetElement( pSArray, &uIndex, &vItem );
  3242. ASSERT( SUCCEEDED( hResult ) );
  3243. strTemp = VarToDisplayString( vItem, bMultiValued, FALSE );
  3244. VariantClear( &vItem );
  3245. strVal += strTemp;
  3246. if( strVal.GetLength( ) > 8096 )
  3247. break;
  3248. }
  3249. return strVal;
  3250. }
  3251. /***********************************************************
  3252. Function:
  3253. Arguments:
  3254. Return:
  3255. Purpose:
  3256. Author(s):
  3257. Revision:
  3258. Date:
  3259. ***********************************************************/
  3260. CString COleDsNDSComplexType::VarToDisplayString( VARIANT& var,
  3261. BOOL bMultiValued,
  3262. BOOL bUseEx )
  3263. {
  3264. LONG uLow, uHigh, uIndex;
  3265. SAFEARRAY* psa;
  3266. VARIANT vItem;
  3267. CString strVal, strTemp;
  3268. HRESULT hResult;
  3269. TCHAR szText[ 2048 ];
  3270. if( bUseEx )
  3271. {
  3272. return VarToDisplayStringEx( var, bMultiValued );
  3273. }
  3274. if( bMultiValued )
  3275. {
  3276. if( VT_DISPATCH == V_VT( &var ) )
  3277. {
  3278. VARIANT_2_String( szText, var );
  3279. return CString( szText );
  3280. }
  3281. ASSERT( (VT_ARRAY | VT_VARIANT) == V_VT(&var) );
  3282. if( (VT_ARRAY | VT_VARIANT) == V_VT(&var) )
  3283. {
  3284. return CString( _T("ERROR: (VT_ARRAY | VT_VARIANT) != V_VT(&var)") );
  3285. }
  3286. psa = V_ARRAY( &var );
  3287. ASSERT( NULL != psa );
  3288. if( NULL == psa )
  3289. {
  3290. return CString( _T("ERROR: NULL == psa" ) );
  3291. }
  3292. hResult = SafeArrayGetLBound( psa, 1, &uLow );
  3293. hResult = SafeArrayGetUBound( psa, 1, &uHigh );
  3294. for( uIndex = uLow; uIndex <= uHigh; uIndex++ )
  3295. {
  3296. if( uIndex != uLow )
  3297. {
  3298. strVal += SEPARATOR_S;
  3299. }
  3300. VariantInit( &vItem );
  3301. hResult = SafeArrayGetElement( psa, &uIndex, &vItem );
  3302. ASSERT( SUCCEEDED( hResult ) );
  3303. strTemp = VarToDisplayString( vItem, FALSE, FALSE );
  3304. VariantClear( &vItem );
  3305. strVal += strTemp;
  3306. if( strVal.GetLength( ) > 8096 )
  3307. break;
  3308. }
  3309. }
  3310. else
  3311. {
  3312. hResult = VARIANT_2_String( szText, var );
  3313. if( SUCCEEDED( hResult ) )
  3314. {
  3315. strVal = szText;
  3316. }
  3317. else
  3318. {
  3319. strVal = OleDsGetErrorText( hResult );
  3320. }
  3321. }
  3322. return strVal;
  3323. }
  3324. /***********************************************************
  3325. Function:
  3326. Arguments:
  3327. Return:
  3328. Purpose:
  3329. Author(s):
  3330. Revision:
  3331. Date:
  3332. ***********************************************************/
  3333. BOOL COleDsNDSComplexType::DisplayStringToDispParamsEx( CString& rText,
  3334. DISPPARAMS& dispParams,
  3335. BOOL bMultiValued )
  3336. {
  3337. SAFEARRAY* pSArray;
  3338. SAFEARRAYBOUND saBound;
  3339. HRESULT hResult;
  3340. LONG lIdx = LBOUND;
  3341. DisplayStringToDispParams( rText, dispParams, bMultiValued, FALSE );
  3342. if( !bMultiValued )
  3343. {
  3344. saBound.lLbound = LBOUND;
  3345. saBound.cElements = 1;
  3346. pSArray = SafeArrayCreate( VT_VARIANT, 1, &saBound );
  3347. hResult = SafeArrayPutElement( pSArray, &lIdx, &dispParams.rgvarg[0] );
  3348. VariantClear( &dispParams.rgvarg[0] );
  3349. V_VT( &dispParams.rgvarg[0] ) = VT_ARRAY | VT_VARIANT;
  3350. V_ARRAY( &dispParams.rgvarg[0] ) = pSArray;
  3351. }
  3352. return TRUE;
  3353. }
  3354. /***********************************************************
  3355. Function:
  3356. Arguments:
  3357. Return:
  3358. Purpose:
  3359. Author(s):
  3360. Revision:
  3361. Date:
  3362. ***********************************************************/
  3363. BOOL COleDsNDSComplexType::DisplayStringToDispParams( CString& rText,
  3364. DISPPARAMS& dispParams,
  3365. BOOL bMultiValued,
  3366. BOOL bUseEx )
  3367. {
  3368. HRESULT hResult;
  3369. int x= 0;
  3370. if( bUseEx )
  3371. {
  3372. return DisplayStringToDispParamsEx( rText, dispParams, bMultiValued );
  3373. }
  3374. dispParams.rgdispidNamedArgs[ 0 ] = DISPID_PROPERTYPUT;
  3375. dispParams.cArgs = 1;
  3376. dispParams.cNamedArgs = 1;
  3377. if( bMultiValued )
  3378. {
  3379. SAFEARRAY* psa;
  3380. SAFEARRAYBOUND sab;
  3381. TCHAR* strText;
  3382. TCHAR* strStore;
  3383. int nItems = 0;
  3384. int nIdx;
  3385. int nSize;
  3386. HRESULT hResult;
  3387. //rText.MakeUpper( );
  3388. strText = (TCHAR*) new TCHAR[ rText.GetLength( ) + 1 ];
  3389. strStore = strText;
  3390. if( !strText )
  3391. {
  3392. return E_FAIL;
  3393. }
  3394. _tcscpy( strText, rText.GetBuffer( rText.GetLength( ) ) );
  3395. nSize = rText.GetLength( );
  3396. nItems = 1;
  3397. for( nIdx = 0; nIdx < nSize ; nIdx++ )
  3398. {
  3399. if( strText[ nIdx ] == SEPARATOR_C )
  3400. {
  3401. strText[ nIdx ] = _T('\0');
  3402. nItems++;
  3403. }
  3404. }
  3405. sab.cElements = nItems;
  3406. sab.lLbound = LBOUND;
  3407. psa = SafeArrayCreate( VT_VARIANT, 1, &sab );
  3408. ASSERT( NULL != psa );
  3409. if ( psa )
  3410. {
  3411. for( nIdx = LBOUND; nIdx < ( LBOUND + nItems ) ; nIdx++ )
  3412. {
  3413. VARIANT var;
  3414. String_2_VARIANT( strText, var );
  3415. strText += _tcslen( strText ) + 1;
  3416. hResult = SafeArrayPutElement( psa, (long FAR *)&nIdx, &var );
  3417. VariantClear( &var );
  3418. }
  3419. V_VT( &dispParams.rgvarg[0] ) = VT_VARIANT | VT_ARRAY;
  3420. V_ARRAY( &dispParams.rgvarg[0] ) = psa;
  3421. }
  3422. delete [] strStore;
  3423. }
  3424. else
  3425. {
  3426. hResult = String_2_VARIANT( rText.GetBuffer( rText.GetLength( ) ),
  3427. dispParams.rgvarg[0] );
  3428. }
  3429. return SUCCEEDED( hResult );
  3430. }
  3431. /***********************************************************
  3432. Function:
  3433. Arguments:
  3434. Return:
  3435. Purpose:
  3436. Author(s):
  3437. Revision:
  3438. Date:
  3439. ***********************************************************/
  3440. CString COleDsVARIANT::VarToDisplayString( VARIANT& var, BOOL bMultiValued, BOOL bUseEx )
  3441. {
  3442. return FromVariantArrayToString( var );
  3443. }
  3444. /***********************************************************
  3445. Function:
  3446. Arguments:
  3447. Return:
  3448. Purpose:
  3449. Author(s):
  3450. Revision:
  3451. Date:
  3452. ***********************************************************/
  3453. HRESULT COleDsVARIANT::Native2Value( ADSVALUE* pADsObject, CString& rVal )
  3454. {
  3455. return S_OK;
  3456. }
  3457. /***********************************************************
  3458. Function:
  3459. Arguments:
  3460. Return:
  3461. Purpose:
  3462. Author(s):
  3463. Revision:
  3464. Date:
  3465. ***********************************************************/
  3466. HRESULT COleDsVARIANT::Value2Native( ADSVALUE* pADsObject, CString& rVal )
  3467. {
  3468. return S_OK;
  3469. }
  3470. /***********************************************************
  3471. Function:
  3472. Arguments:
  3473. Return:
  3474. Purpose:
  3475. Author(s):
  3476. Revision:
  3477. Date:
  3478. ***********************************************************/
  3479. BOOL COleDsVARIANT::DisplayStringToDispParams( CString& rText, DISPPARAMS& dispParams, BOOL bMultiValued, BOOL bUseEx )
  3480. {
  3481. HRESULT hResult;
  3482. dispParams.rgdispidNamedArgs[ 0 ] = DISPID_PROPERTYPUT;
  3483. dispParams.cArgs = 1;
  3484. dispParams.cNamedArgs = 1;
  3485. hResult = BuildVariantArray( VT_BSTR, rText, dispParams.rgvarg[0] );
  3486. return SUCCEEDED( hResult );
  3487. }
  3488. /***********************************************************
  3489. Function:
  3490. Arguments:
  3491. Return:
  3492. Purpose:
  3493. Author(s):
  3494. Revision:
  3495. Date:
  3496. ***********************************************************/
  3497. COleDsOctetString::COleDsOctetString( )
  3498. {
  3499. m_dwSyntaxID = ADSTYPE_OCTET_STRING;
  3500. }
  3501. /***********************************************************
  3502. Function:
  3503. Arguments:
  3504. Return:
  3505. Purpose:
  3506. Author(s):
  3507. Revision:
  3508. Date:
  3509. ***********************************************************/
  3510. CString COleDsOctetString::VarToDisplayStringEx( VARIANT& var, BOOL bMultiValued )
  3511. {
  3512. SAFEARRAY* pSArray;
  3513. HRESULT hResult;
  3514. LONG uLow, uHigh, uIndex;
  3515. VARIANT vItem;
  3516. CString strVal;
  3517. CString strTemp;
  3518. pSArray = V_ARRAY( &var );
  3519. hResult = SafeArrayGetLBound( pSArray, 1, &uLow );
  3520. hResult = SafeArrayGetUBound( pSArray, 1, &uHigh );
  3521. if( !bMultiValued )
  3522. {
  3523. ASSERT( uLow == uHigh );
  3524. }
  3525. for( uIndex = uLow; uIndex <= uHigh; uIndex++ )
  3526. {
  3527. if( uIndex != uLow )
  3528. {
  3529. strVal += SEPARATOR_S;
  3530. }
  3531. VariantInit( &vItem );
  3532. hResult = SafeArrayGetElement( pSArray, &uIndex, &vItem );
  3533. ASSERT( SUCCEEDED( hResult ) );
  3534. strTemp = VarToDisplayString( vItem, bMultiValued, FALSE );
  3535. VariantClear( &vItem );
  3536. strVal += strTemp;
  3537. if( strVal.GetLength( ) > 8096 )
  3538. break;
  3539. }
  3540. return strVal;
  3541. }
  3542. /***********************************************************
  3543. Function:
  3544. Arguments:
  3545. Return:
  3546. Purpose:
  3547. Author(s):
  3548. Revision:
  3549. Date:
  3550. ***********************************************************/
  3551. CString COleDsOctetString::VarToDisplayString( VARIANT& var, BOOL bMultiValued, BOOL bUseEx )
  3552. {
  3553. if( bUseEx )
  3554. {
  3555. return VarToDisplayStringEx( var, bMultiValued );
  3556. }
  3557. if( bMultiValued )
  3558. {
  3559. return FromVariantArrayToString( var );
  3560. }
  3561. else
  3562. {
  3563. return FromVariantArrayToString( var );
  3564. }
  3565. }
  3566. /***********************************************************
  3567. Function:
  3568. Arguments:
  3569. Return:
  3570. Purpose:
  3571. Author(s):
  3572. Revision:
  3573. Date:
  3574. ***********************************************************/
  3575. BOOL COleDsOctetString::DisplayStringToDispParamsEx( CString& rText, DISPPARAMS& dispParams, BOOL bMultiValued )
  3576. {
  3577. SAFEARRAY* pSArray;
  3578. SAFEARRAYBOUND saBound;
  3579. HRESULT hResult;
  3580. LONG lIdx = LBOUND;
  3581. DisplayStringToDispParams( rText, dispParams, bMultiValued, FALSE );
  3582. if( !bMultiValued )
  3583. {
  3584. saBound.lLbound = LBOUND;
  3585. saBound.cElements = 1;
  3586. pSArray = SafeArrayCreate( VT_VARIANT, 1, &saBound );
  3587. hResult = SafeArrayPutElement( pSArray, &lIdx, &dispParams.rgvarg[0] );
  3588. VariantClear( &dispParams.rgvarg[0] );
  3589. V_VT( &dispParams.rgvarg[0] ) = VT_ARRAY | VT_VARIANT;
  3590. V_ARRAY( &dispParams.rgvarg[0] ) = pSArray;
  3591. }
  3592. return TRUE;
  3593. }
  3594. /***********************************************************
  3595. Function:
  3596. Arguments:
  3597. Return:
  3598. Purpose:
  3599. Author(s):
  3600. Revision:
  3601. Date:
  3602. ***********************************************************/
  3603. BOOL COleDsOctetString::DisplayStringToDispParams( CString& rText, DISPPARAMS& dispParams,
  3604. BOOL bMultiValued, BOOL bUseEx )
  3605. {
  3606. HRESULT hResult;
  3607. int x= 0;
  3608. if( bUseEx )
  3609. {
  3610. return DisplayStringToDispParamsEx( rText, dispParams, bMultiValued );
  3611. }
  3612. dispParams.rgdispidNamedArgs[ 0 ] = DISPID_PROPERTYPUT;
  3613. dispParams.cArgs = 1;
  3614. dispParams.cNamedArgs = 1;
  3615. if( bMultiValued )
  3616. {
  3617. hResult = CreateBlobArrayEx( rText, dispParams.rgvarg[0] );
  3618. }
  3619. else
  3620. {
  3621. hResult = CreateBlobArray( rText, dispParams.rgvarg[0] );
  3622. }
  3623. return SUCCEEDED( hResult );
  3624. }
  3625. /***********************************************************
  3626. Function:
  3627. Arguments:
  3628. Return:
  3629. Purpose:
  3630. Author(s):
  3631. Revision:
  3632. Date:
  3633. ***********************************************************/
  3634. HRESULT COleDsOctetString::Native2Value( ADSVALUE* pADsObject,
  3635. CString& rVal )
  3636. {
  3637. DWORD dwItem;
  3638. LPBYTE lpByte;
  3639. TCHAR szText[ 128 ];
  3640. lpByte = pADsObject->OctetString.lpValue;
  3641. ASSERT( lpByte );
  3642. _tcscpy( szText, _T("[") );
  3643. _ultot( pADsObject->OctetString.dwLength, szText + _tcslen( szText ), 10 );
  3644. _tcscat( szText, _T("]") );
  3645. for( dwItem = 0L; dwItem < pADsObject->OctetString.dwLength ; dwItem++ )
  3646. {
  3647. #ifdef UNICODE
  3648. swprintf(
  3649. #else
  3650. sprintf(
  3651. #endif
  3652. szText + _tcslen(szText), _T(" x%02x"), lpByte[ dwItem ] );
  3653. if( _tcslen( szText ) > 120 )
  3654. break;
  3655. }
  3656. rVal = szText;
  3657. return S_OK;
  3658. }
  3659. /***********************************************************
  3660. Function: COleDsOctetString::Value2Native
  3661. Arguments:
  3662. Return:
  3663. Purpose:
  3664. Author(s):
  3665. Revision:
  3666. Date:
  3667. ***********************************************************/
  3668. HRESULT COleDsOctetString::Value2Native( ADSVALUE* pADsObject,
  3669. CString& rVal )
  3670. {
  3671. HRESULT hResult = E_FAIL;
  3672. TCHAR* strText;
  3673. LPBYTE lpByte;
  3674. int nSize, nItems, nIdx;
  3675. rVal.MakeUpper( );
  3676. strText = (TCHAR*) new TCHAR[ rVal.GetLength( ) + 1 ];
  3677. if( !strText )
  3678. {
  3679. return E_FAIL;
  3680. }
  3681. _tcscpy( strText, rVal.GetBuffer( rVal.GetLength( ) ) );
  3682. nSize = rVal.GetLength( );
  3683. nItems = 0;
  3684. for( nIdx = 0; nIdx < nSize ; nIdx++ )
  3685. {
  3686. if( strText[ nIdx ] == _T('X') )
  3687. {
  3688. nItems++;
  3689. }
  3690. }
  3691. lpByte = (LPBYTE) AllocADsMem( nItems );
  3692. ASSERT( lpByte );
  3693. if ( lpByte )
  3694. {
  3695. int nItems = 0;
  3696. for( nIdx = 0; nIdx < nSize ; nIdx++ )
  3697. {
  3698. if( strText[ nIdx ] == _T('X') )
  3699. {
  3700. lpByte[ nItems++] = GetByteValue( strText + nIdx + 1 );
  3701. while( nIdx < nSize && !isspace( strText[ nIdx ] ) )
  3702. nIdx++;
  3703. }
  3704. }
  3705. }
  3706. pADsObject->OctetString.lpValue = lpByte;
  3707. pADsObject->OctetString.dwLength = nItems;
  3708. delete [] strText;
  3709. return hResult;
  3710. }
  3711. /***********************************************************
  3712. Function: COleDsOctetString::FreeAttrValue
  3713. Arguments:
  3714. Return:
  3715. Purpose:
  3716. Author(s):
  3717. Revision:
  3718. Date:
  3719. ***********************************************************/
  3720. void COleDsOctetString::FreeAttrValue( ADSVALUE* pADsValue )
  3721. {
  3722. ASSERT( NULL != pADsValue->OctetString.lpValue );
  3723. FREE_MEMORY( pADsValue->OctetString.lpValue );
  3724. }
  3725. /*******************************************************************
  3726. Function: GetByteValue
  3727. Arguments:
  3728. Return:
  3729. Purpose:
  3730. Author(s):
  3731. Revision:
  3732. Date:
  3733. *******************************************************************/
  3734. BYTE COleDsOctetString::GetByteValue( TCHAR* szString )
  3735. {
  3736. BYTE bBytes[ 2 ];
  3737. bBytes[ 0 ] = bBytes[ 1 ] = 0;
  3738. for( int i = 0; i < 2 ; i++ )
  3739. {
  3740. if( !szString[ i ] )
  3741. break;
  3742. #ifdef UNICODE
  3743. if( !iswdigit( szString[ i ] ) )
  3744. {
  3745. bBytes[ i ] = ( (BYTE) ( szString[ i ] ) ) - 0x37;
  3746. }
  3747. #else
  3748. if( !isdigit( szString[ i ] ) )
  3749. {
  3750. bBytes[ i ] = ( (BYTE) ( szString[ i ] ) ) - 0x37;
  3751. }
  3752. #endif
  3753. else
  3754. {
  3755. bBytes[ i ] = ( (BYTE) ( szString[ i ] ) ) - 0x30;
  3756. }
  3757. }
  3758. return ( bBytes[ 0 ] << 4 ) + bBytes[ 1 ];
  3759. }