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.

2182 lines
52 KiB

  1. #include "stdafx.h"
  2. #include "schclss.h"
  3. #include "maindoc.h"
  4. #include "resource.h"
  5. #include "bwsview.h"
  6. #include "ole2.h"
  7. #include "csyntax.h"
  8. #include "colldlg.h"
  9. #include "prmsdlg.h"
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15. /***********************************************************
  16. Function:
  17. Arguments:
  18. Return:
  19. Purpose:
  20. Author(s):
  21. Revision:
  22. Date:
  23. ***********************************************************/
  24. CMethod::CMethod( )
  25. {
  26. m_nArgs = 0;
  27. m_pArgTypes = NULL;
  28. }
  29. /***********************************************************
  30. Function:
  31. Arguments:
  32. Return:
  33. Purpose:
  34. Author(s):
  35. Revision:
  36. Date:
  37. ***********************************************************/
  38. CMethod::~CMethod( )
  39. {
  40. if( m_pArgTypes != NULL )
  41. delete[] m_pArgTypes;
  42. }
  43. /***********************************************************
  44. Function:
  45. Arguments:
  46. Return:
  47. Purpose:
  48. Author(s):
  49. Revision:
  50. Date:
  51. ***********************************************************/
  52. CString CMethod::GetName( )
  53. {
  54. return m_strName;
  55. }
  56. /***********************************************************
  57. Function:
  58. Arguments:
  59. Return:
  60. Purpose:
  61. Author(s):
  62. Revision:
  63. Date:
  64. ***********************************************************/
  65. CMethod::CMethod( ITypeInfo* pITypeInfo, FUNCDESC* pFuncDesc )
  66. {
  67. HRESULT hResult;
  68. BSTR bstrNames[ 256 ];
  69. UINT cNames;
  70. UINT nIdx;
  71. TCHAR szTemp[ 128 ];
  72. m_nArgs = 0;
  73. m_pArgTypes = NULL;
  74. hResult = pITypeInfo->GetNames( pFuncDesc->memid, bstrNames,
  75. 256, &cNames );
  76. if( SUCCEEDED( hResult ) )
  77. {
  78. m_strName = bstrNames[ 0 ];
  79. m_strAttributes[ ma_Name ] = bstrNames[ 0 ];
  80. m_strAttributes[ ma_DisplayName ] = bstrNames[ 0 ];
  81. m_nArgs = pFuncDesc->cParams;
  82. m_nArgsOpt = pFuncDesc->cParamsOpt;
  83. m_ReturnType = pFuncDesc->elemdescFunc.tdesc.vt;
  84. if( m_nArgs )
  85. {
  86. m_pArgTypes = new VARTYPE[ m_nArgs ];
  87. for( nIdx = 0; nIdx < (UINT)m_nArgs ; nIdx++ )
  88. {
  89. m_pArgTypes[ nIdx ] =
  90. pFuncDesc->lprgelemdescParam[ nIdx ].tdesc.vt;
  91. _tcscpy( szTemp, _T("") );
  92. StringCat( szTemp, bstrNames[ nIdx + 1] );
  93. m_strArgNames.Add( szTemp );
  94. }
  95. }
  96. for( nIdx = 0; nIdx < cNames ; nIdx++ )
  97. {
  98. SysFreeString( bstrNames[ nIdx ] );
  99. }
  100. }
  101. }
  102. /***********************************************************
  103. Function:
  104. Arguments:
  105. Return:
  106. Purpose:
  107. Author(s):
  108. Revision:
  109. Date:
  110. ***********************************************************/
  111. int CMethod::GetArgCount( )
  112. {
  113. return m_nArgs;
  114. }
  115. /***********************************************************
  116. Function:
  117. Arguments:
  118. Return:
  119. Purpose:
  120. Author(s):
  121. Revision:
  122. Date:
  123. ***********************************************************/
  124. int CMethod::GetArgOptionalCount( )
  125. {
  126. return m_nArgsOpt;
  127. }
  128. /***********************************************************
  129. Function:
  130. Arguments:
  131. Return:
  132. Purpose:
  133. Author(s):
  134. Revision:
  135. Date:
  136. ***********************************************************/
  137. VARTYPE CMethod::GetMethodReturnType( )
  138. {
  139. return m_ReturnType;
  140. }
  141. /***********************************************************
  142. Function:
  143. Arguments:
  144. Return:
  145. Purpose:
  146. Author(s):
  147. Revision:
  148. Date:
  149. ***********************************************************/
  150. BOOL CMethod::ConvertArgument( int nArg, CString strArg, VARIANT* )
  151. {
  152. return FALSE;
  153. }
  154. /***********************************************************
  155. Function:
  156. Arguments:
  157. Return:
  158. Purpose:
  159. Author(s):
  160. Revision:
  161. Date:
  162. ***********************************************************/
  163. CString CMethod::GetAttribute( METHODATTR methAttr )
  164. {
  165. switch( methAttr )
  166. {
  167. case ma_Name:
  168. case ma_DisplayName:
  169. return m_strAttributes[ methAttr ];
  170. default:
  171. ASSERT( FALSE );
  172. return CString( _T("???") );
  173. }
  174. }
  175. /***********************************************************
  176. Function:
  177. Arguments:
  178. Return:
  179. Purpose:
  180. Author(s):
  181. Revision:
  182. Date:
  183. ***********************************************************/
  184. HRESULT CMethod::PutAttribute( METHODATTR methAttr, CString& rValue )
  185. {
  186. return E_FAIL;
  187. }
  188. /***********************************************************
  189. Function:
  190. Arguments:
  191. Return:
  192. Purpose:
  193. Author(s):
  194. Revision:
  195. Date:
  196. ***********************************************************/
  197. HRESULT CMethod::CallMethod( IDispatch* pIDispatch, BOOL* pbDisplayMessage )
  198. {
  199. CStringArray aParamValues;
  200. int nIdx;
  201. DISPPARAMS dispparamsArgs = {NULL, NULL, 0, 0};
  202. DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
  203. DISPID dispid;
  204. OLECHAR FAR* szName;
  205. BSTR bstrName;
  206. VARIANT var;
  207. EXCEPINFO aExcepInfo;
  208. UINT uErr;
  209. HRESULT hResult, hResultX;
  210. IADsCollection* pICollection;
  211. IADsMembers* pIMembers;
  212. IDispatch* pIResult;
  213. if( m_nArgs )
  214. {
  215. CParamsDialog aParamsDialog;
  216. aParamsDialog.SetMethodName( m_strName );
  217. aParamsDialog.SetArgNames( &m_strArgNames );
  218. aParamsDialog.SetArgValues( &aParamValues );
  219. if( aParamsDialog.DoModal( ) != IDOK )
  220. return E_FAIL;
  221. dispparamsArgs.rgvarg = new VARIANT[ m_nArgs ];
  222. for( nIdx = 0; nIdx < m_nArgs ; nIdx++ )
  223. {
  224. VARIANT varString;
  225. VariantInit( &dispparamsArgs.rgvarg[ m_nArgs - nIdx - 1] );
  226. VariantInit( &varString );
  227. V_VT( &varString ) = VT_BSTR;
  228. V_BSTR( &varString ) = AllocBSTR( aParamValues[ nIdx ].GetBuffer( 128 ) );
  229. if( VT_VARIANT != m_pArgTypes[ nIdx ] )
  230. {
  231. hResult = VariantChangeType( &dispparamsArgs.rgvarg[ m_nArgs - nIdx - 1],
  232. &varString,
  233. VARIANT_NOVALUEPROP,
  234. m_pArgTypes[ nIdx ] );
  235. }
  236. else
  237. {
  238. BuildVariantArray( VT_BSTR, aParamValues[ nIdx ], dispparamsArgs.rgvarg[ m_nArgs - nIdx - 1] );
  239. }
  240. VariantClear( &varString );
  241. }
  242. }
  243. bstrName = AllocBSTR( m_strName.GetBuffer( 128 ) );
  244. szName = (OLECHAR FAR*) bstrName;
  245. hResult = pIDispatch->GetIDsOfNames( IID_NULL, &szName, 1,
  246. LOCALE_SYSTEM_DEFAULT, &dispid ) ;
  247. SysFreeString( bstrName );
  248. ASSERT( SUCCEEDED( hResult ) );
  249. while( TRUE )
  250. {
  251. HCURSOR aCursor, oldCursor;
  252. if( FAILED( hResult ) )
  253. break;
  254. memset( &aExcepInfo, 0, sizeof( aExcepInfo) );
  255. dispparamsArgs.cArgs = m_nArgs;
  256. dispparamsArgs.cNamedArgs = 0;
  257. aCursor = LoadCursor( NULL, IDC_WAIT );
  258. oldCursor = SetCursor( aCursor );
  259. hResult = pIDispatch->Invoke( dispid,
  260. IID_NULL,
  261. LOCALE_SYSTEM_DEFAULT,
  262. DISPATCH_METHOD,
  263. &dispparamsArgs,
  264. &var,
  265. &aExcepInfo,
  266. &uErr );
  267. SetCursor( oldCursor );
  268. if( DISP_E_EXCEPTION == hResult )
  269. {
  270. hResult = aExcepInfo.scode;
  271. }
  272. if( FAILED( hResult ) )
  273. {
  274. break;
  275. }
  276. if( VT_VOID == m_ReturnType )
  277. break;
  278. // now, we have a return value we must work on.
  279. switch( m_ReturnType )
  280. {
  281. case VT_DISPATCH:
  282. case VT_PTR:
  283. pIResult = V_DISPATCH( &var );
  284. pIResult->AddRef( );
  285. hResultX = pIResult->QueryInterface( IID_IADsCollection,
  286. (void**)&pICollection );
  287. if( SUCCEEDED( hResultX ) )
  288. {
  289. CCollectionDialog aCollectionDialog;
  290. aCollectionDialog.SetCollectionInterface( pICollection );
  291. aCollectionDialog.DoModal( );
  292. pICollection->Release( );
  293. *pbDisplayMessage = FALSE;
  294. }
  295. else
  296. {
  297. hResult = pIResult->QueryInterface( IID_IADsMembers,
  298. (void**)&pIMembers );
  299. if( SUCCEEDED( hResult ) )
  300. {
  301. CCollectionDialog aCollectionDialog;
  302. IADsGroup* pGroup;
  303. //SMITHA HRESULT hResult;
  304. hResult = pIDispatch->QueryInterface( IID_IADsGroup,
  305. (void**)&pGroup );
  306. if( SUCCEEDED( hResult ) )
  307. {
  308. aCollectionDialog.SetGroup( pGroup );
  309. }
  310. else
  311. {
  312. aCollectionDialog.SetMembersInterface( pIMembers );
  313. }
  314. aCollectionDialog.DoModal( );
  315. if( SUCCEEDED( hResult ) )
  316. pGroup->Release( );
  317. pIMembers->Release( );
  318. *pbDisplayMessage = FALSE;
  319. }
  320. }
  321. pIResult->Release( );
  322. break;
  323. case VT_BOOL:
  324. AfxGetMainWnd()->MessageBox( VARIANT_FALSE == V_BOOL( &var ) ?
  325. _T("Result: FALSE") :
  326. _T("Result: TRUE"),
  327. m_strName,
  328. MB_ICONINFORMATION );
  329. *pbDisplayMessage = FALSE;
  330. break;
  331. default:
  332. ASSERT( FALSE );
  333. }
  334. VariantClear( &var );
  335. break;
  336. }
  337. if( dispparamsArgs.rgvarg )
  338. {
  339. for( nIdx = 0; nIdx < m_nArgs ; nIdx++ )
  340. {
  341. if( V_VT( &dispparamsArgs.rgvarg[ nIdx ] ) != VT_EMPTY )
  342. {
  343. VariantClear( &dispparamsArgs.rgvarg[ nIdx ] );
  344. }
  345. }
  346. delete [] dispparamsArgs.rgvarg;
  347. }
  348. return hResult;
  349. }
  350. /***********************************************************
  351. Function:
  352. Arguments:
  353. Return:
  354. Purpose:
  355. Author(s):
  356. Revision:
  357. Date:
  358. ***********************************************************/
  359. CProperty::CProperty( )
  360. {
  361. m_bMandatory = FALSE;
  362. m_dwSyntaxID = 0L;
  363. }
  364. /***********************************************************
  365. Function:
  366. Arguments:
  367. Return:
  368. Purpose:
  369. Author(s):
  370. Revision:
  371. Date:
  372. ***********************************************************/
  373. CProperty::CProperty ( TCHAR* pszName, TCHAR* szSyntax, BOOL bMultiValued )
  374. {
  375. HRESULT hResult = S_OK;
  376. BSTR pszSyntax;
  377. for( int nIdx = 0; nIdx < pa_Limit ; nIdx++ )
  378. {
  379. m_strAttributes[ nIdx ] = _T("NA");
  380. }
  381. m_bMandatory = FALSE;
  382. m_bDefaultSyntax = TRUE;
  383. m_bMultiValued = bMultiValued;
  384. m_dwSyntaxID = 0L;
  385. m_strAttributes[ pa_Name ] = pszName;
  386. m_strAttributes[ pa_DisplayName ] = pszName;
  387. pszSyntax = AllocBSTR( szSyntax );
  388. m_pSyntax = GetSyntaxHandler( pszSyntax );
  389. /*if( SUCCEEDED( hResult ) && !_wcsicmp( pszSyntax, L"String" ) )
  390. {
  391. m_pSyntax = new COleDsString;
  392. }
  393. else if( SUCCEEDED( hResult ) && !_wcsicmp( pszSyntax, L"Counter" ) )
  394. {
  395. m_pSyntax = new COleDsLONG;
  396. }
  397. else if( SUCCEEDED( hResult ) && !_wcsicmp( pszSyntax, L"OleDsPath" ) )
  398. {
  399. m_pSyntax = new COleDsString;
  400. }
  401. else if( SUCCEEDED( hResult ) && !_wcsicmp( pszSyntax, L"EmailAddress" ) )
  402. {
  403. m_pSyntax = new COleDsString;
  404. }
  405. else if( SUCCEEDED( hResult ) && !_wcsicmp( pszSyntax, L"FaxNumber" ) )
  406. {
  407. m_pSyntax = new COleDsString;
  408. }
  409. else if( SUCCEEDED( hResult ) && !_wcsicmp( pszSyntax, L"Integer" ) )
  410. {
  411. m_pSyntax = new COleDsLONG;
  412. }
  413. else if( SUCCEEDED( hResult ) && !_wcsicmp( pszSyntax, L"Interval" ) )
  414. {
  415. m_pSyntax = new COleDsLONG;
  416. }
  417. else if( SUCCEEDED( hResult ) && !_wcsicmp( pszSyntax, L"List" ) )
  418. {
  419. m_pSyntax = new COleDsVARIANT;
  420. }
  421. else if( SUCCEEDED( hResult ) && !_wcsicmp( pszSyntax, L"NetAddress" ) )
  422. {
  423. m_pSyntax = new COleDsString;
  424. }
  425. else if( SUCCEEDED( hResult ) && !_wcsicmp( pszSyntax, L"OctetString" ) )
  426. {
  427. m_pSyntax = new COleDsVARIANT;
  428. }
  429. else if( SUCCEEDED( hResult ) && !_wcsicmp( pszSyntax, L"Path" ) )
  430. {
  431. m_pSyntax = new COleDsString;
  432. }
  433. else if( SUCCEEDED( hResult ) && !_wcsicmp( pszSyntax, L"PhoneNumber" ) )
  434. {
  435. m_pSyntax = new COleDsString;
  436. }
  437. else if( SUCCEEDED( hResult ) && !_wcsicmp( pszSyntax, L"PostalAddress" ) )
  438. {
  439. m_pSyntax = new COleDsString;
  440. }
  441. else if( SUCCEEDED( hResult ) && !_wcsicmp( pszSyntax, L"SmallInterval" ) )
  442. {
  443. m_pSyntax = new COleDsLONG;
  444. }
  445. else if( SUCCEEDED( hResult ) && !_wcsicmp( pszSyntax, L"Time" ) )
  446. {
  447. m_pSyntax = new COleDsDATE;
  448. }
  449. else if( SUCCEEDED( hResult ) && !_wcsicmp( pszSyntax, L"boolean" ) )
  450. {
  451. m_pSyntax = new COleDsBOOL;
  452. }
  453. else if( SUCCEEDED( hResult ) && !_wcsicmp( pszSyntax, L"TimeStamp" ) )
  454. {
  455. m_pSyntax = new COleDsNDSTimeStamp;
  456. }
  457. else if( SUCCEEDED( hResult ) && !_wcsicmp( pszSyntax, L"UTCTime" ) )
  458. {
  459. //m_pSyntax = new COleDsString;
  460. m_pSyntax = new COleDsDATE;
  461. }
  462. else if( SUCCEEDED( hResult ) && !_wcsicmp( pszSyntax, L"GeneralizedTime" ) )
  463. {
  464. //m_pSyntax = new COleDsString;
  465. m_pSyntax = new COleDsDATE;
  466. }
  467. else if( SUCCEEDED( hResult ) && !_wcsicmp( pszSyntax, L"Integer8" ) )
  468. {
  469. m_pSyntax = new COleDsLargeInteger;
  470. }
  471. else if( SUCCEEDED( hResult ) && !_wcsicmp( pszSyntax, L"Postal Address" ) )
  472. {
  473. m_pSyntax = new COleDsNDSPostalAddress;
  474. }
  475. else
  476. {
  477. ASSERT( FALSE );
  478. m_pSyntax = new COleDsString;
  479. }*/
  480. m_strAttributes[ pa_Type ] = szSyntax;
  481. m_strAttributes[ pa_MultiValued ] = bMultiValued ? _T("Yes") : _T("No");
  482. SysFreeString( pszSyntax );
  483. }
  484. /***********************************************************
  485. Function: CProperty::CreateSyntax
  486. Arguments:
  487. Return:
  488. Purpose:
  489. Author(s):
  490. Revision:
  491. Date:
  492. ***********************************************************/
  493. void CProperty::CreateSyntax( ADSTYPE eType )
  494. {
  495. COleDsSyntax* pNewSyntax = NULL;
  496. CString strText;
  497. if( !m_bDefaultSyntax )
  498. return;
  499. pNewSyntax = GetSyntaxHandler( eType, strText );
  500. if( NULL != pNewSyntax )
  501. {
  502. delete m_pSyntax;
  503. m_pSyntax = pNewSyntax;
  504. m_bDefaultSyntax = FALSE;
  505. }
  506. }
  507. /***********************************************************
  508. Function:
  509. Arguments:
  510. Return:
  511. Purpose:
  512. Author(s):
  513. Revision:
  514. Date:
  515. ***********************************************************/
  516. CProperty::CProperty( IADs* pIOleDs )
  517. {
  518. HRESULT hResult;
  519. BSTR bstrText;
  520. CString strTemp;
  521. TCHAR szText[ 128 ];
  522. long lTemp;
  523. VARIANT aVar, vGet;
  524. VARIANT_BOOL aBool;
  525. IADsProperty* pIProp = NULL;
  526. m_bMandatory = FALSE;
  527. m_bMultiValued = FALSE;
  528. m_bDefaultSyntax = TRUE;
  529. m_dwSyntaxID = 0L;
  530. //**************
  531. hResult = pIOleDs->get_Name( &bstrText );
  532. m_strAttributes[ pa_Name ] = bstrText;
  533. m_strAttributes[ pa_DisplayName ] = bstrText;
  534. SysFreeString( bstrText );
  535. //**************
  536. m_strAttributes[ pa_Mandatory ] = _T("No");
  537. //**************
  538. hResult = pIOleDs->QueryInterface( IID_IADsProperty, (void**) &pIProp );
  539. if( pIProp )
  540. {
  541. VariantInit( &vGet );
  542. hResult = Get( pIOleDs, L"Syntax", &vGet );
  543. bstrText = V_BSTR( &vGet );
  544. if( FAILED( hResult ) )
  545. {
  546. hResult = pIProp->get_Syntax( &bstrText );
  547. if( FAILED( hResult ) )
  548. {
  549. bstrText = AllocBSTR( _T("Unknown") );
  550. }
  551. }
  552. m_strAttributes[ pa_Type ] = bstrText;
  553. m_pSyntax = GetSyntaxHandler( bstrText );
  554. SysFreeString( bstrText );
  555. //**************
  556. /*
  557. hResult = Get( pIOleDs, _T("MaxRange"), &vGet );
  558. lTemp = V_I4( &vGet );
  559. if( FAILED( hResult ) )
  560. {
  561. hResult = pIProp->get_MaxRange( &lTemp );
  562. }
  563. if( SUCCEEDED( hResult ) )
  564. {
  565. _ltot( lTemp, szText, 10 );
  566. m_strAttributes[ pa_MaxRange ] = szText;
  567. }
  568. else
  569. {
  570. m_strAttributes[ pa_MaxRange ] = _T("NA");
  571. }
  572. //**************
  573. hResult = Get( pIOleDs, _T("MinRange"), &vGet );
  574. lTemp = V_I4( &vGet );
  575. if( FAILED( hResult ) )
  576. {
  577. hResult = pIProp->get_MinRange( &lTemp );
  578. }
  579. if( SUCCEEDED( hResult ) )
  580. {
  581. _ltot( lTemp, szText, 10 );
  582. m_strAttributes[ pa_MinRange ] = szText;
  583. }
  584. else
  585. {
  586. m_strAttributes[ pa_MinRange ] = _T("NA");
  587. }
  588. */
  589. //**************
  590. V_BOOL( &vGet ) = FALSE;
  591. hResult = Get( pIOleDs, _T("MultiValued"), &vGet );
  592. aBool = V_BOOL( &vGet );
  593. if( FAILED( hResult ) )
  594. {
  595. hResult = pIProp->get_MultiValued( &aBool );
  596. }
  597. m_bMultiValued = aBool;
  598. if( SUCCEEDED( hResult ) )
  599. {
  600. m_strAttributes[ pa_MultiValued ] = aBool ? _T("Yes") : _T("No");
  601. }
  602. else
  603. {
  604. m_strAttributes[ pa_MultiValued ] = _T("NA");
  605. }
  606. //**************
  607. hResult = Get( pIOleDs, _T("OID"), &vGet );
  608. bstrText = V_BSTR( &vGet );
  609. if( FAILED( hResult ) )
  610. {
  611. hResult = pIProp->get_OID( &bstrText );
  612. }
  613. if( bstrText && SUCCEEDED( hResult ) )
  614. {
  615. m_strAttributes[ pa_OID ] = bstrText;
  616. SysFreeString( bstrText );
  617. }
  618. else
  619. {
  620. m_strAttributes[ pa_OID ] = _T("NA");
  621. }
  622. //**************
  623. hResult = Get( pIOleDs, _T("DsNames"), &aVar );
  624. if( FAILED( hResult ) )
  625. {
  626. //hResult = pIProp->get_DsNames( &aVar );
  627. }
  628. if( SUCCEEDED( hResult ) )
  629. {
  630. m_strAttributes[ pa_DsNames ] = FromVariantToString( aVar );
  631. VariantClear( &aVar );
  632. }
  633. else
  634. {
  635. m_strAttributes[ pa_DsNames ] = _T("NA");
  636. }
  637. pIProp->Release( );
  638. }
  639. else
  640. {
  641. m_pSyntax = new COleDsString;
  642. }
  643. }
  644. /***********************************************************
  645. Function:
  646. Arguments:
  647. Return:
  648. Purpose:
  649. Author(s):
  650. Revision:
  651. Date:
  652. ***********************************************************/
  653. CProperty::~CProperty( )
  654. {
  655. delete m_pSyntax;
  656. }
  657. /***********************************************************
  658. Function:
  659. Arguments:
  660. Return:
  661. Purpose:
  662. Author(s):
  663. Revision:
  664. Date:
  665. ***********************************************************/
  666. CString CProperty::GetAttribute( PROPATTR propAttr )
  667. {
  668. switch( propAttr )
  669. {
  670. case pa_Name:
  671. case pa_DisplayName:
  672. case pa_Type:
  673. case pa_DsNames:
  674. case pa_OID:
  675. case pa_MaxRange:
  676. case pa_MinRange:
  677. case pa_Mandatory:
  678. case pa_MultiValued:
  679. return m_strAttributes[ propAttr ];
  680. default:
  681. ASSERT( FALSE );
  682. return CString( _T("???") );
  683. }
  684. }
  685. /***********************************************************
  686. Function:
  687. Arguments:
  688. Return:
  689. Purpose:
  690. Author(s):
  691. Revision:
  692. Date:
  693. ***********************************************************/
  694. HRESULT CProperty::PutAttribute( PROPATTR propAttr, CString& )
  695. {
  696. return E_FAIL;
  697. }
  698. /***********************************************************
  699. Function:
  700. Arguments:
  701. Return:
  702. Purpose:
  703. Author(s):
  704. Revision:
  705. Date:
  706. ***********************************************************/
  707. BOOL CProperty::SetMandatory( BOOL bMandatory )
  708. {
  709. m_bMandatory = bMandatory;
  710. m_strAttributes[ pa_Mandatory ] = bMandatory ? _T("Yes") : _T("No");
  711. return TRUE;
  712. }
  713. /***********************************************************
  714. Function:
  715. Arguments:
  716. Return:
  717. Purpose:
  718. Author(s):
  719. Revision:
  720. Date:
  721. ***********************************************************/
  722. BOOL CProperty::GetMandatory( )
  723. {
  724. return m_bMandatory;
  725. }
  726. /***********************************************************
  727. Function:
  728. Arguments:
  729. Return:
  730. Purpose:
  731. Author(s):
  732. Revision:
  733. Date:
  734. ***********************************************************/
  735. CString CProperty::VarToDisplayString( VARIANT& var, BOOL bUseEx )
  736. {
  737. return m_pSyntax->VarToDisplayString( var, m_bMultiValued, bUseEx );
  738. }
  739. /***********************************************************
  740. Function: CProperty::Value2Native
  741. Arguments:
  742. Return:
  743. Purpose:
  744. Author(s):
  745. Revision:
  746. Date:
  747. ***********************************************************/
  748. HRESULT CProperty::Value2Native( ADS_ATTR_INFO* pAttr, CString& rVal )
  749. {
  750. HRESULT hResult;
  751. ADSTYPE eADsType;
  752. hResult = m_pSyntax->Value2Native( pAttr, rVal );
  753. eADsType = (ADSTYPE)(m_pSyntax->m_dwSyntaxID);
  754. if( ADSTYPE_INVALID != eADsType )
  755. {
  756. pAttr->dwADsType = eADsType;
  757. if( SUCCEEDED( hResult ) )
  758. {
  759. for( DWORD idx = 0; idx < pAttr->dwNumValues ; idx++ )
  760. {
  761. pAttr->pADsValues[ idx ].dwType = eADsType;
  762. }
  763. }
  764. }
  765. return hResult;
  766. }
  767. /***********************************************************
  768. Function: CProperty::Value2Native
  769. Arguments:
  770. Return:
  771. Purpose:
  772. Author(s):
  773. Revision:
  774. Date:
  775. ***********************************************************/
  776. void CProperty::FreeAttrInfo( ADS_ATTR_INFO* pAttrInfo )
  777. {
  778. m_pSyntax->FreeAttrInfo( pAttrInfo );
  779. }
  780. /***********************************************************
  781. Function: CProperty::Native2Value
  782. Arguments:
  783. Return:
  784. Purpose:
  785. Author(s):
  786. Revision:
  787. Date:
  788. ***********************************************************/
  789. HRESULT CProperty::Native2Value( ADS_ATTR_INFO* pAttr, CString& rVal )
  790. {
  791. if( pAttr->dwNumValues )
  792. {
  793. SetSyntaxID( pAttr->dwADsType );
  794. if( pAttr->pADsValues[ 0 ].dwType != pAttr->dwADsType )
  795. {
  796. TRACE( _T("ERROR: Property type differs from value type\n") );
  797. }
  798. }
  799. //if( ADSTYPE_INVALID != pAttr->dwADsType )
  800. //{
  801. CreateSyntax( (ADSTYPE) pAttr->dwADsType );
  802. return m_pSyntax->Native2Value( pAttr, rVal );
  803. //}
  804. //else
  805. //{
  806. // rVal = _T("ERROR: ADSTYPE_INVALID") ;
  807. // return S_OK;
  808. //}
  809. }
  810. /***********************************************************
  811. Function:
  812. Arguments:
  813. Return:
  814. Purpose:
  815. Author(s):
  816. Revision:
  817. Date:
  818. ***********************************************************/
  819. BOOL CProperty::DisplayStringToDispParams( CString& rText, DISPPARAMS& dispParams, BOOL bUseEx )
  820. {
  821. return m_pSyntax->DisplayStringToDispParams( rText, dispParams, m_bMultiValued, bUseEx );
  822. }
  823. /***********************************************************
  824. Function:
  825. Arguments:
  826. Return:
  827. Purpose:
  828. Author(s):
  829. Revision:
  830. Date:
  831. ***********************************************************/
  832. BOOL CProperty::SetSyntaxID( DWORD dwSyntaxID )
  833. {
  834. if( m_dwSyntaxID )
  835. {
  836. ASSERT( dwSyntaxID == m_dwSyntaxID );
  837. }
  838. m_dwSyntaxID = dwSyntaxID;
  839. return TRUE;
  840. }
  841. /***********************************************************
  842. Function:
  843. Arguments:
  844. Return:
  845. Purpose:
  846. Author(s):
  847. Revision:
  848. Date:
  849. ***********************************************************/
  850. DWORD CProperty::GetSyntaxID( )
  851. {
  852. ASSERT( m_dwSyntaxID );
  853. return m_dwSyntaxID;
  854. }
  855. /***********************************************************
  856. Function:
  857. Arguments:
  858. Return:
  859. Purpose:
  860. Author(s):
  861. Revision:
  862. Date:
  863. ***********************************************************/
  864. /*CFuncSet::CFuncSet( )
  865. {
  866. m_pProperties = new CObArray;
  867. m_pMethods = new CObArray;
  868. for( int nIdx = fa_ERROR; nIdx < fa_Limit ; nIdx++ )
  869. {
  870. m_strAttributes[ nIdx ] = _T("???");
  871. }
  872. m_strAttributes[ fa_MethodsCount ] = _T("0");
  873. } */
  874. /***********************************************************
  875. Function:
  876. Arguments:
  877. Return:
  878. Purpose:
  879. Author(s):
  880. Revision:
  881. Date:
  882. ***********************************************************/
  883. /*CFuncSet::CFuncSet( CString& strName )
  884. {
  885. m_pProperties = new CObArray;
  886. m_pMethods = new CObArray;
  887. for( int nIdx = fa_ERROR; nIdx < fa_Limit ; nIdx++ )
  888. {
  889. m_strAttributes[ nIdx ] = _T("???");
  890. }
  891. m_strAttributes[ fa_MethodsCount ] = _T("0");
  892. m_strAttributes[ fa_Name ] = strName;
  893. m_strAttributes[ fa_DisplayName ] = strName;
  894. }*/
  895. /***********************************************************
  896. Function:
  897. Arguments:
  898. Return:
  899. Purpose:
  900. Author(s):
  901. Revision:
  902. Date:
  903. ***********************************************************/
  904. void CClass::AddProperty( CProperty* pProperty )
  905. {
  906. m_pProperties->Add( pProperty );
  907. }
  908. /***********************************************************
  909. Function:
  910. Arguments:
  911. Return:
  912. Purpose:
  913. Author(s):
  914. Revision:
  915. Date:
  916. ***********************************************************/
  917. /*CFuncSet::~CFuncSet( )
  918. {
  919. int nSize, nIdx;
  920. nSize = m_pProperties->GetSize( );
  921. for( nIdx = 0; nIdx < nSize ; nIdx++ )
  922. {
  923. delete m_pProperties->GetAt( nIdx );
  924. }
  925. m_pProperties->RemoveAll( );
  926. delete m_pProperties;
  927. // ****
  928. nSize = m_pMethods->GetSize( );
  929. for( nIdx = 0; nIdx < nSize ; nIdx++ )
  930. {
  931. delete m_pMethods->GetAt( nIdx );
  932. }
  933. m_pMethods->RemoveAll( );
  934. delete m_pMethods;
  935. }*/
  936. /***********************************************************
  937. Function:
  938. Arguments:
  939. Return:
  940. Purpose:
  941. Author(s):
  942. Revision:
  943. Date:
  944. ***********************************************************/
  945. int CClass::GetPropertyCount( )
  946. {
  947. return (int)m_pProperties->GetSize( );
  948. }
  949. /***********************************************************
  950. Function:
  951. Arguments:
  952. Return:
  953. Purpose:
  954. Author(s):
  955. Revision:
  956. Date:
  957. ***********************************************************/
  958. CString CClass::GetAttribute( int nProp, PROPATTR propAttr )
  959. {
  960. CProperty* pProperty;
  961. pProperty = GetProperty( nProp );
  962. return pProperty->GetAttribute( propAttr );
  963. }
  964. /***********************************************************
  965. Function:
  966. Arguments:
  967. Return:
  968. Purpose:
  969. Author(s):
  970. Revision:
  971. Date:
  972. ***********************************************************/
  973. HRESULT CClass::PutAttribute( int nProp, PROPATTR propAttr, CString& rValue )
  974. {
  975. CProperty* pProperty;
  976. pProperty = GetProperty( nProp );
  977. return pProperty->PutAttribute( propAttr, rValue );
  978. }
  979. /***********************************************************
  980. Function:
  981. Arguments:
  982. Return:
  983. Purpose:
  984. Author(s):
  985. Revision:
  986. Date:
  987. ***********************************************************/
  988. CString CClass::GetAttribute( int nMethod, METHODATTR methAttr )
  989. {
  990. CMethod* pMethod;
  991. pMethod = GetMethod( nMethod );
  992. return pMethod->GetAttribute( methAttr );
  993. }
  994. /***********************************************************
  995. Function:
  996. Arguments:
  997. Return:
  998. Purpose:
  999. Author(s):
  1000. Revision:
  1001. Date:
  1002. ***********************************************************/
  1003. HRESULT CClass::PutAttribute( int nMethod, METHODATTR methAttr, CString& rValue )
  1004. {
  1005. CMethod* pMethod;
  1006. pMethod = GetMethod( nMethod );
  1007. return pMethod->PutAttribute( methAttr, rValue );
  1008. }
  1009. /***********************************************************
  1010. Function:
  1011. Arguments:
  1012. Return:
  1013. Purpose:
  1014. Author(s):
  1015. Revision:
  1016. Date:
  1017. ***********************************************************/
  1018. CString CClass::VarToDisplayString( int nPropIndex, VARIANT& var, BOOL bUseEx )
  1019. {
  1020. return GetProperty( nPropIndex )->VarToDisplayString( var, bUseEx );
  1021. }
  1022. /***********************************************************
  1023. Function:
  1024. Arguments:
  1025. Return:
  1026. Purpose:
  1027. Author(s):
  1028. Revision:
  1029. Date:
  1030. ***********************************************************/
  1031. BOOL CClass::DisplayStringToDispParams( int nPropIndex, CString& strText, DISPPARAMS& var, BOOL bUseEx )
  1032. {
  1033. return GetProperty( nPropIndex )->DisplayStringToDispParams( strText, var, bUseEx );
  1034. }
  1035. /***********************************************************
  1036. Function: CClass::GetFunctionalSet
  1037. Arguments:
  1038. Return:
  1039. Purpose:
  1040. Author(s):
  1041. Revision:
  1042. Date:
  1043. ***********************************************************/
  1044. int CClass::LookupProperty( CString& strProperty )
  1045. {
  1046. int nMax, nIter;
  1047. CProperty* pProperty;
  1048. BOOL bFound = FALSE;
  1049. nMax = (int)m_pProperties->GetSize( );
  1050. for( nIter = 0; nIter < nMax && !bFound ; nIter++ )
  1051. {
  1052. pProperty = (CProperty*) ( m_pProperties->GetAt( nIter ) );
  1053. bFound = bFound || ( strProperty == pProperty->GetAttribute( pa_Name ) );
  1054. if( bFound )
  1055. break;
  1056. }
  1057. return ( bFound ? nIter : -1 );
  1058. }
  1059. /***********************************************************
  1060. Function:
  1061. Arguments:
  1062. Return:
  1063. Purpose:
  1064. Author(s):
  1065. Revision:
  1066. Date:
  1067. ***********************************************************/
  1068. CProperty* CClass::GetProperty( int nIndex )
  1069. {
  1070. int nMax;
  1071. CProperty* pProp;
  1072. nMax = (int)m_pProperties->GetSize( );
  1073. ASSERT( nIndex >= 0 && nIndex < nMax );
  1074. pProp = (CProperty*) ( m_pProperties->GetAt( nIndex ) );
  1075. return pProp;
  1076. }
  1077. /***********************************************************
  1078. Function:
  1079. Arguments:
  1080. Return:
  1081. Purpose:
  1082. Author(s):
  1083. Revision:
  1084. Date:
  1085. ***********************************************************/
  1086. CMethod* CClass::GetMethod( int nIndex )
  1087. {
  1088. int nMax;
  1089. CMethod* pProp;
  1090. nMax = (int)m_pMethods->GetSize( );
  1091. ASSERT( nIndex >= 0 && nIndex < nMax );
  1092. pProp = (CMethod*) ( m_pMethods->GetAt( nIndex ) );
  1093. return pProp;
  1094. }
  1095. /***********************************************************
  1096. Function:
  1097. Arguments:
  1098. Return:
  1099. Purpose:
  1100. Author(s):
  1101. Revision:
  1102. Date:
  1103. ***********************************************************/
  1104. REFIID CClass::GetMethodsInterface( )
  1105. {
  1106. return m_refMethods;
  1107. }
  1108. /***********************************************************
  1109. Function: CClass::HasMandatoryProperties
  1110. Arguments:
  1111. Return:
  1112. Purpose:
  1113. Author(s):
  1114. Revision:
  1115. Date:
  1116. ***********************************************************/
  1117. BOOL CClass::HasMandatoryProperties( )
  1118. {
  1119. BOOL bHas = FALSE;
  1120. int nIter, nSize;
  1121. nSize = (int)m_pProperties->GetSize( );
  1122. for( nIter = 0; nIter < nSize && !bHas ; nIter++ )
  1123. {
  1124. bHas |= GetProperty( nIter )->GetMandatory( );
  1125. }
  1126. return bHas;
  1127. }
  1128. /***********************************************************
  1129. Function: CFuncSet::LoadMethodsInformation
  1130. Arguments:
  1131. Return:
  1132. Purpose:
  1133. Author(s):
  1134. Revision:
  1135. Date:
  1136. ***********************************************************/
  1137. HRESULT CClass::LoadMethodsInformation( ITypeInfo* pITypeInfo )
  1138. {
  1139. HRESULT hResult= S_OK;
  1140. int nIdx;
  1141. CString strMethodName;
  1142. FUNCDESC* pFuncDesc;
  1143. CMethod* pMethod;
  1144. TCHAR szCount[ 16 ];
  1145. while( TRUE )
  1146. {
  1147. for( nIdx = 0; nIdx < 200 ; nIdx++ )
  1148. {
  1149. hResult = pITypeInfo->GetFuncDesc( nIdx, &pFuncDesc );
  1150. // now, we have function description, we must search for function type
  1151. if( FAILED( hResult ) )
  1152. continue;
  1153. if( INVOKE_FUNC != pFuncDesc->invkind || pFuncDesc->memid > 1000 )
  1154. {
  1155. pITypeInfo->ReleaseFuncDesc( pFuncDesc );
  1156. continue;
  1157. }
  1158. pMethod = new CMethod( pITypeInfo, pFuncDesc );
  1159. pITypeInfo->ReleaseFuncDesc( pFuncDesc );
  1160. strMethodName = pMethod->GetAttribute( ma_Name );
  1161. if( !strMethodName.CompareNoCase( _T("Get") ) )
  1162. {
  1163. delete pMethod;
  1164. continue;
  1165. }
  1166. if( !strMethodName.CompareNoCase( _T("GetEx") ) )
  1167. {
  1168. delete pMethod;
  1169. continue;
  1170. }
  1171. if( !strMethodName.CompareNoCase( _T("Put") ) )
  1172. {
  1173. delete pMethod;
  1174. continue;
  1175. }
  1176. if( !strMethodName.CompareNoCase( _T("PutEx") ) )
  1177. {
  1178. delete pMethod;
  1179. continue;
  1180. }
  1181. if( !strMethodName.CompareNoCase( _T("GetInfo") ) )
  1182. {
  1183. delete pMethod;
  1184. continue;
  1185. }
  1186. if( !strMethodName.CompareNoCase( _T("SetInfo") ) )
  1187. {
  1188. delete pMethod;
  1189. continue;
  1190. }
  1191. m_pMethods->Add( pMethod );
  1192. }
  1193. break;
  1194. }
  1195. _itot( (int)m_pMethods->GetSize( ), szCount, 10 );
  1196. m_strAttributes [ ca_MethodsCount ] = szCount;
  1197. return hResult;
  1198. }
  1199. /***********************************************************
  1200. Function:
  1201. Arguments:
  1202. Return:
  1203. Purpose:
  1204. Author(s):
  1205. Revision:
  1206. Date:
  1207. ***********************************************************/
  1208. BOOL GetFuncSetName( VARIANT& v, CString& strFuncSet, int nIdx )
  1209. {
  1210. SAFEARRAY* pSafeArray;
  1211. TCHAR szText[ 256 ];
  1212. VARIANT varString;
  1213. long lBound, uBound, lItem;
  1214. HRESULT hResult;
  1215. BOOL bFirst;
  1216. BSTR bstrVal;
  1217. CString strTemp;
  1218. strFuncSet.Empty( );
  1219. ASSERT( V_VT( &v ) & VT_ARRAY );
  1220. pSafeArray = V_ARRAY( &v );
  1221. hResult = SafeArrayGetLBound(pSafeArray, 1, &lBound);
  1222. hResult = SafeArrayGetUBound(pSafeArray, 1, &uBound);
  1223. VariantInit( &varString );
  1224. szText[ 0 ] = _T('\0');
  1225. bFirst = TRUE;
  1226. lItem = lBound + nIdx;
  1227. hResult = SafeArrayGetElement( pSafeArray, &lItem, &bstrVal );
  1228. if( FAILED( hResult ) )
  1229. {
  1230. return FALSE;
  1231. }
  1232. strTemp = bstrVal;
  1233. SysFreeString( bstrVal );
  1234. if( -1 != strTemp.Find( _T('.') ) )
  1235. {
  1236. strFuncSet = strTemp.SpanExcluding( _T(".") );
  1237. }
  1238. strFuncSet.TrimLeft( );
  1239. return TRUE;
  1240. }
  1241. /***********************************************************
  1242. Function:
  1243. Arguments:
  1244. Return:
  1245. Purpose:
  1246. Author(s):
  1247. Revision:
  1248. Date:
  1249. ***********************************************************/
  1250. CClass::CClass ( TCHAR* pszClass, REFIID rPrimaryInterface )
  1251. :m_refMethods( IID_IADs )
  1252. {
  1253. LPOLESTR pOleStr;
  1254. HRESULT hResult;
  1255. m_pProperties = new CObArray;
  1256. m_pMethods = new CObArray;
  1257. for( int nIdx = ca_ERROR; nIdx < ca_Limit; nIdx++ )
  1258. {
  1259. m_strAttributes[ nIdx ] = _T("NA");
  1260. }
  1261. m_strAttributes[ ca_Name ] = pszClass;
  1262. hResult = StringFromIID( rPrimaryInterface, &pOleStr );
  1263. if( SUCCEEDED( hResult ) )
  1264. {
  1265. m_strAttributes[ ca_PrimaryInterface ] = pOleStr;
  1266. //SysFreeString( pOleStr );
  1267. CoTaskMemFree( pOleStr );
  1268. }
  1269. }
  1270. /***********************************************************
  1271. Function:
  1272. Arguments:
  1273. Return:
  1274. Purpose:
  1275. Author(s):
  1276. Revision:
  1277. Date:
  1278. ***********************************************************/
  1279. CClass::CClass( CString& strSchema, CMainDoc* pMainDoc )
  1280. :m_refMethods( IID_IADs )
  1281. {
  1282. HRESULT hResult;
  1283. IADsClass* pIOleDsClass = NULL;
  1284. IADs* pIOleDsCls = NULL;
  1285. IADsContainer* pContainer = NULL;
  1286. IUnknown* pEnum = NULL;
  1287. IEnumVARIANT* pIEnumVar = NULL;
  1288. BSTR bstrText= NULL;
  1289. VARIANT aVar;
  1290. CString strAliased;
  1291. IADsProperty* pIProperty = NULL;
  1292. IADs* pIOleDs = NULL;
  1293. VARIANT_BOOL varBOOL;
  1294. CString strFuncSet;
  1295. CString strProperty;
  1296. CString strTemp;
  1297. long lTemp;
  1298. VARIANT vGet;
  1299. m_pMainDoc = pMainDoc;
  1300. m_pProperties = new CObArray;
  1301. m_pMethods = new CObArray;
  1302. for( int nIdx = ca_ERROR; nIdx < ca_Limit; nIdx++ )
  1303. {
  1304. m_strAttributes[ nIdx ] = _T("???");
  1305. }
  1306. {
  1307. TCHAR szPath [ 512 ];
  1308. hResult = m_pMainDoc->XOleDsGetObject( strSchema.GetBuffer( 128 ),
  1309. IID_IADsClass,
  1310. (void**) &pIOleDsClass );
  1311. if( FAILED( hResult ) )
  1312. {
  1313. _tcscpy( szPath, strSchema.GetBuffer( 256 ) );
  1314. _tcscat( szPath, _T(",Class") );
  1315. hResult = m_pMainDoc->XOleDsGetObject( szPath, IID_IADsClass, (void**) &pIOleDsClass );
  1316. }
  1317. }
  1318. if( FAILED( hResult ) )
  1319. {
  1320. TRACE( _T("Could not open schema object\n") );
  1321. return;
  1322. }
  1323. hResult = pIOleDsClass->QueryInterface( IID_IADs, (void**) &pIOleDsCls );
  1324. //*******************
  1325. hResult = pIOleDsClass->get_Name( &bstrText );
  1326. ASSERT( SUCCEEDED( hResult ) );
  1327. m_strAttributes[ ca_Name ] = bstrText;
  1328. SysFreeString( bstrText );
  1329. bstrText = NULL;
  1330. //*******************
  1331. VariantInit( &vGet );
  1332. V_BSTR( &vGet ) = NULL;
  1333. hResult = Get( pIOleDsCls, _T("CLSID"), &vGet );
  1334. bstrText = V_BSTR( &vGet );
  1335. if( FAILED( hResult ) )
  1336. {
  1337. hResult = pIOleDsClass->get_CLSID( &bstrText );
  1338. }
  1339. if( bstrText && SUCCEEDED( hResult ) )
  1340. {
  1341. m_strAttributes[ ca_CLSID ] = bstrText;
  1342. SysFreeString( bstrText );
  1343. }
  1344. else
  1345. {
  1346. m_strAttributes[ ca_CLSID ] = _T("NA");
  1347. }
  1348. //*******************
  1349. VariantInit( &vGet );
  1350. V_BSTR( &vGet ) = NULL;
  1351. hResult = Get( pIOleDsCls, _T("PrimaryInterface"), &vGet );
  1352. bstrText = V_BSTR( &vGet );
  1353. if( FAILED( hResult ) )
  1354. {
  1355. hResult = pIOleDsClass->get_PrimaryInterface( &bstrText );
  1356. }
  1357. //ASSERT( SUCCEEDED( hResult ) );
  1358. if( bstrText && SUCCEEDED( hResult ) )
  1359. {
  1360. m_strAttributes[ ca_PrimaryInterface ] = bstrText;
  1361. SysFreeString( bstrText );
  1362. }
  1363. else
  1364. {
  1365. m_strAttributes[ ca_PrimaryInterface ] = _T("NA");
  1366. }
  1367. //*******************
  1368. VariantInit( &vGet );
  1369. V_BSTR( &vGet ) = NULL;
  1370. hResult = Get( pIOleDsCls, _T("HelpFileName"), &vGet );
  1371. bstrText = V_BSTR( &vGet );
  1372. if( FAILED( hResult ) )
  1373. {
  1374. hResult = pIOleDsClass->get_HelpFileName( &bstrText );
  1375. }
  1376. //ASSERT( SUCCEEDED( hResult ) );
  1377. if( bstrText && SUCCEEDED( hResult ) )
  1378. {
  1379. m_strAttributes[ ca_HelpFileName ] = bstrText;
  1380. SysFreeString( bstrText );
  1381. }
  1382. else
  1383. {
  1384. m_strAttributes[ ca_HelpFileName ] = _T("NA");
  1385. }
  1386. //*******************
  1387. VariantInit( &vGet );
  1388. V_BSTR( &vGet ) = NULL;
  1389. hResult = Get( pIOleDsCls, _T("HelpFileContext"), &vGet );
  1390. lTemp = V_I4( &vGet );
  1391. if( FAILED( hResult ) )
  1392. {
  1393. hResult = pIOleDsClass->get_HelpFileContext( &lTemp );
  1394. }
  1395. //ASSERT( SUCCEEDED( hResult ) );
  1396. if( SUCCEEDED( hResult ) )
  1397. {
  1398. TCHAR szText[ 128 ];
  1399. _ltot( lTemp, szText, 10 );
  1400. m_strAttributes[ ca_HelpFileContext ] = szText;
  1401. }
  1402. else
  1403. {
  1404. m_strAttributes[ ca_HelpFileContext ] = _T("NA");
  1405. }
  1406. //*******************
  1407. VariantInit( &vGet );
  1408. V_BSTR( &vGet ) = NULL;
  1409. hResult = Get( pIOleDsCls, _T("OID"), &vGet );
  1410. bstrText = V_BSTR( &vGet );
  1411. if( FAILED( hResult ) )
  1412. {
  1413. hResult = pIOleDsClass->get_OID( &bstrText );
  1414. }
  1415. //ASSERT( bstrText && SUCCEEDED( hResult ) );
  1416. if( bstrText && SUCCEEDED( hResult ) )
  1417. {
  1418. m_strAttributes[ ca_OID ] = bstrText;
  1419. SysFreeString( bstrText );
  1420. }
  1421. else
  1422. {
  1423. m_strAttributes[ ca_OID ] = _T("NA");
  1424. }
  1425. //*******************
  1426. VariantInit( &vGet );
  1427. V_BSTR( &vGet ) = NULL;
  1428. hResult = Get( pIOleDsCls, _T("Container"), &vGet );
  1429. varBOOL = V_BOOL( &vGet );
  1430. if( FAILED( hResult ) )
  1431. {
  1432. hResult = pIOleDsClass->get_Container( (VARIANT_BOOL*)&varBOOL );
  1433. }
  1434. //ASSERT( SUCCEEDED( hResult ) );
  1435. if( SUCCEEDED( hResult ) )
  1436. {
  1437. m_bContainer = (BOOL)varBOOL;
  1438. m_strAttributes[ ca_Container ] = m_bContainer ? _T("YES") :_T("No");
  1439. }
  1440. else
  1441. {
  1442. m_strAttributes[ ca_Container ] = _T("NA");
  1443. }
  1444. //*******************
  1445. VariantInit( &vGet );
  1446. V_BSTR( &vGet ) = NULL;
  1447. hResult = Get( pIOleDsCls, _T("Abstract"), &vGet );
  1448. varBOOL = V_BOOL( &vGet );
  1449. if( FAILED( hResult ) )
  1450. {
  1451. hResult = pIOleDsClass->get_Abstract( (VARIANT_BOOL*)&varBOOL );
  1452. }
  1453. //ASSERT( SUCCEEDED( hResult ) );
  1454. if( SUCCEEDED( hResult ) )
  1455. {
  1456. m_strAttributes[ ca_Abstract ] = varBOOL ? _T("YES") :_T("No");
  1457. }
  1458. else
  1459. {
  1460. m_strAttributes[ ca_Abstract ] = _T("NA");
  1461. }
  1462. //*******************
  1463. hResult = Get( pIOleDsCls, _T("DerivedFrom"), &aVar );
  1464. if( FAILED( hResult ) )
  1465. {
  1466. hResult = pIOleDsClass->get_DerivedFrom( &aVar );
  1467. }
  1468. if( SUCCEEDED( hResult ) )
  1469. {
  1470. m_strAttributes[ ca_DerivedFrom ] = FromVariantToString( aVar );
  1471. VariantClear( &aVar );
  1472. }
  1473. else
  1474. {
  1475. m_strAttributes[ ca_DerivedFrom ] = _T("NA");
  1476. }
  1477. //*******************
  1478. hResult = Get( pIOleDsCls, _T("Containment"), &aVar );
  1479. if( FAILED( hResult ) )
  1480. {
  1481. hResult = pIOleDsClass->get_Containment( &aVar );
  1482. }
  1483. //ASSERT( SUCCEEDED( hResult ) );
  1484. if( SUCCEEDED( hResult ) )
  1485. {
  1486. //m_strAttributes[ ca_Containment ] = FromVariantToString( aVar );
  1487. m_strAttributes[ ca_Containment ] = FromVariantArrayToString( aVar );
  1488. VariantClear( &aVar );
  1489. }
  1490. else
  1491. {
  1492. m_strAttributes[ ca_Containment ] = _T("NA");
  1493. }
  1494. //strFuncSet.Empty( );
  1495. //pFuncSet = new CFuncSet( strFuncSet );
  1496. //m_pFuncSets->Add( pFuncSet );
  1497. BuildMandatoryPropertiesList( pIOleDsClass );
  1498. //********************
  1499. BuildOptionalPropertiesList( pIOleDsClass );
  1500. pIOleDsClass->Release( );
  1501. pIOleDsCls->Release( );
  1502. }
  1503. /***********************************************************
  1504. Function:
  1505. Arguments:
  1506. Return:
  1507. Purpose:
  1508. Author(s):
  1509. Revision:
  1510. Date:
  1511. ***********************************************************/
  1512. HRESULT CClass::BuildOptionalPropertiesList( IADsClass* pIClass )
  1513. {
  1514. HRESULT hResult;
  1515. VARIANT aOptionalProperty;
  1516. hResult = Get( pIClass, _T("OptionalProperties"), &aOptionalProperty );
  1517. if( FAILED( hResult ) )
  1518. {
  1519. hResult = pIClass->get_OptionalProperties( &aOptionalProperty );
  1520. }
  1521. if( SUCCEEDED( hResult ) )
  1522. {
  1523. AddProperties( pIClass, aOptionalProperty, FALSE );
  1524. VariantClear( &aOptionalProperty );
  1525. }
  1526. return hResult;
  1527. }
  1528. /***********************************************************
  1529. Function:
  1530. Arguments:
  1531. Return:
  1532. Purpose:
  1533. Author(s):
  1534. Revision:
  1535. Date:
  1536. ***********************************************************/
  1537. HRESULT CClass::AddProperties( IADsClass* pIClass, VARIANT& rVar, BOOL bMandatory )
  1538. {
  1539. HRESULT hResult;
  1540. IADs* pIOleDs = NULL;
  1541. BSTR bstrParent;
  1542. while( TRUE )
  1543. {
  1544. hResult = pIClass->QueryInterface( IID_IADs, (void**)&pIOleDs );
  1545. if( FAILED( hResult ) )
  1546. break;
  1547. hResult = pIClass->get_Parent( &bstrParent );
  1548. ASSERT( SUCCEEDED( hResult ) );
  1549. if( FAILED( hResult ) )
  1550. break;
  1551. if( VT_BSTR == V_VT( &rVar ) )
  1552. {
  1553. AddProperty( bstrParent, V_BSTR( &rVar ), bMandatory );
  1554. }
  1555. else
  1556. {
  1557. SAFEARRAY* pSafeArray;
  1558. VARIANT varString;
  1559. long lBound, uBound, lItem;
  1560. //SMITHA HRESULT hResult;
  1561. ASSERT( V_VT( &rVar ) & (VT_VARIANT | VT_ARRAY) );
  1562. pSafeArray = V_ARRAY( &rVar );
  1563. hResult = SafeArrayGetLBound(pSafeArray, 1, &lBound);
  1564. hResult = SafeArrayGetUBound(pSafeArray, 1, &uBound);
  1565. VariantInit( &varString );
  1566. for( lItem = lBound; lItem <= uBound ; lItem++ )
  1567. {
  1568. hResult = SafeArrayGetElement( pSafeArray, &lItem, &varString );
  1569. ASSERT( VT_BSTR == V_VT( &varString ) );
  1570. if( FAILED( hResult ) )
  1571. {
  1572. break;
  1573. }
  1574. AddProperty( bstrParent, V_BSTR( &varString ), bMandatory );
  1575. VariantClear( &varString );
  1576. }
  1577. }
  1578. SysFreeString( bstrParent );
  1579. break;
  1580. }
  1581. if( pIOleDs )
  1582. pIOleDs->Release( );
  1583. return hResult;
  1584. }
  1585. /***********************************************************
  1586. Function:
  1587. Arguments:
  1588. Return:
  1589. Purpose:
  1590. Author(s):
  1591. Revision:
  1592. Date:
  1593. ***********************************************************/
  1594. HRESULT CClass::AddProperty( BSTR bstrSchema, BSTR bstrName, BOOL bMandatory )
  1595. {
  1596. HRESULT hResult;
  1597. WCHAR szPath[ 1024 ];
  1598. IADs* pIOleDs;
  1599. if ((sizeof(szPath)/2) < (wcslen(bstrSchema) + wcslen(bstrName) + 2)) //we divide sizeof by 2 because WCHAR takes 2 bytes
  1600. return E_FAIL;
  1601. szPath[0] = L'\0';
  1602. wcscpy( szPath, bstrSchema );
  1603. wcscat( szPath, L"/" );
  1604. wcscat( szPath, bstrName );
  1605. hResult = m_pMainDoc->XOleDsGetObject( szPath, IID_IADs, (void**)&pIOleDs );
  1606. if( FAILED( hResult ) )
  1607. {
  1608. // OK, let's qualify it...
  1609. wcscat( szPath, L",Property" );
  1610. hResult = m_pMainDoc->XOleDsGetObject( szPath, IID_IADs, (void**)&pIOleDs );
  1611. }
  1612. if( SUCCEEDED( hResult ) )
  1613. {
  1614. CProperty* pProperty;
  1615. //hResult = pIOleDs->GetInfo( );
  1616. pProperty = new CProperty( pIOleDs );
  1617. pProperty->SetMandatory( bMandatory );
  1618. AddProperty( pProperty );
  1619. pIOleDs->Release( );
  1620. }
  1621. return hResult;
  1622. }
  1623. /***********************************************************
  1624. Function:
  1625. Arguments:
  1626. Return:
  1627. Purpose:
  1628. Author(s):
  1629. Revision:
  1630. Date:
  1631. ***********************************************************/
  1632. HRESULT CClass::BuildOptionalPropertiesList( IADsContainer* pIContainer )
  1633. {
  1634. return S_OK;
  1635. }
  1636. /***********************************************************
  1637. Function:
  1638. Arguments:
  1639. Return:
  1640. Purpose:
  1641. Author(s):
  1642. Revision:
  1643. Date:
  1644. ***********************************************************/
  1645. HRESULT CClass::BuildMandatoryPropertiesList( IADsClass* pIClass )
  1646. {
  1647. HRESULT hResult;
  1648. VARIANT aMandatoryProperties;
  1649. hResult = Get( pIClass, _T("MandatoryProperties"), &aMandatoryProperties );
  1650. if( FAILED( hResult ) )
  1651. {
  1652. hResult = pIClass->get_MandatoryProperties( &aMandatoryProperties );
  1653. }
  1654. if( SUCCEEDED( hResult ) )
  1655. {
  1656. AddProperties( pIClass, aMandatoryProperties, TRUE );
  1657. VariantClear( &aMandatoryProperties );
  1658. }
  1659. return hResult;
  1660. }
  1661. /***********************************************************
  1662. Function:
  1663. Arguments:
  1664. Return:
  1665. Purpose:
  1666. Author(s):
  1667. Revision:
  1668. Date:
  1669. ***********************************************************/
  1670. HRESULT CClass::LoadMethodsInformation( TCHAR* pszOperationsInterface )
  1671. {
  1672. HRESULT hResult= S_OK;
  1673. ITypeLib* pITypeLib = NULL;
  1674. ITypeInfo* pITypeInfo = NULL;
  1675. BSTR bstrPath;
  1676. BSTR bstrOperationsInterface;
  1677. CString strGUID;
  1678. MEMBERID aMemId;
  1679. unsigned short aFind = 1;
  1680. while( TRUE )
  1681. {
  1682. hResult = QueryPathOfRegTypeLib( LIBID_ADs, 1, 0,
  1683. LOCALE_SYSTEM_DEFAULT, &bstrPath );
  1684. if( FAILED( hResult ) )
  1685. break;
  1686. hResult = LoadTypeLib( bstrPath, &pITypeLib );
  1687. SysFreeString( bstrPath );
  1688. if( FAILED( hResult ) )
  1689. break;
  1690. bstrOperationsInterface = AllocBSTR( pszOperationsInterface );
  1691. hResult = pITypeLib->FindName( (OLECHAR FAR* )bstrOperationsInterface,
  1692. 0,
  1693. &pITypeInfo,
  1694. &aMemId,
  1695. &aFind );
  1696. SysFreeString( bstrOperationsInterface );
  1697. if( FAILED( hResult ) || !aFind )
  1698. break;
  1699. LoadMethodsInformation( pITypeInfo );
  1700. break;
  1701. }
  1702. if( NULL != pITypeInfo )
  1703. pITypeInfo->Release( );
  1704. if( NULL != pITypeLib )
  1705. pITypeLib->Release( );
  1706. return hResult;
  1707. }
  1708. /***********************************************************
  1709. Function:
  1710. Arguments:
  1711. Return:
  1712. Purpose:
  1713. Author(s):
  1714. Revision:
  1715. Date:
  1716. ***********************************************************/
  1717. HRESULT CClass::ReadMandatoryPropertiesInformation( VARIANT* pVar )
  1718. {
  1719. CString strTemp;
  1720. CString strWork;
  1721. CString strProperty;
  1722. CProperty* pProperty;
  1723. int nProp;
  1724. strTemp = FromVariantToString( *pVar );
  1725. strTemp.TrimLeft( );
  1726. while( strTemp.GetLength( ) )
  1727. {
  1728. CString strMandProp;
  1729. int nPos;
  1730. strMandProp = strTemp.SpanExcluding( _T("#") );
  1731. nPos = strMandProp.Find( _T('.') );
  1732. nPos++;
  1733. strProperty = strMandProp.GetBuffer( 128 ) + nPos;
  1734. // get rid of leading spaces
  1735. strProperty.TrimLeft( );
  1736. nProp = LookupProperty( strProperty );
  1737. ASSERT( -1 != nProp );
  1738. if( -1 == nProp )
  1739. break;
  1740. pProperty = GetProperty( nProp );
  1741. pProperty->SetMandatory( TRUE );
  1742. strWork = strTemp;
  1743. nPos = strWork.Find( _T('#') );
  1744. if( -1 == nPos )
  1745. {
  1746. strWork.Empty( );
  1747. }
  1748. nPos++;
  1749. strTemp = strWork.GetBuffer( 128 ) + nPos;
  1750. strTemp.TrimLeft( );
  1751. }
  1752. //SMITHA return TRUE;
  1753. return S_OK;
  1754. }
  1755. /***********************************************************
  1756. Function:
  1757. Arguments:
  1758. Return:
  1759. Purpose:
  1760. Author(s):
  1761. Revision:
  1762. Date:
  1763. ***********************************************************/
  1764. CClass::CClass( )
  1765. :m_refMethods( IID_IADs )
  1766. {
  1767. for( int nIdx = ca_ERROR; nIdx < ca_Limit; nIdx++ )
  1768. {
  1769. m_strAttributes[ nIdx ] = _T("???");
  1770. }
  1771. }
  1772. /***********************************************************
  1773. Function:
  1774. Arguments:
  1775. Return:
  1776. Purpose:
  1777. Author(s):
  1778. Revision:
  1779. Date:
  1780. ***********************************************************/
  1781. CClass::~CClass( )
  1782. {
  1783. int nSize, nIdx;
  1784. nSize = (int)m_pProperties->GetSize( );
  1785. for( nIdx = 0; nIdx < nSize ; nIdx++ )
  1786. {
  1787. delete m_pProperties->GetAt( nIdx );
  1788. }
  1789. m_pProperties->RemoveAll( );
  1790. delete m_pProperties;
  1791. // ****
  1792. nSize = (int)m_pMethods->GetSize( );
  1793. for( nIdx = 0; nIdx < nSize ; nIdx++ )
  1794. {
  1795. delete m_pMethods->GetAt( nIdx );
  1796. }
  1797. m_pMethods->RemoveAll( );
  1798. delete m_pMethods;
  1799. }
  1800. /***********************************************************
  1801. Function: CClass::GetAttribute
  1802. Arguments:
  1803. Return:
  1804. Purpose:
  1805. Author(s):
  1806. Revision:
  1807. Date:
  1808. ***********************************************************/
  1809. CString CClass::GetAttribute( CLASSATTR classAttr )
  1810. {
  1811. switch( classAttr )
  1812. {
  1813. case ca_Name:
  1814. case ca_DisplayName:
  1815. case ca_CLSID:
  1816. case ca_OID:
  1817. case ca_Abstract:
  1818. case ca_DerivedFrom:
  1819. case ca_Containment:
  1820. case ca_Container:
  1821. case ca_PrimaryInterface:
  1822. case ca_HelpFileName:
  1823. case ca_HelpFileContext:
  1824. case ca_MethodsCount:
  1825. return m_strAttributes[ classAttr ];
  1826. default:
  1827. ASSERT( FALSE );
  1828. return m_strAttributes[ ca_ERROR ];
  1829. }
  1830. }
  1831. /***********************************************************
  1832. Function: CClass::PutAttribute
  1833. Arguments:
  1834. Return:
  1835. Purpose:
  1836. Author(s):
  1837. Revision:
  1838. Date:
  1839. ***********************************************************/
  1840. HRESULT CClass::PutAttribute( CLASSATTR classAttr, CString& )
  1841. {
  1842. return E_FAIL;
  1843. }
  1844.