Leaked source code of windows server 2003
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.

4613 lines
119 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. //SMITHA 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. _tcscpy( szText, (TCHAR *) pValue->pFaxNumber->TelephoneNumber );
  1813. }
  1814. else
  1815. {
  1816. _tcscpy( szText, _T("NULL") );
  1817. }
  1818. _tcscat( szText, NDS_SEPARATOR_S );
  1819. rString = szText;
  1820. if( NULL != pValue->pFaxNumber->Parameters )
  1821. {
  1822. rString = rString + Blob2String( pValue->pFaxNumber->Parameters,
  1823. pValue->pFaxNumber->NumberOfBits );
  1824. }
  1825. else
  1826. {
  1827. rString = rString + _T("NULL");
  1828. }
  1829. return S_OK;
  1830. }
  1831. /***********************************************************
  1832. Function: COleDsNDSFaxNumber::Value2Native
  1833. Arguments:
  1834. Return:
  1835. Purpose:
  1836. Author(s):
  1837. Revision:
  1838. Date:
  1839. ***********************************************************/
  1840. HRESULT COleDsNDSFaxNumber::Value2Native( ADSVALUE* pValue,
  1841. CString& rString )
  1842. {
  1843. DWORD dwValues;
  1844. CString strTelephoneNumber;
  1845. CString strParameters;
  1846. pValue->dwType = ADSTYPE_FAXNUMBER;
  1847. dwValues = GetValuesCount( rString, NDS_SEPARATOR );
  1848. if( 2 != dwValues )
  1849. {
  1850. ASSERT( FALSE );
  1851. return E_FAIL;
  1852. }
  1853. strTelephoneNumber = GetValueByIndex( rString, NDS_SEPARATOR, 0L );
  1854. strParameters = GetValueByIndex( rString, NDS_SEPARATOR, 1L );
  1855. pValue->pFaxNumber = (ADS_FAXNUMBER*) AllocADsMem( sizeof(ADS_FAXNUMBER) );
  1856. ASSERT( NULL != pValue->pFaxNumber );
  1857. if( NULL == pValue->pFaxNumber )
  1858. {
  1859. return E_FAIL;
  1860. }
  1861. pValue->pFaxNumber->TelephoneNumber = AllocWCHAR( (LPTSTR)(LPCTSTR)strTelephoneNumber );
  1862. String2Blob( strParameters.GetBuffer( strParameters.GetLength( ) ),
  1863. (void**) (pValue->pFaxNumber->Parameters),
  1864. &(pValue->pFaxNumber->NumberOfBits) );
  1865. return S_OK;
  1866. }
  1867. /***********************************************************
  1868. Function: COleDsNDSFaxNumber::FreeAttrValue
  1869. Arguments:
  1870. Return:
  1871. Purpose:
  1872. Author(s):
  1873. Revision:
  1874. Date:
  1875. ***********************************************************/
  1876. void COleDsNDSFaxNumber::FreeAttrValue( ADSVALUE* pValue )
  1877. {
  1878. if( NULL != pValue->pFaxNumber )
  1879. {
  1880. FREE_MEMORY( pValue->pFaxNumber->TelephoneNumber );
  1881. FREE_MEMORY( pValue->pFaxNumber->Parameters );
  1882. }
  1883. FREE_MEMORY( pValue->pFaxNumber );
  1884. }
  1885. /***********************************************************
  1886. Function: COleDsNDSFaxNumber::String_2_VARIANT
  1887. Arguments:
  1888. Return:
  1889. Purpose:
  1890. Author(s):
  1891. Revision:
  1892. Date:
  1893. ***********************************************************/
  1894. HRESULT COleDsNDSFaxNumber::String_2_VARIANT( TCHAR* pszText,
  1895. VARIANT& rVar )
  1896. {
  1897. DWORD dwValues;
  1898. CString strTelephoneNumber, strVal;
  1899. CString strParameters;
  1900. HRESULT hResult;
  1901. IADsFaxNumber* pFaxNumber = NULL;
  1902. IDispatch* pDisp = NULL;
  1903. BSTR bstrVal = NULL;
  1904. VARIANT vVal;
  1905. VariantInit( &vVal );
  1906. while( TRUE )
  1907. {
  1908. hResult = CoCreateInstance(
  1909. CLSID_FaxNumber,
  1910. NULL,
  1911. CLSCTX_ALL,
  1912. IID_IADsFaxNumber,
  1913. (void **)&pFaxNumber);
  1914. ASSERT( SUCCEEDED( hResult ) );
  1915. if( FAILED( hResult ) )
  1916. break;
  1917. strVal = pszText;
  1918. dwValues = GetValuesCount( strVal, NDS_SEPARATOR );
  1919. if( 2 != dwValues )
  1920. {
  1921. hResult = E_FAIL;
  1922. ASSERT( FALSE );
  1923. break;
  1924. }
  1925. strTelephoneNumber= GetValueByIndex( strVal, NDS_SEPARATOR, 0L );
  1926. strParameters = GetValueByIndex( strVal, NDS_SEPARATOR, 1L );
  1927. bstrVal = AllocBSTR( strTelephoneNumber.GetBuffer( strTelephoneNumber.GetLength( ) ) );
  1928. hResult = pFaxNumber->put_TelephoneNumber( bstrVal );
  1929. ASSERT( SUCCEEDED( hResult ) );
  1930. hResult = CreateBlobArray( strParameters, vVal );
  1931. ASSERT( SUCCEEDED( hResult ) );
  1932. hResult = pFaxNumber->put_Parameters( vVal );
  1933. ASSERT( SUCCEEDED( hResult ) );
  1934. hResult = pFaxNumber->QueryInterface( IID_IDispatch, (void**)&pDisp );
  1935. ASSERT( SUCCEEDED( hResult ) );
  1936. V_VT( &rVar ) = VT_DISPATCH;
  1937. V_DISPATCH( &rVar ) = pDisp;
  1938. break;
  1939. }
  1940. SysFreeString( bstrVal );
  1941. VariantClear( &vVal );
  1942. RELEASE( pFaxNumber );
  1943. return hResult;
  1944. }
  1945. /***********************************************************
  1946. Function: COleDsNDSFaxNumber::VARIANT_2_String
  1947. Arguments:
  1948. Return:
  1949. Purpose:
  1950. Author(s):
  1951. Revision:
  1952. Date:
  1953. ***********************************************************/
  1954. HRESULT COleDsNDSFaxNumber::VARIANT_2_String( TCHAR* pszText,
  1955. VARIANT& rVar )
  1956. {
  1957. HRESULT hResult = E_FAIL;
  1958. IADsFaxNumber* pFaxNumber = NULL;
  1959. VARIANT vParameters;
  1960. BSTR bstrTelephoneNumber = NULL;
  1961. CString strText;
  1962. VariantInit( &vParameters );
  1963. while( TRUE )
  1964. {
  1965. ASSERT( VT_DISPATCH == V_VT( &rVar ) );
  1966. if( VT_DISPATCH != V_VT( &rVar ) )
  1967. break;
  1968. hResult = V_DISPATCH( &rVar )->QueryInterface( IID_IADsFaxNumber,
  1969. (void**)&pFaxNumber );
  1970. ASSERT( SUCCEEDED( hResult ) );
  1971. if( FAILED( hResult) )
  1972. break;
  1973. hResult = pFaxNumber->get_TelephoneNumber( &bstrTelephoneNumber );
  1974. ASSERT( SUCCEEDED( hResult ) );
  1975. if( FAILED( hResult) )
  1976. break;
  1977. hResult = pFaxNumber->get_Parameters( &vParameters );
  1978. ASSERT( SUCCEEDED( hResult ) );
  1979. if( FAILED( hResult) )
  1980. break;
  1981. Convert( pszText, bstrTelephoneNumber );
  1982. _tcscat( pszText, NDS_SEPARATOR_S );
  1983. strText = FromVariantToString( vParameters );
  1984. _tcscat( pszText, (LPCTSTR)strText );
  1985. break;
  1986. }
  1987. SysFreeString( bstrTelephoneNumber );
  1988. VariantClear( &vParameters );
  1989. RELEASE( pFaxNumber );
  1990. return hResult;
  1991. }
  1992. /***********************************************************
  1993. Function: COleDsNDSEMail::COleDsNDSEMail
  1994. Arguments:
  1995. Return:
  1996. Purpose:
  1997. Author(s):
  1998. Revision:
  1999. Date:
  2000. ***********************************************************/
  2001. COleDsNDSEMail::COleDsNDSEMail ( )
  2002. {
  2003. m_dwSyntaxID = ADSTYPE_EMAIL;
  2004. }
  2005. /***********************************************************
  2006. Function: COleDsNDSEMail::Native2Value
  2007. Arguments:
  2008. Return:
  2009. Purpose:
  2010. Author(s):
  2011. Revision:
  2012. Date:
  2013. ***********************************************************/
  2014. HRESULT COleDsNDSEMail::Native2Value( ADSVALUE* pValue,
  2015. CString& rString )
  2016. {
  2017. int nIdx;
  2018. TCHAR szText[ 256 ];
  2019. ASSERT( ADSTYPE_EMAIL == pValue->dwType );
  2020. if( ADSTYPE_EMAIL != pValue->dwType )
  2021. {
  2022. rString = _T("ERROR: ADSTYPE_EMAIL != pValue->dwType");
  2023. return E_FAIL;
  2024. }
  2025. nIdx = 0;
  2026. if( NULL != pValue->Email.Address )
  2027. {
  2028. _stprintf( szText,
  2029. _T("%ld & %S"),
  2030. pValue->Email.Type,
  2031. pValue->Email.Address );
  2032. }
  2033. else
  2034. {
  2035. _stprintf( szText,
  2036. _T("%ld & NULL"),
  2037. pValue->Email.Type );
  2038. }
  2039. rString = szText;
  2040. return S_OK;
  2041. }
  2042. /***********************************************************
  2043. Function: COleDsNDSEMail::Value2Native
  2044. Arguments:
  2045. Return:
  2046. Purpose:
  2047. Author(s):
  2048. Revision:
  2049. Date:
  2050. ***********************************************************/
  2051. HRESULT COleDsNDSEMail::Value2Native( ADSVALUE* pValue,
  2052. CString& rString )
  2053. {
  2054. DWORD dwValues, dwSize;
  2055. CString strNumber;
  2056. CString strAddress;
  2057. pValue->dwType = ADSTYPE_EMAIL;
  2058. dwValues = GetValuesCount( rString, NDS_SEPARATOR );
  2059. if( 2 != dwValues )
  2060. {
  2061. ASSERT( FALSE );
  2062. return E_FAIL;
  2063. }
  2064. strNumber = GetValueByIndex( rString, NDS_SEPARATOR, 0L );
  2065. strAddress = GetValueByIndex( rString, NDS_SEPARATOR, 1L );
  2066. pValue->Email.Type = (DWORD)_ttol( (LPCTSTR) strNumber );
  2067. dwSize = strAddress.GetLength( ) + 1;
  2068. dwSize = dwSize * sizeof(WCHAR);
  2069. pValue->Email.Address = (LPWSTR) AllocADsMem( dwSize );
  2070. Convert( pValue->Email.Address, strAddress.GetBuffer( strAddress.GetLength( ) ) );
  2071. return S_OK;
  2072. }
  2073. /***********************************************************
  2074. Function: COleDsNDSEMail::FreeAttrValue
  2075. Arguments:
  2076. Return:
  2077. Purpose:
  2078. Author(s):
  2079. Revision:
  2080. Date:
  2081. ***********************************************************/
  2082. void COleDsNDSEMail::FreeAttrValue( ADSVALUE* pValue )
  2083. {
  2084. FREE_MEMORY( pValue->Email.Address );
  2085. }
  2086. /***********************************************************
  2087. Function: COleDsNDSEMail::String_2_VARIANT
  2088. Arguments:
  2089. Return:
  2090. Purpose:
  2091. Author(s):
  2092. Revision:
  2093. Date:
  2094. ***********************************************************/
  2095. HRESULT COleDsNDSEMail::String_2_VARIANT( TCHAR* pszText,
  2096. VARIANT& rVar )
  2097. {
  2098. DWORD dwValues;
  2099. CString strNumber, strVal;
  2100. CString strAddress;
  2101. HRESULT hResult;
  2102. IADsEmail* pEMail = NULL;
  2103. IDispatch* pDisp = NULL;
  2104. BSTR bstrVal = NULL;
  2105. while( TRUE )
  2106. {
  2107. hResult = CoCreateInstance(
  2108. CLSID_Email,
  2109. NULL,
  2110. CLSCTX_ALL,
  2111. IID_IADsEmail,
  2112. (void **)&pEMail);
  2113. ASSERT( SUCCEEDED( hResult ) );
  2114. if( FAILED( hResult ) )
  2115. break;
  2116. strVal = pszText;
  2117. dwValues = GetValuesCount( strVal, NDS_SEPARATOR );
  2118. if( 2 != dwValues )
  2119. {
  2120. hResult = E_FAIL;
  2121. ASSERT( FALSE );
  2122. break;
  2123. }
  2124. strNumber = GetValueByIndex( strVal, NDS_SEPARATOR, 0L );
  2125. strAddress = GetValueByIndex( strVal, NDS_SEPARATOR, 1L );
  2126. hResult = pEMail->put_Type( _ttol( (LPCTSTR) strNumber ) );
  2127. ASSERT( SUCCEEDED( hResult ) );
  2128. bstrVal = AllocBSTR( strAddress.GetBuffer( strAddress.GetLength( ) ) );
  2129. hResult = pEMail->put_Address( bstrVal );
  2130. ASSERT( SUCCEEDED( hResult ) );
  2131. hResult = pEMail->QueryInterface( IID_IDispatch, (void**)&pDisp );
  2132. ASSERT( SUCCEEDED( hResult ) );
  2133. V_VT( &rVar ) = VT_DISPATCH;
  2134. V_DISPATCH( &rVar ) = pDisp;
  2135. break;
  2136. }
  2137. SysFreeString( bstrVal );
  2138. RELEASE( pEMail );
  2139. return hResult;
  2140. }
  2141. /***********************************************************
  2142. Function: COleDsNDSEMail::VARIANT_2_String
  2143. Arguments:
  2144. Return:
  2145. Purpose:
  2146. Author(s):
  2147. Revision:
  2148. Date:
  2149. ***********************************************************/
  2150. HRESULT COleDsNDSEMail::VARIANT_2_String( TCHAR* pszText,
  2151. VARIANT& rVar )
  2152. {
  2153. HRESULT hResult = E_FAIL;
  2154. IADsEmail* pEmail = NULL;
  2155. LONG lType;
  2156. BSTR bstrVal = NULL;
  2157. while( TRUE )
  2158. {
  2159. ASSERT( VT_DISPATCH == V_VT( &rVar ) );
  2160. if( VT_DISPATCH != V_VT( &rVar ) )
  2161. break;
  2162. hResult = V_DISPATCH( &rVar )->QueryInterface( IID_IADsEmail,
  2163. (void**)&pEmail );
  2164. ASSERT( SUCCEEDED( hResult ) );
  2165. if( FAILED( hResult) )
  2166. break;
  2167. hResult = pEmail->get_Type( &lType );
  2168. ASSERT( SUCCEEDED( hResult ) );
  2169. if( FAILED( hResult) )
  2170. break;
  2171. hResult = pEmail->get_Address( &bstrVal );
  2172. ASSERT( SUCCEEDED( hResult ) );
  2173. if( FAILED( hResult) )
  2174. break;
  2175. _ltot( lType, pszText, 10 );
  2176. _tcscat( pszText, NDS_SEPARATOR_S );
  2177. Convert( pszText + _tcslen(pszText), bstrVal );
  2178. break;
  2179. }
  2180. SysFreeString( bstrVal );
  2181. RELEASE( pEmail );
  2182. return hResult;
  2183. }
  2184. /***********************************************************
  2185. Function: COleDsNDSTypedName::COleDsNDSTypedName
  2186. Arguments:
  2187. Return:
  2188. Purpose:
  2189. Author(s):
  2190. Revision:
  2191. Date:
  2192. ***********************************************************/
  2193. COleDsNDSTypedName::COleDsNDSTypedName( )
  2194. {
  2195. m_dwSyntaxID = ADSTYPE_TYPEDNAME;
  2196. }
  2197. /***********************************************************
  2198. Function: COleDsNDSTypedName::Native2Value
  2199. Arguments:
  2200. Return:
  2201. Purpose:
  2202. Author(s):
  2203. Revision:
  2204. Date:
  2205. ***********************************************************/
  2206. HRESULT COleDsNDSTypedName::Native2Value( ADSVALUE* pValue,
  2207. CString& rString )
  2208. {
  2209. int nIdx;
  2210. TCHAR szText[ 256 ];
  2211. ASSERT( ADSTYPE_TYPEDNAME == pValue->dwType );
  2212. if( ADSTYPE_TYPEDNAME != pValue->dwType )
  2213. {
  2214. rString = _T("ERROR: ADSTYPE_TYPEDNAME != pValue->dwType");
  2215. return E_FAIL;
  2216. }
  2217. if( NULL == pValue->pTypedName )
  2218. {
  2219. ASSERT( FALSE );
  2220. return E_FAIL;
  2221. }
  2222. nIdx = 0;
  2223. if( NULL != pValue->pTypedName->ObjectName )
  2224. {
  2225. _stprintf( szText,
  2226. _T("%S & %ld & %ld"),
  2227. pValue->pTypedName->ObjectName,
  2228. pValue->pTypedName->Level,
  2229. pValue->pTypedName->Interval );
  2230. }
  2231. else
  2232. {
  2233. _stprintf( szText,
  2234. _T("NULL & %ld & %ld"),
  2235. pValue->pTypedName->Level,
  2236. pValue->pTypedName->Interval );
  2237. }
  2238. rString = szText;
  2239. return S_OK;
  2240. }
  2241. /***********************************************************
  2242. Function: COleDsNDSTypedName::Value2Native
  2243. Arguments:
  2244. Return:
  2245. Purpose:
  2246. Author(s):
  2247. Revision:
  2248. Date:
  2249. ***********************************************************/
  2250. HRESULT COleDsNDSTypedName::Value2Native( ADSVALUE* pValue,
  2251. CString& rString )
  2252. {
  2253. DWORD dwValues;
  2254. CString strLevel;
  2255. CString strInterval;
  2256. CString strObjectName;
  2257. pValue->dwType = ADSTYPE_TYPEDNAME;
  2258. dwValues = GetValuesCount( rString, NDS_SEPARATOR );
  2259. if( 3 != dwValues )
  2260. {
  2261. ASSERT( FALSE );
  2262. return E_FAIL;
  2263. }
  2264. pValue->pTypedName = (ADS_TYPEDNAME*) AllocADsMem( sizeof(ADS_TYPEDNAME) );
  2265. strObjectName = GetValueByIndex( rString, NDS_SEPARATOR, 0L );
  2266. strLevel = GetValueByIndex( rString, NDS_SEPARATOR, 1L );
  2267. strInterval = GetValueByIndex( rString, NDS_SEPARATOR, 2L );
  2268. pValue->pTypedName->Level = (DWORD)_ttol( (LPCTSTR) strLevel );
  2269. pValue->pTypedName->Interval = (DWORD)_ttol( (LPCTSTR) strInterval );
  2270. pValue->pTypedName->ObjectName= AllocWCHAR( (TCHAR*)(LPCTSTR)strObjectName );
  2271. return S_OK;
  2272. }
  2273. /***********************************************************
  2274. Function: COleDsNDSTypedName::FreeAttrValue
  2275. Arguments:
  2276. Return:
  2277. Purpose:
  2278. Author(s):
  2279. Revision:
  2280. Date:
  2281. ***********************************************************/
  2282. void COleDsNDSTypedName::FreeAttrValue( ADSVALUE* pValue )
  2283. {
  2284. FREE_MEMORY( pValue->pTypedName->ObjectName );
  2285. FREE_MEMORY( pValue->pTypedName );
  2286. }
  2287. /***********************************************************
  2288. Function: COleDsNDSEMail::String_2_VARIANT
  2289. Arguments:
  2290. Return:
  2291. Purpose:
  2292. Author(s):
  2293. Revision:
  2294. Date:
  2295. ***********************************************************/
  2296. HRESULT COleDsNDSTypedName::String_2_VARIANT( TCHAR* pszText,
  2297. VARIANT& rVar )
  2298. {
  2299. DWORD dwValues;
  2300. CString strLevel, strVal;
  2301. CString strInterval;
  2302. CString strObjectName;
  2303. HRESULT hResult;
  2304. IADsTypedName* pTypedName = NULL;
  2305. IDispatch* pDisp = NULL;
  2306. BSTR bstrObjectName = NULL;
  2307. while( TRUE )
  2308. {
  2309. hResult = CoCreateInstance(
  2310. CLSID_TypedName,
  2311. NULL,
  2312. CLSCTX_ALL,
  2313. IID_IADsTypedName,
  2314. (void **)&pTypedName );
  2315. ASSERT( SUCCEEDED( hResult ) );
  2316. if( FAILED( hResult ) )
  2317. break;
  2318. strVal = pszText;
  2319. dwValues = GetValuesCount( strVal, NDS_SEPARATOR );
  2320. if( 3 != dwValues )
  2321. {
  2322. hResult = E_FAIL;
  2323. ASSERT( FALSE );
  2324. break;
  2325. }
  2326. strObjectName = GetValueByIndex( strVal, NDS_SEPARATOR, 0L );
  2327. strLevel = GetValueByIndex( strVal, NDS_SEPARATOR, 1L );
  2328. strInterval = GetValueByIndex( strVal, NDS_SEPARATOR, 2L );
  2329. hResult = pTypedName->put_Level( _ttol( (LPCTSTR) strLevel ) );
  2330. ASSERT( SUCCEEDED( hResult ) );
  2331. hResult = pTypedName->put_Interval( _ttol( (LPCTSTR) strInterval ) );
  2332. ASSERT( SUCCEEDED( hResult ) );
  2333. bstrObjectName = AllocBSTR( strObjectName.GetBuffer( strObjectName.GetLength( ) ) );
  2334. hResult = pTypedName->put_ObjectName( bstrObjectName );
  2335. ASSERT( SUCCEEDED( hResult ) );
  2336. hResult = pTypedName->QueryInterface( IID_IDispatch, (void**)&pDisp );
  2337. ASSERT( SUCCEEDED( hResult ) );
  2338. V_VT( &rVar ) = VT_DISPATCH;
  2339. V_DISPATCH( &rVar ) = pDisp;
  2340. break;
  2341. }
  2342. SysFreeString( bstrObjectName );
  2343. RELEASE( pTypedName );
  2344. return hResult;
  2345. }
  2346. /***********************************************************
  2347. Function: COleDsNDSTypedName::VARIANT_2_String
  2348. Arguments:
  2349. Return:
  2350. Purpose:
  2351. Author(s):
  2352. Revision:
  2353. Date:
  2354. ***********************************************************/
  2355. HRESULT COleDsNDSTypedName::VARIANT_2_String( TCHAR* pszText,
  2356. VARIANT& rVar )
  2357. {
  2358. HRESULT hResult = E_FAIL;
  2359. IADsTypedName* pTypedName = NULL;
  2360. LONG lLevel, lInterval;
  2361. BSTR bstrObjectName = NULL;
  2362. while( TRUE )
  2363. {
  2364. ASSERT( VT_DISPATCH == V_VT( &rVar ) );
  2365. if( VT_DISPATCH != V_VT( &rVar ) )
  2366. break;
  2367. hResult = V_DISPATCH( &rVar )->QueryInterface( IID_IADsTypedName,
  2368. (void**)&pTypedName );
  2369. ASSERT( SUCCEEDED( hResult ) );
  2370. if( FAILED( hResult) )
  2371. break;
  2372. hResult = pTypedName->get_Level( &lLevel );
  2373. ASSERT( SUCCEEDED( hResult ) );
  2374. if( FAILED( hResult) )
  2375. break;
  2376. hResult = pTypedName->get_Interval( &lInterval );
  2377. ASSERT( SUCCEEDED( hResult ) );
  2378. if( FAILED( hResult) )
  2379. break;
  2380. hResult = pTypedName->get_ObjectName( &bstrObjectName );
  2381. ASSERT( SUCCEEDED( hResult ) );
  2382. if( FAILED( hResult) )
  2383. break;
  2384. Convert( pszText, bstrObjectName );
  2385. _tcscat( pszText, NDS_SEPARATOR_S );
  2386. _ltot( lLevel, pszText + _tcslen( pszText), 10 );
  2387. _tcscat( pszText, NDS_SEPARATOR_S );
  2388. _ltot( lInterval, pszText + _tcslen( pszText), 10 );
  2389. break;
  2390. }
  2391. SysFreeString( bstrObjectName );
  2392. RELEASE( pTypedName );
  2393. return hResult;
  2394. }
  2395. /***********************************************************
  2396. Function: COleDsNDSHold::COleDsNDSHold
  2397. Arguments:
  2398. Return:
  2399. Purpose:
  2400. Author(s):
  2401. Revision:
  2402. Date:
  2403. ***********************************************************/
  2404. COleDsNDSHold::COleDsNDSHold( )
  2405. {
  2406. m_dwSyntaxID = ADSTYPE_HOLD;
  2407. }
  2408. /***********************************************************
  2409. Function: COleDsNDSHold::Native2Value
  2410. Arguments:
  2411. Return:
  2412. Purpose:
  2413. Author(s):
  2414. Revision:
  2415. Date:
  2416. ***********************************************************/
  2417. HRESULT COleDsNDSHold::Native2Value( ADSVALUE* pValue,
  2418. CString& rString )
  2419. {
  2420. int nIdx;
  2421. TCHAR szText[ 256 ];
  2422. ASSERT( ADSTYPE_HOLD == pValue->dwType );
  2423. if( ADSTYPE_HOLD != pValue->dwType )
  2424. {
  2425. rString = _T("ERROR: ADSTYPE_HOLD != pValue->dwType");
  2426. return E_FAIL;
  2427. }
  2428. nIdx = 0;
  2429. if( NULL != pValue->Hold.ObjectName )
  2430. {
  2431. _stprintf( szText,
  2432. _T("%ld & %S"),
  2433. pValue->Hold.Amount,
  2434. pValue->Hold.ObjectName );
  2435. }
  2436. else
  2437. {
  2438. _stprintf( szText,
  2439. _T("NULL & %ld "),
  2440. pValue->Hold.Amount );
  2441. }
  2442. rString = szText;
  2443. return S_OK;
  2444. }
  2445. /***********************************************************
  2446. Function: COleDsNDSHold::Value2Native
  2447. Arguments:
  2448. Return:
  2449. Purpose:
  2450. Author(s):
  2451. Revision:
  2452. Date:
  2453. ***********************************************************/
  2454. HRESULT COleDsNDSHold::Value2Native( ADSVALUE* pValue,
  2455. CString& rString )
  2456. {
  2457. DWORD dwValues;
  2458. CString strAmount;
  2459. CString strObjectName;
  2460. pValue->dwType = ADSTYPE_HOLD;
  2461. dwValues = GetValuesCount( rString, NDS_SEPARATOR );
  2462. if( 2 != dwValues )
  2463. {
  2464. ASSERT( FALSE );
  2465. return E_FAIL;
  2466. }
  2467. strAmount = GetValueByIndex( rString, NDS_SEPARATOR, 1L );
  2468. strObjectName = GetValueByIndex( rString, NDS_SEPARATOR, 0L );
  2469. pValue->Hold.Amount = (DWORD)_ttol( (LPCTSTR) strAmount );
  2470. pValue->Hold.ObjectName = AllocWCHAR( (TCHAR*)(LPCTSTR)strObjectName );
  2471. return S_OK;
  2472. }
  2473. /***********************************************************
  2474. Function: COleDsNDSHold::FreeAttrValue
  2475. Arguments:
  2476. Return:
  2477. Purpose:
  2478. Author(s):
  2479. Revision:
  2480. Date:
  2481. ***********************************************************/
  2482. void COleDsNDSHold::FreeAttrValue( ADSVALUE* pValue )
  2483. {
  2484. FREE_MEMORY( pValue->Hold.ObjectName );
  2485. }
  2486. /***********************************************************
  2487. Function: COleDsNDSEMail::String_2_VARIANT
  2488. Arguments:
  2489. Return:
  2490. Purpose:
  2491. Author(s):
  2492. Revision:
  2493. Date:
  2494. ***********************************************************/
  2495. HRESULT COleDsNDSHold::String_2_VARIANT( TCHAR* pszText,
  2496. VARIANT& rVar )
  2497. {
  2498. DWORD dwValues;
  2499. CString strAmount, strVal;
  2500. CString strObjectName;
  2501. HRESULT hResult;
  2502. IADsHold* pHold = NULL;
  2503. IDispatch* pDisp = NULL;
  2504. BSTR bstrObjectName = NULL;
  2505. while( TRUE )
  2506. {
  2507. hResult = CoCreateInstance(
  2508. CLSID_Hold,
  2509. NULL,
  2510. CLSCTX_ALL,
  2511. IID_IADsHold,
  2512. (void **)&pHold );
  2513. ASSERT( SUCCEEDED( hResult ) );
  2514. if( FAILED( hResult ) )
  2515. break;
  2516. strVal = pszText;
  2517. dwValues = GetValuesCount( strVal, NDS_SEPARATOR );
  2518. if( 2 != dwValues )
  2519. {
  2520. hResult = E_FAIL;
  2521. ASSERT( FALSE );
  2522. break;
  2523. }
  2524. strAmount = GetValueByIndex( strVal, NDS_SEPARATOR, 1L );
  2525. strObjectName = GetValueByIndex( strVal, NDS_SEPARATOR, 0L );
  2526. hResult = pHold->put_Amount( _ttol( (LPCTSTR) strAmount ) );
  2527. ASSERT( SUCCEEDED( hResult ) );
  2528. bstrObjectName = AllocBSTR( strObjectName.GetBuffer( strObjectName.GetLength( ) ) );
  2529. hResult = pHold->put_ObjectName( bstrObjectName );
  2530. ASSERT( SUCCEEDED( hResult ) );
  2531. hResult = pHold->QueryInterface( IID_IDispatch, (void**)&pDisp );
  2532. ASSERT( SUCCEEDED( hResult ) );
  2533. V_VT( &rVar ) = VT_DISPATCH;
  2534. V_DISPATCH( &rVar ) = pDisp;
  2535. break;
  2536. }
  2537. SysFreeString( bstrObjectName );
  2538. RELEASE( pHold );
  2539. return hResult;
  2540. }
  2541. /***********************************************************
  2542. Function: COleDsNDSHold::VARIANT_2_String
  2543. Arguments:
  2544. Return:
  2545. Purpose:
  2546. Author(s):
  2547. Revision:
  2548. Date:
  2549. ***********************************************************/
  2550. HRESULT COleDsNDSHold::VARIANT_2_String( TCHAR* pszText,
  2551. VARIANT& rVar )
  2552. {
  2553. HRESULT hResult = E_FAIL;
  2554. IADsHold* pHold = NULL;
  2555. LONG lAmount;
  2556. BSTR bstrObjectName = NULL;
  2557. while( TRUE )
  2558. {
  2559. ASSERT( VT_DISPATCH == V_VT( &rVar ) );
  2560. if( VT_DISPATCH != V_VT( &rVar ) )
  2561. break;
  2562. hResult = V_DISPATCH( &rVar )->QueryInterface( IID_IADsHold,
  2563. (void**)&pHold );
  2564. ASSERT( SUCCEEDED( hResult ) );
  2565. if( FAILED( hResult) )
  2566. break;
  2567. hResult = pHold->get_Amount( &lAmount );
  2568. ASSERT( SUCCEEDED( hResult ) );
  2569. if( FAILED( hResult) )
  2570. break;
  2571. hResult = pHold->get_ObjectName( &bstrObjectName );
  2572. ASSERT( SUCCEEDED( hResult ) );
  2573. if( FAILED( hResult) )
  2574. break;
  2575. Convert( pszText, bstrObjectName );
  2576. _tcscat( pszText, NDS_SEPARATOR_S );
  2577. _ltot( lAmount, pszText + _tcslen( pszText), 10 );
  2578. break;
  2579. }
  2580. SysFreeString( bstrObjectName );
  2581. RELEASE( pHold );
  2582. return hResult;
  2583. }
  2584. /***********************************************************
  2585. Function: COleDsNDSBackLink::COleDsNDSBackLink
  2586. Arguments:
  2587. Return:
  2588. Purpose:
  2589. Author(s):
  2590. Revision:
  2591. Date:
  2592. ***********************************************************/
  2593. COleDsNDSBackLink::COleDsNDSBackLink( )
  2594. {
  2595. m_dwSyntaxID = ADSTYPE_BACKLINK;
  2596. }
  2597. /***********************************************************
  2598. Function: COleDsNDSBackLink::Native2Value
  2599. Arguments:
  2600. Return:
  2601. Purpose:
  2602. Author(s):
  2603. Revision:
  2604. Date:
  2605. ***********************************************************/
  2606. HRESULT COleDsNDSBackLink::Native2Value( ADSVALUE* pValue,
  2607. CString& rString )
  2608. {
  2609. int nIdx;
  2610. TCHAR szText[ 256 ];
  2611. ASSERT( ADSTYPE_BACKLINK == pValue->dwType );
  2612. if( ADSTYPE_BACKLINK != pValue->dwType )
  2613. {
  2614. rString = _T("ERROR: ADSTYPE_BACKLINK != pValue->dwType");
  2615. return E_FAIL;
  2616. }
  2617. nIdx = 0;
  2618. if( NULL != pValue->BackLink.ObjectName )
  2619. {
  2620. _stprintf( szText,
  2621. _T("%ld & %S"),
  2622. pValue->BackLink.RemoteID,
  2623. pValue->BackLink.ObjectName );
  2624. }
  2625. else
  2626. {
  2627. _stprintf( szText,
  2628. _T("%ld & NULL"),
  2629. pValue->BackLink.RemoteID );
  2630. }
  2631. rString = szText;
  2632. return S_OK;
  2633. }
  2634. /***********************************************************
  2635. Function: COleDsNDSBackLink::Value2Native
  2636. Arguments:
  2637. Return:
  2638. Purpose:
  2639. Author(s):
  2640. Revision:
  2641. Date:
  2642. ***********************************************************/
  2643. HRESULT COleDsNDSBackLink::Value2Native( ADSVALUE* pValue,
  2644. CString& rString )
  2645. {
  2646. DWORD dwValues;
  2647. CString strRemoteID;
  2648. CString strObjectName;
  2649. pValue->dwType = ADSTYPE_BACKLINK;
  2650. dwValues = GetValuesCount( rString, NDS_SEPARATOR );
  2651. if( 2 != dwValues )
  2652. {
  2653. ASSERT( FALSE );
  2654. return E_FAIL;
  2655. }
  2656. strRemoteID = GetValueByIndex( rString, NDS_SEPARATOR, 0L );
  2657. strObjectName = GetValueByIndex( rString, NDS_SEPARATOR, 1L );
  2658. pValue->BackLink.RemoteID = (DWORD)_ttol( (LPCTSTR) strRemoteID );
  2659. pValue->BackLink.ObjectName = AllocWCHAR( (TCHAR*)(LPCTSTR)strObjectName );
  2660. return S_OK;
  2661. }
  2662. /***********************************************************
  2663. Function: COleDsNDSBackLink::FreeAttrValue
  2664. Arguments:
  2665. Return:
  2666. Purpose:
  2667. Author(s):
  2668. Revision:
  2669. Date:
  2670. ***********************************************************/
  2671. void COleDsNDSBackLink::FreeAttrValue( ADSVALUE* pValue )
  2672. {
  2673. FREE_MEMORY( pValue->BackLink.ObjectName );
  2674. }
  2675. /***********************************************************
  2676. Function: COleDsNDSEMail::String_2_VARIANT
  2677. Arguments:
  2678. Return:
  2679. Purpose:
  2680. Author(s):
  2681. Revision:
  2682. Date:
  2683. ***********************************************************/
  2684. HRESULT COleDsNDSBackLink::String_2_VARIANT( TCHAR* pszText,
  2685. VARIANT& rVar )
  2686. {
  2687. DWORD dwValues;
  2688. CString strRemoteID, strVal;
  2689. CString strObjectName;
  2690. HRESULT hResult;
  2691. IADsBackLink* pBackLink = NULL;
  2692. IDispatch* pDisp = NULL;
  2693. BSTR bstrObjectName = NULL;
  2694. while( TRUE )
  2695. {
  2696. hResult = CoCreateInstance(
  2697. CLSID_BackLink,
  2698. NULL,
  2699. CLSCTX_ALL,
  2700. IID_IADsBackLink,
  2701. (void **)&pBackLink );
  2702. ASSERT( SUCCEEDED( hResult ) );
  2703. if( FAILED( hResult ) )
  2704. break;
  2705. strVal = pszText;
  2706. dwValues = GetValuesCount( strVal, NDS_SEPARATOR );
  2707. if( 2 != dwValues )
  2708. {
  2709. hResult = E_FAIL;
  2710. ASSERT( FALSE );
  2711. break;
  2712. }
  2713. strRemoteID = GetValueByIndex( strVal, NDS_SEPARATOR, 0L );
  2714. strObjectName = GetValueByIndex( strVal, NDS_SEPARATOR, 1L );
  2715. hResult = pBackLink->put_RemoteID( _ttol( (LPCTSTR) strRemoteID ) );
  2716. ASSERT( SUCCEEDED( hResult ) );
  2717. bstrObjectName = AllocBSTR( strObjectName.GetBuffer( strObjectName.GetLength( ) ) );
  2718. hResult = pBackLink->put_ObjectName( bstrObjectName );
  2719. ASSERT( SUCCEEDED( hResult ) );
  2720. hResult = pBackLink->QueryInterface( IID_IDispatch, (void**)&pDisp );
  2721. ASSERT( SUCCEEDED( hResult ) );
  2722. V_VT( &rVar ) = VT_DISPATCH;
  2723. V_DISPATCH( &rVar ) = pDisp;
  2724. break;
  2725. }
  2726. SysFreeString( bstrObjectName );
  2727. RELEASE( pBackLink );
  2728. return hResult;
  2729. }
  2730. /***********************************************************
  2731. Function: COleDsNDSBackLink::VARIANT_2_String
  2732. Arguments:
  2733. Return:
  2734. Purpose:
  2735. Author(s):
  2736. Revision:
  2737. Date:
  2738. ***********************************************************/
  2739. HRESULT COleDsNDSBackLink::VARIANT_2_String( TCHAR* pszText,
  2740. VARIANT& rVar )
  2741. {
  2742. HRESULT hResult = E_FAIL;
  2743. IADsBackLink* pBackLink = NULL;
  2744. LONG lRemoteID;
  2745. BSTR bstrObjectName = NULL;
  2746. while( TRUE )
  2747. {
  2748. ASSERT( VT_DISPATCH == V_VT( &rVar ) );
  2749. if( VT_DISPATCH != V_VT( &rVar ) )
  2750. break;
  2751. hResult = V_DISPATCH( &rVar )->QueryInterface( IID_IADsBackLink,
  2752. (void**)&pBackLink );
  2753. ASSERT( SUCCEEDED( hResult ) );
  2754. if( FAILED( hResult) )
  2755. break;
  2756. hResult = pBackLink->get_RemoteID( &lRemoteID );
  2757. ASSERT( SUCCEEDED( hResult ) );
  2758. if( FAILED( hResult) )
  2759. break;
  2760. hResult = pBackLink->get_ObjectName( &bstrObjectName );
  2761. ASSERT( SUCCEEDED( hResult ) );
  2762. if( FAILED( hResult) )
  2763. break;
  2764. _ltot( lRemoteID, pszText, 10 );
  2765. _tcscat( pszText, NDS_SEPARATOR_S );
  2766. Convert( pszText + _tcslen(pszText), bstrObjectName );
  2767. break;
  2768. }
  2769. SysFreeString( bstrObjectName );
  2770. RELEASE( pBackLink );
  2771. return hResult;
  2772. }
  2773. /***********************************************************
  2774. Function: COleDsNDSPostalAddress::COleDsNDSPostalAddress
  2775. Arguments:
  2776. Return:
  2777. Purpose:
  2778. Author(s):
  2779. Revision:
  2780. Date:
  2781. ***********************************************************/
  2782. COleDsNDSPath::COleDsNDSPath ( )
  2783. {
  2784. m_dwSyntaxID = ADSTYPE_PATH;
  2785. }
  2786. /***********************************************************
  2787. Function: COleDsNDSPath::Native2Value
  2788. Arguments:
  2789. Return:
  2790. Purpose:
  2791. Author(s):
  2792. Revision:
  2793. Date:
  2794. ***********************************************************/
  2795. HRESULT COleDsNDSPath::Native2Value( ADSVALUE* pValue,
  2796. CString& rString )
  2797. {
  2798. int nIdx;
  2799. TCHAR szText[ 256 ];
  2800. ASSERT( ADSTYPE_PATH == pValue->dwType );
  2801. if( ADSTYPE_PATH != pValue->dwType )
  2802. {
  2803. rString = _T("ERROR: ADSTYPE_PATH != pValue->dwType");
  2804. return E_FAIL;
  2805. }
  2806. nIdx = 0;
  2807. if( NULL != pValue->pPath )
  2808. {
  2809. _stprintf( szText,
  2810. _T("%ld & %S & %S"),
  2811. pValue->pPath->Type,
  2812. pValue->pPath->VolumeName,
  2813. pValue->pPath->Path);
  2814. }
  2815. else
  2816. {
  2817. _stprintf( szText,
  2818. _T("%ld & NULL & NULL"),
  2819. pValue->pPath->Type );
  2820. }
  2821. rString = szText;
  2822. return S_OK;
  2823. }
  2824. /***********************************************************
  2825. Function: COleDsNDSPath::Value2Native
  2826. Arguments:
  2827. Return:
  2828. Purpose:
  2829. Author(s):
  2830. Revision:
  2831. Date:
  2832. ***********************************************************/
  2833. HRESULT COleDsNDSPath::Value2Native( ADSVALUE* pValue,
  2834. CString& rString )
  2835. {
  2836. DWORD dwValues;
  2837. CString strType;
  2838. CString strVolName;
  2839. CString strPath;
  2840. pValue->pPath = (ADS_PATH*) AllocADsMem( sizeof(ADS_PATH) );
  2841. if( NULL == pValue->pPath )
  2842. return E_FAIL;
  2843. pValue->pPath->VolumeName = NULL;
  2844. pValue->pPath->Path = NULL;
  2845. pValue->dwType = ADSTYPE_PATH;
  2846. dwValues = GetValuesCount( rString, NDS_SEPARATOR );
  2847. if( 3 != dwValues )
  2848. {
  2849. ASSERT( FALSE );
  2850. return E_FAIL;
  2851. }
  2852. strType = GetValueByIndex( rString, NDS_SEPARATOR, 0L );
  2853. strVolName = GetValueByIndex( rString, NDS_SEPARATOR, 1L );
  2854. strPath = GetValueByIndex( rString, NDS_SEPARATOR, 2L );
  2855. pValue->pPath->Type = (DWORD)_ttol( (LPCTSTR) strType );
  2856. pValue->pPath->VolumeName = AllocWCHAR( strVolName.GetBuffer( strVolName.GetLength( ) ) );
  2857. pValue->pPath->Path = AllocWCHAR( strPath.GetBuffer( strPath.GetLength( ) ) );
  2858. return S_OK;
  2859. }
  2860. /***********************************************************
  2861. Function: COleDsNDSEMail::FreeAttrValue
  2862. Arguments:
  2863. Return:
  2864. Purpose:
  2865. Author(s):
  2866. Revision:
  2867. Date:
  2868. ***********************************************************/
  2869. void COleDsNDSPath::FreeAttrValue( ADSVALUE* pValue )
  2870. {
  2871. FREE_MEMORY( pValue->pPath->VolumeName );
  2872. FREE_MEMORY( pValue->pPath->Path );
  2873. FREE_MEMORY( pValue->pPath );
  2874. }
  2875. /***********************************************************
  2876. Function: COleDsNDSPath::String_2_VARIANT
  2877. Arguments:
  2878. Return:
  2879. Purpose:
  2880. Author(s):
  2881. Revision:
  2882. Date:
  2883. ***********************************************************/
  2884. HRESULT COleDsNDSPath::String_2_VARIANT( TCHAR* pszText,
  2885. VARIANT& rVar )
  2886. {
  2887. DWORD dwValues;
  2888. CString strType, strVal;
  2889. CString strVolName;
  2890. CString strPath;
  2891. HRESULT hResult;
  2892. IADsPath* pPath = NULL;
  2893. IDispatch* pDisp = NULL;
  2894. BSTR bstrVal = NULL;
  2895. while( TRUE )
  2896. {
  2897. hResult = CoCreateInstance(
  2898. CLSID_Path,
  2899. NULL,
  2900. CLSCTX_ALL,
  2901. IID_IADsPath,
  2902. (void **)&pPath );
  2903. ASSERT( SUCCEEDED( hResult ) );
  2904. if( FAILED( hResult ) )
  2905. break;
  2906. strVal = pszText;
  2907. dwValues = GetValuesCount( strVal, NDS_SEPARATOR );
  2908. if( 3 != dwValues )
  2909. {
  2910. hResult = E_FAIL;
  2911. ASSERT( FALSE );
  2912. break;
  2913. }
  2914. strType = GetValueByIndex( strVal, NDS_SEPARATOR, 0L );
  2915. strVolName = GetValueByIndex( strVal, NDS_SEPARATOR, 1L );
  2916. strPath = GetValueByIndex( strVal, NDS_SEPARATOR, 2L );
  2917. hResult = pPath->put_Type( _ttol( (LPCTSTR) strType ) );
  2918. ASSERT( SUCCEEDED( hResult ) );
  2919. bstrVal = AllocBSTR( strVolName.GetBuffer( strVolName.GetLength( ) ) );
  2920. hResult = pPath->put_VolumeName( bstrVal );
  2921. ASSERT( SUCCEEDED( hResult ) );
  2922. SysFreeString( bstrVal );
  2923. bstrVal = AllocBSTR( strPath.GetBuffer( strPath.GetLength( ) ) );
  2924. hResult = pPath->put_Path( bstrVal );
  2925. ASSERT( SUCCEEDED( hResult ) );
  2926. SysFreeString( bstrVal );
  2927. hResult = pPath->QueryInterface( IID_IDispatch, (void**)&pDisp );
  2928. ASSERT( SUCCEEDED( hResult ) );
  2929. V_VT( &rVar ) = VT_DISPATCH;
  2930. V_DISPATCH( &rVar ) = pDisp;
  2931. break;
  2932. }
  2933. RELEASE( pPath );
  2934. return hResult;
  2935. }
  2936. /***********************************************************
  2937. Function: COleDsNDSPath::VARIANT_2_String
  2938. Arguments:
  2939. Return:
  2940. Purpose:
  2941. Author(s):
  2942. Revision:
  2943. Date:
  2944. ***********************************************************/
  2945. HRESULT COleDsNDSPath::VARIANT_2_String( TCHAR* pszText,
  2946. VARIANT& rVar )
  2947. {
  2948. HRESULT hResult = E_FAIL;
  2949. IADsPath* pPath = NULL;
  2950. LONG lType;
  2951. BSTR bstrVolName = NULL;
  2952. BSTR bstrPath = NULL;
  2953. while( TRUE )
  2954. {
  2955. ASSERT( VT_DISPATCH == V_VT( &rVar ) );
  2956. if( VT_DISPATCH != V_VT( &rVar ) )
  2957. break;
  2958. hResult = V_DISPATCH( &rVar )->QueryInterface( IID_IADsPath,
  2959. (void**)&pPath );
  2960. ASSERT( SUCCEEDED( hResult ) );
  2961. if( FAILED( hResult) )
  2962. break;
  2963. hResult = pPath->get_Type( &lType );
  2964. ASSERT( SUCCEEDED( hResult ) );
  2965. if( FAILED( hResult) )
  2966. break;
  2967. hResult = pPath->get_VolumeName( &bstrVolName );
  2968. ASSERT( SUCCEEDED( hResult ) );
  2969. if( FAILED( hResult) )
  2970. break;
  2971. hResult = pPath->get_Path( &bstrPath );
  2972. ASSERT( SUCCEEDED( hResult ) );
  2973. if( FAILED( hResult) )
  2974. break;
  2975. _ltot( lType, pszText, 10 );
  2976. _tcscat( pszText, NDS_SEPARATOR_S );
  2977. Convert( pszText + _tcslen(pszText), bstrVolName );
  2978. _tcscat( pszText, NDS_SEPARATOR_S );
  2979. Convert( pszText + _tcslen(pszText), bstrPath );
  2980. break;
  2981. }
  2982. SysFreeString( bstrVolName );
  2983. SysFreeString( bstrPath );
  2984. RELEASE( pPath );
  2985. return hResult;
  2986. }
  2987. /***********************************************************
  2988. Function: COleDsNDSTimeStamp::COleDsNDSTimeStamp
  2989. Arguments:
  2990. Return:
  2991. Purpose:
  2992. Author(s):
  2993. Revision:
  2994. Date:
  2995. ***********************************************************/
  2996. COleDsNDSTimeStamp::COleDsNDSTimeStamp( )
  2997. {
  2998. m_dwSyntaxID = ADSTYPE_TIMESTAMP;
  2999. }
  3000. /***********************************************************
  3001. Function: COleDsNDSTimeStamp::GenerateString
  3002. Arguments:
  3003. Return:
  3004. Purpose:
  3005. Author(s):
  3006. Revision:
  3007. Date:
  3008. ***********************************************************/
  3009. HRESULT COleDsNDSTimeStamp::GenerateString( TCHAR* szText,
  3010. DWORD dwWholeSeconds,
  3011. DWORD dwEventID )
  3012. {
  3013. _tcscpy( szText, _T("WholeSeconds: ") );
  3014. _ultot( dwWholeSeconds,
  3015. szText + _tcslen(szText),
  3016. 10 );
  3017. _tcscat( szText, _T("EventID: ") );
  3018. _ultot( dwEventID,
  3019. szText + _tcslen(szText),
  3020. 10 );
  3021. return S_OK;
  3022. }
  3023. /***********************************************************
  3024. Function: COleDsNDSTimeStamp::GetComponents
  3025. Arguments:
  3026. Return:
  3027. Purpose:
  3028. Author(s):
  3029. Revision:
  3030. Date:
  3031. ***********************************************************/
  3032. HRESULT COleDsNDSTimeStamp::GetComponents( TCHAR* pszString,
  3033. DWORD* pdwWholeSeconds,
  3034. DWORD* pdwEventID )
  3035. {
  3036. TCHAR szText1[ 128 ];
  3037. TCHAR szText2[ 128 ];
  3038. int nRet = 0;
  3039. *pdwWholeSeconds = 0xAABBCCDD;
  3040. *pdwEventID = 0xAABBCCDD;
  3041. nRet = _stscanf( pszString, _T("%s%d%s%d"), szText1,
  3042. pdwWholeSeconds, szText2, pdwWholeSeconds );
  3043. if (4 != nRet)
  3044. return E_FAIL;
  3045. return ( (*pdwWholeSeconds == 0xAABBCCDD) && (*pdwEventID == 0xAABBCCDD) ) ?
  3046. S_OK : E_FAIL;
  3047. }
  3048. /***********************************************************
  3049. Function: COleDsNDSTimeStamp::Value2Native
  3050. Arguments:
  3051. Return:
  3052. Purpose:
  3053. Author(s):
  3054. Revision:
  3055. Date:
  3056. ***********************************************************/
  3057. HRESULT COleDsNDSTimeStamp::Value2Native ( ADSVALUE* pValue,
  3058. CString& rString )
  3059. {
  3060. DWORD dwValues;
  3061. CString strWholeSeconds;
  3062. CString strEventID;
  3063. pValue->dwType = ADSTYPE_TIMESTAMP;
  3064. dwValues = GetValuesCount( rString, NDS_SEPARATOR );
  3065. if( 2 != dwValues )
  3066. {
  3067. ASSERT( FALSE );
  3068. return E_FAIL;
  3069. }
  3070. strWholeSeconds= GetValueByIndex( rString, NDS_SEPARATOR, 0L );
  3071. strEventID = GetValueByIndex( rString, NDS_SEPARATOR, 1L );
  3072. pValue->Timestamp.WholeSeconds= (DWORD)_ttol( (LPCTSTR) strWholeSeconds );
  3073. pValue->Timestamp.EventID = (DWORD)_ttol( (LPCTSTR) strEventID );
  3074. return S_OK;
  3075. }
  3076. /***********************************************************
  3077. Function: COleDsNDSTimeStamp::Native2Value
  3078. Arguments:
  3079. Return:
  3080. Purpose:
  3081. Author(s):
  3082. Revision:
  3083. Date:
  3084. ***********************************************************/
  3085. HRESULT COleDsNDSTimeStamp::Native2Value( ADSVALUE* pValue,
  3086. CString& rString)
  3087. {
  3088. TCHAR szText[ 128 ];
  3089. ASSERT( ADSTYPE_TIMESTAMP != pValue->dwType );
  3090. if( ADSTYPE_TIMESTAMP != pValue->dwType )
  3091. {
  3092. rString = _T("ERROR: ADSTYPE_TIMESTAMP != pValue->dwType");
  3093. return E_FAIL;
  3094. }
  3095. _ultot( pValue->Timestamp.WholeSeconds,
  3096. szText,
  3097. 10 );
  3098. _tcscat( szText, NDS_SEPARATOR_S );
  3099. _ultot( pValue->Timestamp.EventID,
  3100. szText + _tcslen(szText),
  3101. 10 );
  3102. rString = szText;
  3103. return S_OK;
  3104. }
  3105. /***********************************************************
  3106. Function: COleDsNDSTimeStamp::String_2_VARIANT
  3107. Arguments:
  3108. Return:
  3109. Purpose:
  3110. Author(s):
  3111. Revision:
  3112. Date:
  3113. ***********************************************************/
  3114. HRESULT COleDsNDSTimeStamp::String_2_VARIANT( TCHAR* pszText,
  3115. VARIANT& rVar )
  3116. {
  3117. HRESULT hResult;
  3118. IADsTimestamp* pTimeStamp;
  3119. DWORD dwValues;
  3120. CString strWholeSeconds;
  3121. CString strEventID;
  3122. CString rString;
  3123. rString = pszText;
  3124. dwValues = GetValuesCount( rString, NDS_SEPARATOR );
  3125. if( 2 != dwValues )
  3126. {
  3127. ASSERT( FALSE );
  3128. return E_FAIL;
  3129. }
  3130. strWholeSeconds= GetValueByIndex( rString, NDS_SEPARATOR, 0L );
  3131. strEventID = GetValueByIndex( rString, NDS_SEPARATOR, 1L );
  3132. hResult = hResult = CoCreateInstance(
  3133. CLSID_Timestamp,
  3134. NULL,
  3135. CLSCTX_INPROC_SERVER,
  3136. IID_IADsTimestamp,
  3137. (void **)&pTimeStamp );
  3138. ASSERT( SUCCEEDED( hResult ) );
  3139. if( FAILED( hResult ) )
  3140. return hResult;
  3141. hResult = pTimeStamp->put_WholeSeconds( _ttol( (LPCTSTR) strWholeSeconds ) );
  3142. ASSERT( SUCCEEDED( hResult ) );
  3143. hResult = pTimeStamp->put_EventID( _ttol( (LPCTSTR) strEventID ) );
  3144. ASSERT( SUCCEEDED( hResult ) );
  3145. if( SUCCEEDED( hResult ) )
  3146. {
  3147. IDispatch* pDisp = NULL;
  3148. V_VT( &rVar ) = VT_DISPATCH;
  3149. hResult = pTimeStamp->QueryInterface( IID_IDispatch, (void**)&pDisp );
  3150. ASSERT( SUCCEEDED( hResult ) );
  3151. V_DISPATCH( &rVar ) = pDisp;
  3152. }
  3153. pTimeStamp->Release( );
  3154. return hResult;
  3155. }
  3156. /***********************************************************
  3157. Function: COleDsNDSTimeStamp::VARIANT_2_String
  3158. Arguments:
  3159. Return:
  3160. Purpose:
  3161. Author(s):
  3162. Revision:
  3163. Date:
  3164. ***********************************************************/
  3165. HRESULT COleDsNDSTimeStamp::VARIANT_2_String( TCHAR* pszText, VARIANT& rVar )
  3166. {
  3167. IADsTimestamp* pTimeStamp = NULL;
  3168. HRESULT hResult;
  3169. long lWholeSeconds, lEventID;
  3170. ASSERT( VT_DISPATCH == V_VT( &rVar) );
  3171. if( VT_DISPATCH != V_VT( &rVar) )
  3172. {
  3173. _tcscpy( pszText, _T("ERROR: VT_DISPATCH != V_VT( &rVar)") );
  3174. return E_FAIL;
  3175. }
  3176. hResult = V_DISPATCH( &rVar )->QueryInterface( IID_IADsTimestamp,
  3177. (void**)&pTimeStamp );
  3178. ASSERT( SUCCEEDED( hResult ) );
  3179. if( FAILED( hResult ) )
  3180. {
  3181. _tcscpy( pszText, _T("ERROR: QI for IID_IADsTimeStamp fails") );
  3182. return hResult;
  3183. }
  3184. hResult = pTimeStamp->get_WholeSeconds( &lWholeSeconds );
  3185. ASSERT( SUCCEEDED( hResult ) );
  3186. hResult = pTimeStamp->get_EventID( &lEventID );
  3187. ASSERT( SUCCEEDED( hResult ) );
  3188. pTimeStamp->Release( );
  3189. _ultot( lWholeSeconds,
  3190. pszText,
  3191. 10 );
  3192. _tcscat( pszText, NDS_SEPARATOR_S );
  3193. _ultot( lEventID,
  3194. pszText + _tcslen(pszText),
  3195. 10 );
  3196. return hResult;
  3197. }
  3198. /***********************************************************
  3199. Function: COleDsNDSComplexType::COleDsNDSComplexType
  3200. Arguments:
  3201. Return:
  3202. Purpose:
  3203. Author(s):
  3204. Revision:
  3205. Date:
  3206. ***********************************************************/
  3207. COleDsNDSComplexType::COleDsNDSComplexType( )
  3208. {
  3209. }
  3210. /***********************************************************
  3211. Function:
  3212. Arguments:
  3213. Return:
  3214. Purpose:
  3215. Author(s):
  3216. Revision:
  3217. Date:
  3218. ***********************************************************/
  3219. CString COleDsNDSComplexType::VarToDisplayStringEx( VARIANT& var,
  3220. BOOL bMultiValued )
  3221. {
  3222. SAFEARRAY* pSArray;
  3223. HRESULT hResult;
  3224. LONG uLow, uHigh, uIndex;
  3225. VARIANT vItem;
  3226. CString strVal;
  3227. CString strTemp;
  3228. pSArray = V_ARRAY( &var );
  3229. hResult = SafeArrayGetLBound( pSArray, 1, &uLow );
  3230. hResult = SafeArrayGetUBound( pSArray, 1, &uHigh );
  3231. if( !bMultiValued )
  3232. {
  3233. ASSERT( uLow == uHigh );
  3234. }
  3235. for( uIndex = uLow; uIndex <= uHigh; uIndex++ )
  3236. {
  3237. if( uIndex != uLow )
  3238. {
  3239. strVal += SEPARATOR_S;
  3240. }
  3241. VariantInit( &vItem );
  3242. hResult = SafeArrayGetElement( pSArray, &uIndex, &vItem );
  3243. ASSERT( SUCCEEDED( hResult ) );
  3244. strTemp = VarToDisplayString( vItem, bMultiValued, FALSE );
  3245. VariantClear( &vItem );
  3246. strVal += strTemp;
  3247. if( strVal.GetLength( ) > 8096 )
  3248. break;
  3249. }
  3250. return strVal;
  3251. }
  3252. /***********************************************************
  3253. Function:
  3254. Arguments:
  3255. Return:
  3256. Purpose:
  3257. Author(s):
  3258. Revision:
  3259. Date:
  3260. ***********************************************************/
  3261. CString COleDsNDSComplexType::VarToDisplayString( VARIANT& var,
  3262. BOOL bMultiValued,
  3263. BOOL bUseEx )
  3264. {
  3265. LONG uLow, uHigh, uIndex;
  3266. SAFEARRAY* psa;
  3267. VARIANT vItem;
  3268. CString strVal, strTemp;
  3269. HRESULT hResult;
  3270. TCHAR szText[ 2048 ];
  3271. if( bUseEx )
  3272. {
  3273. return VarToDisplayStringEx( var, bMultiValued );
  3274. }
  3275. if( bMultiValued )
  3276. {
  3277. if( VT_DISPATCH == V_VT( &var ) )
  3278. {
  3279. VARIANT_2_String( szText, var );
  3280. return CString( szText );
  3281. }
  3282. ASSERT( (VT_ARRAY | VT_VARIANT) == V_VT(&var) );
  3283. if( (VT_ARRAY | VT_VARIANT) == V_VT(&var) )
  3284. {
  3285. return CString( _T("ERROR: (VT_ARRAY | VT_VARIANT) != V_VT(&var)") );
  3286. }
  3287. psa = V_ARRAY( &var );
  3288. ASSERT( NULL != psa );
  3289. if( NULL == psa )
  3290. {
  3291. return CString( _T("ERROR: NULL == psa" ) );
  3292. }
  3293. hResult = SafeArrayGetLBound( psa, 1, &uLow );
  3294. hResult = SafeArrayGetUBound( psa, 1, &uHigh );
  3295. for( uIndex = uLow; uIndex <= uHigh; uIndex++ )
  3296. {
  3297. if( uIndex != uLow )
  3298. {
  3299. strVal += SEPARATOR_S;
  3300. }
  3301. VariantInit( &vItem );
  3302. hResult = SafeArrayGetElement( psa, &uIndex, &vItem );
  3303. ASSERT( SUCCEEDED( hResult ) );
  3304. strTemp = VarToDisplayString( vItem, FALSE, FALSE );
  3305. VariantClear( &vItem );
  3306. strVal += strTemp;
  3307. if( strVal.GetLength( ) > 8096 )
  3308. break;
  3309. }
  3310. }
  3311. else
  3312. {
  3313. hResult = VARIANT_2_String( szText, var );
  3314. if( SUCCEEDED( hResult ) )
  3315. {
  3316. strVal = szText;
  3317. }
  3318. else
  3319. {
  3320. strVal = OleDsGetErrorText( hResult );
  3321. }
  3322. }
  3323. return strVal;
  3324. }
  3325. /***********************************************************
  3326. Function:
  3327. Arguments:
  3328. Return:
  3329. Purpose:
  3330. Author(s):
  3331. Revision:
  3332. Date:
  3333. ***********************************************************/
  3334. BOOL COleDsNDSComplexType::DisplayStringToDispParamsEx( CString& rText,
  3335. DISPPARAMS& dispParams,
  3336. BOOL bMultiValued )
  3337. {
  3338. SAFEARRAY* pSArray;
  3339. SAFEARRAYBOUND saBound;
  3340. HRESULT hResult;
  3341. LONG lIdx = LBOUND;
  3342. DisplayStringToDispParams( rText, dispParams, bMultiValued, FALSE );
  3343. if( !bMultiValued )
  3344. {
  3345. saBound.lLbound = LBOUND;
  3346. saBound.cElements = 1;
  3347. pSArray = SafeArrayCreate( VT_VARIANT, 1, &saBound );
  3348. hResult = SafeArrayPutElement( pSArray, &lIdx, &dispParams.rgvarg[0] );
  3349. VariantClear( &dispParams.rgvarg[0] );
  3350. V_VT( &dispParams.rgvarg[0] ) = VT_ARRAY | VT_VARIANT;
  3351. V_ARRAY( &dispParams.rgvarg[0] ) = pSArray;
  3352. }
  3353. return TRUE;
  3354. }
  3355. /***********************************************************
  3356. Function:
  3357. Arguments:
  3358. Return:
  3359. Purpose:
  3360. Author(s):
  3361. Revision:
  3362. Date:
  3363. ***********************************************************/
  3364. BOOL COleDsNDSComplexType::DisplayStringToDispParams( CString& rText,
  3365. DISPPARAMS& dispParams,
  3366. BOOL bMultiValued,
  3367. BOOL bUseEx )
  3368. {
  3369. HRESULT hResult;
  3370. int x= 0;
  3371. if( bUseEx )
  3372. {
  3373. return DisplayStringToDispParamsEx( rText, dispParams, bMultiValued );
  3374. }
  3375. dispParams.rgdispidNamedArgs[ 0 ] = DISPID_PROPERTYPUT;
  3376. dispParams.cArgs = 1;
  3377. dispParams.cNamedArgs = 1;
  3378. if( bMultiValued )
  3379. {
  3380. SAFEARRAY* psa;
  3381. SAFEARRAYBOUND sab;
  3382. TCHAR* strText;
  3383. TCHAR* strStore;
  3384. int nItems = 0;
  3385. int nIdx;
  3386. int nSize;
  3387. //rText.MakeUpper( );
  3388. strText = (TCHAR*) new TCHAR[ rText.GetLength( ) + 1 ];
  3389. strStore = strText;
  3390. if( !strText )
  3391. {
  3392. return FALSE;
  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. //SMITHA 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. }