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.

3240 lines
81 KiB

  1. #include "stdafx.h"
  2. #include "resource.h"
  3. #include "qstatus.h"
  4. #include "createit.h"
  5. #include "copyitem.h"
  6. #include "moveitem.h"
  7. #include "delitem.h"
  8. #include "maindoc.h"
  9. #include "objects.h"
  10. #include "cacls.h"
  11. #include "schemavw.h"
  12. #include "csyntax.h"
  13. #include "qstatus.h"
  14. #ifdef _DEBUG
  15. #undef THIS_FILE
  16. static char BASED_CODE THIS_FILE[] = __FILE__;
  17. #endif
  18. #define NEXT_COUNT 1
  19. /***********************************************************
  20. Function:
  21. Arguments:
  22. Return:
  23. Purpose:
  24. Author(s):
  25. Revision:
  26. Date:
  27. ***********************************************************/
  28. COleDsObject::COleDsObject( ):m_refOperations(IID_IUnknown)
  29. {
  30. m_pIUnk = NULL;
  31. m_bUseSchemaInformation = TRUE;
  32. m_pClass = NULL;
  33. m_pParent = NULL;
  34. m_bSupportAdd = FALSE;
  35. m_bSupportDelete = TRUE;
  36. m_bSupportMove = FALSE;
  37. m_bSupportCopy = FALSE;
  38. m_dwCount = 0L;
  39. m_pfReadValues = NULL;
  40. m_pCachedValues = NULL;
  41. m_pdwUpdateType = NULL;
  42. m_pfDirty = NULL;
  43. m_nPropertiesCount = 0;
  44. m_ppPropertiesEntries = NULL;
  45. m_pChildren = NULL;
  46. m_pDeleteStatus = NULL;
  47. }
  48. /***********************************************************
  49. Function:
  50. Arguments:
  51. Return:
  52. Purpose:
  53. Author(s):
  54. Revision:
  55. Date:
  56. ***********************************************************/
  57. void COleDsObject::SetDocument( CMainDoc* pMainDoc )
  58. {
  59. m_pDoc = pMainDoc;
  60. }
  61. /***********************************************************
  62. Function:
  63. Arguments:
  64. Return:
  65. Purpose:
  66. Author(s):
  67. Revision:
  68. Date:
  69. ***********************************************************/
  70. COleDsObject::COleDsObject( IUnknown* pIUnk ):m_refOperations(IID_IUnknown)
  71. {
  72. IADs* pIOleDs = NULL;
  73. BSTR bstrClass = NULL;
  74. BSTR bstrOleDsPath = NULL;
  75. BSTR bstrName = NULL;
  76. BSTR bstrSchemaPath = NULL;
  77. HRESULT hResult;
  78. m_nPropertiesCount = 0;
  79. m_ppPropertiesEntries = NULL;
  80. m_pDoc = NULL;
  81. m_pChildren = new CDWordArray;
  82. m_bUseSchemaInformation = TRUE;
  83. m_pIUnk = pIUnk;
  84. m_pIUnk->AddRef( );
  85. m_pClass = NULL;
  86. m_pParent = NULL;
  87. m_bSupportAdd = FALSE;
  88. m_bSupportDelete = TRUE;
  89. m_bSupportMove = FALSE;
  90. m_bSupportCopy = FALSE;
  91. m_dwType = (DWORD)-1L;
  92. m_pfReadValues = NULL;
  93. m_pCachedValues = NULL;
  94. m_pfDirty = NULL;
  95. m_pdwUpdateType = NULL;
  96. hResult = pIUnk->QueryInterface( IID_IADs, (void**) &pIOleDs );
  97. {
  98. IADsContainer* pIContainer;
  99. if( SUCCEEDED( pIUnk->QueryInterface( IID_IADsContainer, (void**)&pIContainer ) ) )
  100. {
  101. pIContainer->Release( );
  102. m_bSupportMove = TRUE;
  103. m_bSupportCopy = TRUE;
  104. }
  105. }
  106. //ASSERT( SUCCEEDED( hResult ) );
  107. if( SUCCEEDED( hResult ))
  108. {
  109. pIOleDs->get_Class ( &bstrClass );
  110. CheckIfValidClassName ( bstrClass );
  111. pIOleDs->get_ADsPath ( &bstrOleDsPath );
  112. pIOleDs->get_Name ( &bstrName );
  113. m_strClassName = bstrClass;
  114. m_strItemName = bstrName;
  115. m_strOleDsPath = bstrOleDsPath;
  116. m_dwType = TypeFromString( bstrClass );
  117. ASSERT( m_dwType != -1L );
  118. SysFreeString( bstrClass );
  119. SysFreeString( bstrOleDsPath );
  120. SysFreeString( bstrName );
  121. hResult = pIOleDs->get_Schema( &bstrSchemaPath );
  122. if( SUCCEEDED( hResult ) )
  123. {
  124. m_strSchemaPath = bstrSchemaPath;
  125. SysFreeString( bstrSchemaPath );
  126. }
  127. pIOleDs->Release( );
  128. }
  129. m_pDeleteStatus = NULL;
  130. }
  131. /***********************************************************
  132. Function:
  133. Arguments:
  134. Return:
  135. Purpose:
  136. Author(s):
  137. Revision:
  138. Date:
  139. ***********************************************************/
  140. COleDsObject* COleDsObject::GetParent( )
  141. {
  142. return m_pParent;
  143. }
  144. /***********************************************************
  145. Function:
  146. Arguments:
  147. Return:
  148. Purpose:
  149. Author(s):
  150. Revision:
  151. Date:
  152. ***********************************************************/
  153. void COleDsObject::SetParent( COleDsObject* pParent )
  154. {
  155. m_pParent = pParent;
  156. }
  157. /***********************************************************
  158. Function:
  159. Arguments:
  160. Return:
  161. Purpose:
  162. Author(s):
  163. Revision:
  164. Date:
  165. ***********************************************************/
  166. BOOL COleDsObject::AddItemSuported( )
  167. {
  168. return m_bSupportAdd;
  169. }
  170. /***********************************************************
  171. Function:
  172. Arguments:
  173. Return:
  174. Purpose:
  175. Author(s):
  176. Revision:
  177. Date:
  178. ***********************************************************/
  179. BOOL COleDsObject::DeleteItemSuported( )
  180. {
  181. return m_bSupportDelete;
  182. }
  183. /***********************************************************
  184. Function:
  185. Arguments:
  186. Return:
  187. Purpose:
  188. Author(s):
  189. Revision:
  190. Date:
  191. ***********************************************************/
  192. BOOL COleDsObject::MoveItemSupported( )
  193. {
  194. return m_bSupportMove;
  195. }
  196. /***********************************************************
  197. Function:
  198. Arguments:
  199. Return:
  200. Purpose:
  201. Author(s):
  202. Revision:
  203. Date:
  204. ***********************************************************/
  205. BOOL COleDsObject::CopyItemSupported( )
  206. {
  207. return m_bSupportCopy;
  208. }
  209. /***********************************************************
  210. Function:
  211. Arguments:
  212. Return:
  213. Purpose:
  214. Author(s):
  215. Revision:
  216. Date:
  217. ***********************************************************/
  218. HRESULT COleDsObject::AddItem( )
  219. {
  220. return E_FAIL;
  221. }
  222. /***********************************************************
  223. Function:
  224. Arguments:
  225. Return:
  226. Purpose:
  227. Author(s):
  228. Revision:
  229. Date:
  230. ***********************************************************/
  231. HRESULT COleDsObject::DeleteItem( )
  232. {
  233. HRESULT hResult;
  234. if( NULL == m_pParent )
  235. {
  236. return E_FAIL;
  237. }
  238. m_pParent->CreateTheObject( );
  239. hResult = m_pParent->DeleteItem( this );
  240. m_pParent->ReleaseIfNotTransient( );
  241. return hResult;
  242. }
  243. /***********************************************************
  244. Function:
  245. Arguments:
  246. Return:
  247. Purpose:
  248. Author(s):
  249. Revision:
  250. Date:
  251. ***********************************************************/
  252. HRESULT COleDsObject::DeleteItem( COleDsObject* )
  253. {
  254. return E_FAIL;
  255. }
  256. /***********************************************************
  257. Function:
  258. Arguments:
  259. Return:
  260. Purpose:
  261. Author(s):
  262. Revision:
  263. Date:
  264. ***********************************************************/
  265. HRESULT COleDsObject::MoveItem( )
  266. {
  267. CMoveItem aMoveItem;
  268. BSTR bstrSource;
  269. BSTR bstrNewName;
  270. HRESULT hResult = E_FAIL;
  271. IADsContainer* pIContainer;
  272. IDispatch* pIUnk;
  273. ULONG ulRef;
  274. aMoveItem.SetContainerName( m_strOleDsPath );
  275. if( IDOK == aMoveItem.DoModal( ) )
  276. {
  277. bstrSource = AllocBSTR( aMoveItem.m_strSource.GetBuffer( 512 ) );
  278. bstrNewName = AllocBSTR( aMoveItem.m_strDestination.GetBuffer( 512 ) );
  279. hResult = m_pIUnk->QueryInterface( IID_IADsContainer, (void**)&pIContainer );
  280. ASSERT( SUCCEEDED( hResult ) );
  281. if( SUCCEEDED( hResult ) )
  282. {
  283. hResult = pIContainer->MoveHere( bstrSource, bstrNewName, &pIUnk );
  284. ulRef = pIUnk->Release( );
  285. ASSERT( !ulRef );
  286. pIContainer->Release( );
  287. }
  288. SysFreeString( bstrSource );
  289. SysFreeString( bstrNewName );
  290. }
  291. return hResult;
  292. }
  293. /***********************************************************
  294. Function:
  295. Arguments:
  296. Return:
  297. Purpose:
  298. Author(s):
  299. Revision:
  300. Date:
  301. ***********************************************************/
  302. HRESULT COleDsObject::CopyItem( )
  303. {
  304. CCopyItem aCopyItem;
  305. BSTR bstrSource;
  306. BSTR bstrNewName;
  307. HRESULT hResult = E_FAIL;;
  308. IADsContainer* pIContainer;
  309. IDispatch* pIUnk;
  310. ULONG ulRef;
  311. aCopyItem.SetContainerName( m_strOleDsPath );
  312. if( IDOK == aCopyItem.DoModal( ) )
  313. {
  314. bstrSource = AllocBSTR( aCopyItem.m_strSource.GetBuffer( 512 ) );
  315. bstrNewName = AllocBSTR( aCopyItem.m_strDestination.GetBuffer( 512 ) );
  316. hResult = m_pIUnk->QueryInterface( IID_IADsContainer, (void**)&pIContainer );
  317. ASSERT( SUCCEEDED( hResult ) );
  318. if( SUCCEEDED( hResult ) )
  319. {
  320. hResult = pIContainer->CopyHere( bstrSource, bstrNewName, &pIUnk );
  321. ulRef = pIUnk->Release( );
  322. ASSERT( !ulRef );
  323. pIContainer->Release( );
  324. }
  325. SysFreeString( bstrSource );
  326. SysFreeString( bstrNewName );
  327. }
  328. return hResult;
  329. }
  330. /***********************************************************
  331. Function:
  332. Arguments:
  333. Return:
  334. Purpose:
  335. Author(s):
  336. Revision:
  337. Date:
  338. ***********************************************************/
  339. HRESULT COleDsObject::ContainerAddItem( void )
  340. {
  341. CCreateItem aCreateItem;
  342. BSTR bstrClass;
  343. BSTR bstrRelativeName;
  344. IADsContainer* pIContainer;
  345. HRESULT hResult;
  346. IDispatch* pNewItem;
  347. IADs* pNewIOleDs;
  348. CString strQualifiedName;
  349. // build the name for diplay purposes
  350. MakeQualifiedName( strQualifiedName, m_strOleDsPath, m_dwType );
  351. aCreateItem.m_strParent = strQualifiedName;
  352. if( aCreateItem.DoModal( ) != IDOK )
  353. {
  354. return E_FAIL;
  355. }
  356. // get object name and class
  357. bstrClass = AllocBSTR( aCreateItem.m_strClass.GetBuffer(128) );
  358. bstrRelativeName = AllocBSTR( aCreateItem.m_strRelativeName.GetBuffer(128) );
  359. // good point, check if the parent object implements the IADsContainer interface
  360. hResult = m_pIUnk->QueryInterface( IID_IADsContainer, (void**)&pIContainer );
  361. ASSERT( SUCCEEDED( hResult ) );
  362. if( FAILED( hResult ) )
  363. {
  364. return hResult;
  365. }
  366. // make the call for create
  367. hResult = pIContainer->Create( bstrClass, bstrRelativeName, &pNewItem );
  368. if( SUCCEEDED( hResult ) )
  369. {
  370. // ask the user for values on mandatory attributes
  371. COleDsObject* pOleDsObject;
  372. CClass* pClass;
  373. pOleDsObject = new COleDsObject( pNewItem );
  374. pClass = m_pDoc->CreateClass( pOleDsObject );
  375. pOleDsObject->SetDocument( m_pDoc );
  376. if( pClass->HasMandatoryProperties( ) )
  377. {
  378. CSetMandatoryProperties aSetMandatoryProperties;
  379. aSetMandatoryProperties.SetOleDsObject( pOleDsObject );
  380. aSetMandatoryProperties.DoModal( );
  381. }
  382. HCURSOR oldSursor, newCursor;
  383. newCursor = LoadCursor( NULL, IDC_WAIT );
  384. oldSursor = SetCursor( newCursor );
  385. if( IsClassObject( ) || m_pDoc->UseVBStyle( ) )
  386. {
  387. hResult = pNewItem->QueryInterface( IID_IADs, (void**) &pNewIOleDs );
  388. ASSERT( SUCCEEDED( hResult ) );
  389. hResult = pNewIOleDs->SetInfo( );
  390. pNewIOleDs->Release( );
  391. }
  392. else
  393. {
  394. DWORD dwDirty = 0L;
  395. ADS_ATTR_INFO* pAttrDef;
  396. IDirectoryObject* pIADsObject;
  397. hResult = pOleDsObject->GetDirtyAttributes( &pAttrDef, &dwDirty );
  398. if( SUCCEEDED( hResult ) )
  399. {
  400. hResult = m_pIUnk->QueryInterface( IID_IDirectoryObject,
  401. (void**)&pIADsObject );
  402. ASSERT( SUCCEEDED( hResult ) );
  403. if( SUCCEEDED( hResult ) )
  404. {
  405. hResult = pIADsObject->CreateDSObject( bstrRelativeName,
  406. pAttrDef,
  407. dwDirty,
  408. NULL );
  409. pIADsObject->Release( );
  410. }
  411. }
  412. }
  413. SetCursor( oldSursor );
  414. pNewItem->Release( );
  415. delete pOleDsObject;
  416. }
  417. SysFreeString( bstrClass );
  418. SysFreeString( bstrRelativeName );
  419. pIContainer->Release( );
  420. return hResult;
  421. }
  422. /***********************************************************
  423. Function:
  424. Arguments:
  425. Return:
  426. Purpose:
  427. Author(s):
  428. Revision:
  429. Date:
  430. ***********************************************************/
  431. HRESULT COleDsObject::ContainerDeleteItem ( COleDsObject* pObject )
  432. {
  433. CDeleteItem aDeleteItem;
  434. BSTR bstrClass;
  435. BSTR bstrName;
  436. IADsContainer* pIContainer;
  437. IDirectoryObject* pDSObject;
  438. HRESULT hResult;
  439. CString strQualifiedName;
  440. BOOL bRecursive = FALSE;
  441. ASSERT( NULL != pObject );
  442. MakeQualifiedName( strQualifiedName, m_strOleDsPath, m_dwType );
  443. aDeleteItem.m_strParent = strQualifiedName;
  444. aDeleteItem.m_strName = pObject->GetItemName( );
  445. aDeleteItem.m_strClass = pObject->GetClass( );
  446. if( aDeleteItem.DoModal( ) != IDOK )
  447. {
  448. return E_FAIL;
  449. }
  450. bstrClass = AllocBSTR( aDeleteItem.m_strClass.GetBuffer(128) );
  451. bstrName = AllocBSTR( aDeleteItem.m_strName.GetBuffer(128) );
  452. bRecursive = aDeleteItem.m_bRecursive;
  453. if( IsClassObject( ) || m_pDoc->UseVBStyle( ) )
  454. {
  455. hResult = m_pIUnk->QueryInterface( IID_IADsContainer, (void**)&pIContainer );
  456. ASSERT( SUCCEEDED( hResult ) );
  457. if( FAILED( hResult ) )
  458. {
  459. return hResult;
  460. }
  461. if( !bRecursive )
  462. {
  463. hResult = pIContainer->Delete( bstrClass, bstrName );
  464. }
  465. else
  466. {
  467. IDispatch* pDispChild;
  468. IUnknown* pDispUnk;
  469. hResult = pIContainer->GetObject( bstrClass, bstrName, &pDispChild );
  470. if( SUCCEEDED( hResult ) )
  471. {
  472. hResult = pDispChild->QueryInterface( IID_IUnknown, (void**)&pDispUnk );
  473. pDispChild->Release( );
  474. if( SUCCEEDED( hResult ) )
  475. {
  476. hResult = PurgeObject( pIContainer, pDispUnk, NULL );
  477. pDispUnk->Release( );
  478. }
  479. }
  480. }
  481. pIContainer->Release( );
  482. }
  483. else
  484. {
  485. hResult = m_pIUnk->QueryInterface( IID_IDirectoryObject, (void**)&pDSObject );
  486. ASSERT( SUCCEEDED( hResult ) );
  487. if( FAILED( hResult ) )
  488. {
  489. return hResult;
  490. }
  491. hResult = pDSObject->DeleteDSObject( bstrName );
  492. pDSObject->Release( );
  493. }
  494. SysFreeString( bstrClass );
  495. SysFreeString( bstrName );
  496. return hResult;
  497. }
  498. /***********************************************************
  499. Function:
  500. Arguments:
  501. Return:
  502. Purpose:
  503. Author(s):
  504. Revision:
  505. Date:
  506. ***********************************************************/
  507. HRESULT COleDsObject::ContainerMoveItem( )
  508. {
  509. CMoveItem aMoveItem;
  510. BSTR bstrSource;
  511. BSTR bstrDestination;
  512. IADsContainer* pIContainer;
  513. HRESULT hResult;
  514. IDispatch* pNewItem;
  515. IADs* pNewIOleDs;
  516. CString strQualifiedName;
  517. MakeQualifiedName( strQualifiedName, m_strOleDsPath, m_dwType );
  518. aMoveItem.m_strParent = strQualifiedName;
  519. if( aMoveItem.DoModal( ) != IDOK )
  520. {
  521. return E_FAIL;
  522. }
  523. bstrSource = AllocBSTR( aMoveItem.m_strSource.GetBuffer(128) );
  524. bstrDestination = AllocBSTR( aMoveItem.m_strDestination.GetBuffer(128) );
  525. hResult = m_pIUnk->QueryInterface( IID_IADsContainer, (void**)&pIContainer );
  526. ASSERT( SUCCEEDED( hResult ) );
  527. if( FAILED( hResult ) )
  528. {
  529. return hResult;
  530. }
  531. hResult = pIContainer->MoveHere( bstrSource, bstrDestination, &pNewItem );
  532. if( SUCCEEDED( hResult ) )
  533. {
  534. hResult = pNewItem->QueryInterface( IID_IADs, (void**) &pNewIOleDs );
  535. ASSERT( SUCCEEDED( hResult ) );
  536. hResult = pNewIOleDs->SetInfo( );
  537. pNewIOleDs->Release( );
  538. pNewItem->Release( );
  539. }
  540. SysFreeString( bstrSource );
  541. SysFreeString( bstrDestination );
  542. pIContainer->Release( );
  543. return hResult;
  544. }
  545. /***********************************************************
  546. Function:
  547. Arguments:
  548. Return:
  549. Purpose:
  550. Author(s):
  551. Revision:
  552. Date:
  553. ***********************************************************/
  554. HRESULT COleDsObject::ContainerCopyItem( )
  555. {
  556. CCopyItem aCopyItem;
  557. BSTR bstrSource;
  558. BSTR bstrDestination;
  559. IADsContainer* pIContainer;
  560. HRESULT hResult;
  561. IDispatch* pNewItem;
  562. IADs* pNewIOleDs;
  563. CString strQualifiedName;
  564. MakeQualifiedName( strQualifiedName, m_strOleDsPath, m_dwType );
  565. aCopyItem.m_strParent = strQualifiedName;
  566. if( aCopyItem.DoModal( ) != IDOK )
  567. {
  568. return E_FAIL;
  569. }
  570. bstrSource = AllocBSTR( aCopyItem.m_strSource.GetBuffer(128) );
  571. bstrDestination = AllocBSTR( aCopyItem.m_strDestination.GetBuffer(128) );
  572. hResult = m_pIUnk->QueryInterface( IID_IADsContainer, (void**)&pIContainer );
  573. ASSERT( SUCCEEDED( hResult ) );
  574. if( FAILED( hResult ) )
  575. {
  576. return hResult;
  577. }
  578. hResult = pIContainer->CopyHere( bstrSource, bstrDestination, &pNewItem );
  579. if( SUCCEEDED( hResult ) )
  580. {
  581. hResult = pNewItem->QueryInterface( IID_IADs, (void**) &pNewIOleDs );
  582. ASSERT( SUCCEEDED( hResult ) );
  583. hResult = pNewIOleDs->SetInfo( );
  584. pNewIOleDs->Release( );
  585. pNewItem->Release( );
  586. }
  587. SysFreeString( bstrSource );
  588. SysFreeString( bstrDestination );
  589. pIContainer->Release( );
  590. return hResult;
  591. }
  592. /***********************************************************
  593. Function:
  594. Arguments:
  595. Return:
  596. Purpose:
  597. Author(s):
  598. Revision:
  599. Date:
  600. ***********************************************************/
  601. HRESULT COleDsObject::GetInterface( IUnknown** pIUnk )
  602. {
  603. if( NULL != m_pIUnk )
  604. {
  605. m_pIUnk->AddRef( );
  606. *pIUnk = m_pIUnk;
  607. return S_OK;
  608. }
  609. else
  610. {
  611. if( CreateTheObject( ) )
  612. {
  613. *pIUnk = m_pIUnk;
  614. m_pIUnk = NULL;
  615. return S_OK;
  616. }
  617. else
  618. {
  619. ASSERT( FALSE );
  620. TRACE( _T("Could not create the object\n") );
  621. return E_FAIL;
  622. }
  623. }
  624. }
  625. /***********************************************************
  626. Function:
  627. Arguments:
  628. Return:
  629. Purpose:
  630. Author(s):
  631. Revision:
  632. Date:
  633. ***********************************************************/
  634. BOOL COleDsObject::CreateTheObject( )
  635. {
  636. CString m_strQualifiedName;
  637. HRESULT hResult;
  638. if( NULL == m_pIUnk )
  639. {
  640. m_strQualifiedName = m_strOleDsPath;
  641. m_strQualifiedName += _T(',');
  642. m_strQualifiedName += m_strClassName;
  643. hResult = m_pDoc->XOleDsGetObject( m_strQualifiedName.GetBuffer( 128 ),
  644. IID_IUnknown, (void**)&m_pIUnk );
  645. ASSERT( SUCCEEDED( hResult ) );
  646. }
  647. return ( NULL != m_pIUnk );
  648. }
  649. /***********************************************************
  650. Function:
  651. Arguments:
  652. Return:
  653. Purpose:
  654. Author(s):
  655. Revision:
  656. Date:
  657. ***********************************************************/
  658. HRESULT COleDsObject::ReleaseIfNotTransient( void )
  659. {
  660. HRESULT hResult = S_OK;
  661. unsigned long lRefs;
  662. return S_OK;
  663. /*hResult = m_pIUnk->QueryInterface( IID_IADs, (void**) &pIOleDs );
  664. ASSERT( SUCCEEDED( hResult ) );
  665. hResult = pIOleDs->get_OleDsPath( &bstrOleDsPath );
  666. m_strOleDsPath = bstrOleDsPath;
  667. ASSERT( m_strOleDsPath.GetLength( ) );
  668. pIOleDs->Release( );
  669. m_pIUnk->Release( );*/
  670. if( NULL != m_pIUnk )
  671. {
  672. lRefs = m_pIUnk->Release( );
  673. if( 0 != lRefs )
  674. {
  675. /*TRACE( _T("ReleaseIfNotTransient detected that references to this object are still maintained\n") );
  676. TRACE( _T("Object:%s\t References:%ld"), m_strOleDsPath.GetBuffer( 128 ), lRefs );*/
  677. while( lRefs != 0 )
  678. {
  679. lRefs = m_pIUnk->Release( );
  680. }
  681. }
  682. }
  683. m_pIUnk = NULL;
  684. return hResult;
  685. }
  686. /***********************************************************
  687. Function:
  688. Arguments:
  689. Return:
  690. Purpose:
  691. Author(s):
  692. Revision:
  693. Date:
  694. ***********************************************************/
  695. COleDsObject::~COleDsObject( )
  696. {
  697. int nIter, nSize;
  698. DWORD dwToken;
  699. COleDsObject* pChild;
  700. ClearPropertiesList( );
  701. if( NULL != m_pIUnk )
  702. {
  703. ULONG ulRef;
  704. ulRef = m_pIUnk->Release( );
  705. if( ulRef )
  706. {
  707. TRACE( _T("ERROR! Release din't returned 0 reference count for %s\n"), m_strOleDsPath );
  708. }
  709. }
  710. if( NULL != m_pChildren )
  711. {
  712. nSize = (int)m_pChildren->GetSize( );
  713. for( nIter = 0; nIter < nSize ; nIter++ )
  714. {
  715. dwToken = m_pChildren->GetAt( nIter );
  716. ASSERT( dwToken );
  717. if( dwToken )
  718. {
  719. pChild = m_pDoc->GetObject( &dwToken );
  720. }
  721. delete pChild;
  722. }
  723. m_pChildren->RemoveAll( );
  724. delete m_pChildren;
  725. }
  726. if( NULL != m_pfReadValues )
  727. delete [] m_pfReadValues;
  728. if( NULL != m_pCachedValues )
  729. delete []m_pCachedValues;
  730. if( NULL != m_pfDirty )
  731. delete [] m_pfDirty;
  732. if( NULL != m_pdwUpdateType )
  733. delete [] m_pdwUpdateType;
  734. }
  735. /***********************************************************
  736. Function: COleDsObject::ClearPropertiesList
  737. Arguments:
  738. Return:
  739. Purpose:
  740. Author(s):
  741. Revision:
  742. Date:
  743. ***********************************************************/
  744. HRESULT COleDsObject::ClearPropertiesList( void )
  745. {
  746. int nIdx;
  747. if( m_ppPropertiesEntries )
  748. {
  749. for( nIdx = 0; nIdx < m_nPropertiesCount ; nIdx++ )
  750. {
  751. if( NULL != m_ppPropertiesEntries[ nIdx ] )
  752. {
  753. m_ppPropertiesEntries[ nIdx ]->Release( );
  754. }
  755. }
  756. FreeADsMem( m_ppPropertiesEntries );
  757. }
  758. m_nPropertiesCount = 0;
  759. m_ppPropertiesEntries = NULL;
  760. return S_OK;
  761. }
  762. /***********************************************************
  763. Function: COleDsObject::CreatePropertiesList
  764. Arguments:
  765. Return:
  766. Purpose:
  767. Author(s):
  768. Revision:
  769. Date:
  770. ***********************************************************/
  771. HRESULT COleDsObject::CreatePropertiesList( void )
  772. {
  773. HRESULT hResult;
  774. long lPropCount, lIdx;
  775. IADsPropertyList* pPropList = NULL;
  776. VARIANT var;
  777. if( m_nPropertiesCount )
  778. return S_OK;
  779. //ClearPropertiesList( );
  780. hResult = m_pIUnk->QueryInterface( IID_IADsPropertyList,
  781. (void**)&pPropList );
  782. if( FAILED( hResult ) )
  783. return hResult;
  784. hResult = pPropList->get_PropertyCount( &lPropCount );
  785. if( 0 == lPropCount )
  786. {
  787. pPropList->Release( );
  788. return hResult;
  789. }
  790. m_ppPropertiesEntries = (IUnknown**) AllocADsMem( lPropCount *
  791. sizeof(IUnknown*) );
  792. m_nPropertiesCount = (int)lPropCount;
  793. lIdx = 0;
  794. while( TRUE )
  795. {
  796. hResult = pPropList->Next( &var );
  797. if( FAILED( hResult ) )
  798. break;
  799. if( lIdx == m_nPropertiesCount )
  800. {
  801. ASSERT( FALSE );
  802. break;
  803. }
  804. hResult = V_DISPATCH( &var )->QueryInterface( IID_IUnknown,
  805. (void**)&m_ppPropertiesEntries[ lIdx++ ] );
  806. VariantClear( &var );
  807. }
  808. pPropList->Release( );
  809. return hResult;
  810. }
  811. /***********************************************************
  812. Function: COleDsObject::IsClassObject
  813. Arguments:
  814. Return:
  815. Purpose:
  816. Author(s):
  817. Revision:
  818. Date:
  819. ***********************************************************/
  820. BOOL COleDsObject::IsClassObject( )
  821. {
  822. return ( !m_strClassName.CompareNoCase( _T("Schema") ) ) ||
  823. ( !m_strClassName.CompareNoCase( _T("Class") ) ) ||
  824. ( !m_strClassName.CompareNoCase( _T("Property") ) ) ||
  825. ( !m_strClassName.CompareNoCase( _T("Syntax") ) );
  826. }
  827. /***********************************************************
  828. Function: COleDsObject::CreateClassInfo
  829. Arguments:
  830. Return:
  831. Purpose:
  832. Author(s):
  833. Revision:
  834. Date:
  835. ***********************************************************/
  836. void COleDsObject::CreateClassInfo( )
  837. {
  838. int nPropCount;
  839. if( !IsClassObject( ) && m_pDoc->UsePropertiesList( ) )
  840. {
  841. CreatePropertiesList( );
  842. return;
  843. }
  844. if( !m_pClass )
  845. {
  846. m_pClass = m_pDoc->CreateClass( this );
  847. if( !IsClassObject( ) && !m_pDoc->UseVBStyle( ) )
  848. {
  849. nPropCount = m_pClass->GetPropertyCount( );
  850. m_pCachedValues = new CString[ nPropCount ];
  851. m_pfReadValues = new BOOL[ nPropCount ];
  852. m_pfDirty = new BOOL[ nPropCount ];
  853. m_pdwUpdateType = new DWORD[ nPropCount ];
  854. for( int nIdx = 0; nIdx < nPropCount ; nIdx++ )
  855. {
  856. m_pfReadValues[ nIdx ] = FALSE;
  857. m_pfDirty[ nIdx ] = FALSE;
  858. }
  859. }
  860. }
  861. }
  862. /***********************************************************
  863. Function:
  864. Arguments:
  865. Return:
  866. Purpose:
  867. Author(s):
  868. Revision:
  869. Date:
  870. ***********************************************************/
  871. BOOL COleDsObject::HasChildren( )
  872. {
  873. return m_bHasChildren;
  874. }
  875. /***********************************************************
  876. Function:
  877. Arguments:
  878. Return:
  879. Purpose:
  880. Author(s):
  881. Revision:
  882. Date:
  883. ***********************************************************/
  884. CString COleDsObject::GetClass( )
  885. {
  886. return m_strClassName;
  887. }
  888. /***********************************************************
  889. Function:
  890. Arguments:
  891. Return:
  892. Purpose:
  893. Author(s):
  894. Revision:
  895. Date:
  896. ***********************************************************/
  897. CString COleDsObject::GetOleDsPath( )
  898. {
  899. return m_strOleDsPath;
  900. }
  901. /***********************************************************
  902. Function:
  903. Arguments:
  904. Return:
  905. Purpose:
  906. Author(s):
  907. Revision:
  908. Date:
  909. ***********************************************************/
  910. CString COleDsObject::GetItemName( )
  911. {
  912. return m_strItemName;
  913. }
  914. /***********************************************************
  915. Function:
  916. Arguments:
  917. Return:
  918. Purpose:
  919. Author(s):
  920. Revision:
  921. Date:
  922. ***********************************************************/
  923. CString* COleDsObject::PtrGetItemName( )
  924. {
  925. return &m_strItemName;
  926. }
  927. /***********************************************************
  928. Function:
  929. Arguments:
  930. Return:
  931. Purpose:
  932. Author(s):
  933. Revision:
  934. Date:
  935. ***********************************************************/
  936. CString COleDsObject::GetSchemaPath( )
  937. {
  938. return m_strSchemaPath;
  939. }
  940. /***********************************************************
  941. Function:
  942. Arguments:
  943. Return:
  944. Purpose:
  945. Author(s):
  946. Revision:
  947. Date:
  948. ***********************************************************/
  949. CString COleDsObject::GetDeleteName( )
  950. {
  951. return m_strItemName;
  952. }
  953. /***********************************************************
  954. Function:
  955. Arguments:
  956. Return:
  957. Purpose:
  958. Author(s):
  959. Revision:
  960. Date:
  961. ***********************************************************/
  962. DWORD COleDsObject::GetChildren( DWORD* pTokens,
  963. DWORD dwMaxCount,
  964. CDialog* pQueryStatus,
  965. BOOL* pFilters,
  966. DWORD dwFilters )
  967. {
  968. m_dwFilters = dwFilters;
  969. m_pFilters = pFilters;
  970. m_pTokens = pTokens;
  971. m_dwMaxCount = dwMaxCount;
  972. m_pQueryStatus = pQueryStatus;
  973. m_dwCount = 0L;
  974. m_bAbort = FALSE;
  975. ((CQueryStatus*)pQueryStatus)->SetAbortFlag( &m_bAbort );
  976. return 0L;
  977. }
  978. /***********************************************************
  979. Function:
  980. Arguments:
  981. Return:
  982. Purpose:
  983. Author(s):
  984. Revision:
  985. Date:
  986. ***********************************************************/
  987. DWORD COleDsObject::GetChildren( IADsContainer* pIContainer )
  988. {
  989. IUnknown* pIEnum;
  990. HRESULT hResult;
  991. SetFilter( pIContainer, m_pFilters, m_dwFilters );
  992. hResult = pIContainer->get__NewEnum( &pIEnum );
  993. if( SUCCEEDED( hResult ) )
  994. {
  995. AddNamesFromEnum( pIEnum );
  996. pIEnum->Release( );
  997. }
  998. return 0L;
  999. }
  1000. /***********************************************************
  1001. Function:
  1002. Arguments:
  1003. Return:
  1004. Purpose:
  1005. Author(s):
  1006. Revision:
  1007. Date:
  1008. ***********************************************************/
  1009. DWORD COleDsObject::GetChildren( IADsCollection* pIColl )
  1010. {
  1011. IUnknown* pIEnum;
  1012. HRESULT hResult;
  1013. //SetFilter( pIColl, m_pFilters, m_dwFilters );
  1014. hResult = pIColl->get__NewEnum( &pIEnum );
  1015. if( SUCCEEDED( hResult ) )
  1016. {
  1017. AddNamesFromEnum( pIEnum );
  1018. pIEnum->Release( );
  1019. }
  1020. return 0L;
  1021. }
  1022. /***********************************************************
  1023. Function:
  1024. Arguments:
  1025. Return:
  1026. Purpose:
  1027. Author(s):
  1028. Revision:
  1029. Date:
  1030. ***********************************************************/
  1031. DWORD COleDsObject::GetChildren( MEMBERS* pIGroupMem )
  1032. {
  1033. IUnknown* pIEnum;
  1034. HRESULT hResult;
  1035. SetFilter( pIGroupMem, m_pFilters, m_dwFilters );
  1036. hResult = pIGroupMem->get__NewEnum( &pIEnum );
  1037. if( SUCCEEDED( hResult ) )
  1038. {
  1039. AddNamesFromEnum( pIEnum );
  1040. pIEnum->Release( );
  1041. }
  1042. return 0L;
  1043. }
  1044. /***********************************************************
  1045. Function: AddNamesFromEnum
  1046. Arguments: pIEnum - IUnknown interface of the enumeration
  1047. (ususlly get through a get__NewEnum on
  1048. IADsContainer or IADsCollection or
  1049. IADsMembers)
  1050. Return: NA
  1051. Purpose: Walk the enumeration and retrieves the "child"
  1052. objects
  1053. Author(s): CezarU
  1054. Revision: 0
  1055. Date: 04/05/1996
  1056. ***********************************************************/
  1057. void COleDsObject::AddNamesFromEnum( IUnknown* pIEnum )
  1058. {
  1059. HRESULT hResult;
  1060. VARIANT aVariant[ NEXT_COUNT ];
  1061. IADs* pChildOleDs;
  1062. ULONG ulGet, ulIdx;
  1063. IEnumVARIANT* pIEnumVar = NULL;
  1064. BOOL bDisplay;
  1065. DWORD dwToken;
  1066. while( TRUE )
  1067. {
  1068. if( NULL == pIEnum )
  1069. {
  1070. break;
  1071. }
  1072. // query for EnumVARIANT interface
  1073. hResult = pIEnum->QueryInterface( IID_IEnumVARIANT, (void**)&pIEnumVar );
  1074. if( FAILED( hResult ) )
  1075. {
  1076. ASSERT(FALSE);
  1077. break;
  1078. }
  1079. // try dummy operations for Skip, Reset, Clone.
  1080. {
  1081. IEnumVARIANT* pICloneVar = NULL;
  1082. hResult = pIEnumVar->Skip( 1 );
  1083. hResult = pIEnumVar->Clone( &pICloneVar );
  1084. if( pICloneVar )
  1085. {
  1086. pICloneVar->Release( );
  1087. }
  1088. hResult = pIEnumVar->Reset( );
  1089. }
  1090. // ask for the next NEXT_COUNT objects
  1091. hResult = pIEnumVar->Next( NEXT_COUNT, aVariant, &ulGet );
  1092. while( ulGet && m_dwCount < m_dwMaxCount )
  1093. {
  1094. // get the returned object
  1095. bDisplay = FALSE;
  1096. for( ulIdx = 0;
  1097. m_dwCount < m_dwMaxCount && ulIdx < ulGet && !m_bAbort;
  1098. ulIdx++ )
  1099. {
  1100. // query for the IADs interface
  1101. hResult = V_DISPATCH( &aVariant[ ulIdx ] )->QueryInterface( IID_IADs,
  1102. (void**)&pChildOleDs );
  1103. // Indirectly call release on IDispatch interface
  1104. VariantClear( &aVariant[ ulIdx ] );
  1105. if( SUCCEEDED( hResult ) )
  1106. {
  1107. // create an "browse" object based on the OleDs object
  1108. dwToken = m_pDoc->CreateOleDsItem( this, pChildOleDs );
  1109. ASSERT( dwToken );
  1110. // need no more the IADs interface
  1111. pChildOleDs->Release( );
  1112. // ad the token of the new "browse" object in the array
  1113. m_pTokens[ m_dwCount++ ] = dwToken;
  1114. // make the token part of the children list
  1115. m_pChildren->Add( dwToken );
  1116. if( m_pQueryStatus )
  1117. {
  1118. // increment object type counter in "QueryStatus" dialog
  1119. COleDsObject* pObject;
  1120. pObject = m_pDoc->GetObject( &dwToken );
  1121. ((CQueryStatus*)m_pQueryStatus)->IncrementType( pObject->GetType( ), TRUE );
  1122. }
  1123. }
  1124. }
  1125. for( ; ulIdx < ulGet ; ulIdx++ )
  1126. {
  1127. // get rid of the unused objects; this code is hit when
  1128. // the user hits "Stop" in the "QueryStatus" dialog
  1129. VariantClear( &aVariant[ ulIdx ] );
  1130. }
  1131. if( !m_bAbort && m_dwCount < m_dwMaxCount )
  1132. {
  1133. // ask for the NEXT_COUNT objects
  1134. hResult = pIEnumVar->Next( NEXT_COUNT, aVariant, &ulGet );
  1135. if( m_bAbort )
  1136. {
  1137. for( ulIdx = 0 ; ulIdx < ulGet ; ulIdx++ )
  1138. {
  1139. // get rid of the unused objects; this code is hit when
  1140. // the user hits "Stop" in the "QueryStatus" dialog
  1141. VariantClear( &aVariant[ ulIdx ] );
  1142. }
  1143. }
  1144. }
  1145. if( m_bAbort )
  1146. break;
  1147. }
  1148. break;
  1149. }
  1150. if( pIEnumVar )
  1151. {
  1152. pIEnumVar->Release( );
  1153. }
  1154. }
  1155. /***********************************************************
  1156. Function:
  1157. Arguments:
  1158. Return:
  1159. Purpose:
  1160. Author(s):
  1161. Revision:
  1162. Date:
  1163. ***********************************************************/
  1164. HRESULT COleDsObject::PutProperty( int nProp, CString& strPropValue, LONG lnControlCode )
  1165. {
  1166. CreateClassInfo( );
  1167. if( IsClassObject( ) )
  1168. {
  1169. return PutPropertyVB( nProp, strPropValue, lnControlCode );
  1170. }
  1171. if( m_pDoc->UsePropertiesList( ) )
  1172. {
  1173. //return PutPropertyList( int nProp, CString& strPropValue, LONG lnControlCode );
  1174. return E_FAIL;
  1175. }
  1176. if( m_pDoc->UseVBStyle( ) )
  1177. {
  1178. return PutPropertyVB( nProp, strPropValue, lnControlCode );
  1179. }
  1180. else
  1181. {
  1182. return PutPropertyCPP( nProp, strPropValue, lnControlCode );
  1183. }
  1184. }
  1185. /***********************************************************
  1186. Function:
  1187. Arguments:
  1188. Return:
  1189. Purpose:
  1190. Author(s):
  1191. Revision:
  1192. Date:
  1193. ***********************************************************/
  1194. HRESULT COleDsObject::PutPropertyCPP( int nProp, CString& strPropValue,
  1195. LONG lnControlCode )
  1196. {
  1197. if( strPropValue.Compare( m_pCachedValues[ nProp ] ) )
  1198. {
  1199. m_pfDirty[ nProp ] = TRUE;
  1200. m_pCachedValues[ nProp ] = strPropValue;
  1201. m_pdwUpdateType[ nProp ] = lnControlCode;
  1202. }
  1203. return S_OK;
  1204. }
  1205. /***********************************************************
  1206. Function:
  1207. Arguments:
  1208. Return:
  1209. Purpose:
  1210. Author(s):
  1211. Revision:
  1212. Date:
  1213. ***********************************************************/
  1214. HRESULT COleDsObject::PutPropertyVB( int nProp,
  1215. CString& strPropValue,
  1216. LONG lnControlCode )
  1217. {
  1218. HRESULT hResult;
  1219. IDispatch* pIDispatchFS= NULL;
  1220. CString strProperty, strFuncSet;
  1221. DISPID dispid;
  1222. BOOL bRez;
  1223. DISPPARAMS dispParams;
  1224. VARIANT aVar[ 20 ];
  1225. DISPID adispidNamedArgs[ 20 ];
  1226. BSTR bstrPut;
  1227. EXCEPINFO aExcepInfo;
  1228. BOOL bUseGeneric;
  1229. dispParams.rgdispidNamedArgs = adispidNamedArgs;
  1230. strProperty = GetAttribute( nProp, pa_Name );
  1231. bUseGeneric = m_pDoc->GetUseGeneric( );
  1232. bUseGeneric = bUseGeneric && !IsClassObject( );
  1233. hResult = GetIDispatchForFuncSet( 0, &pIDispatchFS );
  1234. while( TRUE )
  1235. {
  1236. if( FAILED( hResult ) )
  1237. break;
  1238. if( !bUseGeneric )
  1239. {
  1240. bstrPut = AllocBSTR( strProperty.GetBuffer( 128 ) );
  1241. hResult = pIDispatchFS->GetIDsOfNames( IID_NULL, &bstrPut, 1,
  1242. LOCALE_SYSTEM_DEFAULT, &dispid ) ;
  1243. SysFreeString( bstrPut );
  1244. if( FAILED( hResult ) )
  1245. break;
  1246. dispParams.rgvarg = aVar;
  1247. bRez = DisplayStringToDispParams( nProp,
  1248. strPropValue,
  1249. dispParams,
  1250. FALSE );
  1251. if( bRez )
  1252. {
  1253. hResult = pIDispatchFS->Invoke( dispid, IID_NULL,
  1254. LOCALE_SYSTEM_DEFAULT,
  1255. DISPATCH_PROPERTYPUT,
  1256. &dispParams,
  1257. NULL, &aExcepInfo, NULL);
  1258. if( DISP_E_EXCEPTION == hResult )
  1259. {
  1260. hResult = aExcepInfo.scode;
  1261. }
  1262. VariantClear( &aVar[ 0 ] );
  1263. }
  1264. }
  1265. else
  1266. {
  1267. bstrPut = m_pDoc->GetUseGetEx( ) ?
  1268. AllocBSTR( _T("PutEx") ) : AllocBSTR( _T("Put") );
  1269. hResult = pIDispatchFS->GetIDsOfNames( IID_NULL, &bstrPut,
  1270. 1, LOCALE_SYSTEM_DEFAULT,
  1271. &dispid );
  1272. SysFreeString( bstrPut );
  1273. ASSERT( SUCCEEDED( hResult ) );
  1274. if( FAILED( hResult ) )
  1275. break;
  1276. // we got the dispid of Put method...
  1277. dispParams.rgvarg = &aVar[ 0 ];
  1278. bRez = DisplayStringToDispParams( nProp,
  1279. strPropValue,
  1280. dispParams,
  1281. bUseGeneric && m_pDoc->GetUseGetEx( ) );
  1282. VariantInit( &aVar[ 1 ] );
  1283. V_VT( &aVar[ 1 ] ) = VT_BSTR;
  1284. V_BSTR( &aVar[ 1 ] ) = AllocBSTR( strProperty.GetBuffer( 128 ) );
  1285. if( m_pDoc->GetUseGetEx( ) )
  1286. {
  1287. VariantInit( &aVar[ 2 ] );
  1288. V_VT( &aVar[ 2 ] ) = VT_I4;
  1289. V_I4( &aVar[ 2 ] ) = lnControlCode;
  1290. dispParams.cArgs = 3;
  1291. }
  1292. else
  1293. {
  1294. dispParams.cArgs = 2;
  1295. }
  1296. dispParams.rgvarg = aVar;
  1297. dispParams.cNamedArgs = 0;
  1298. if( bRez )
  1299. {
  1300. hResult = pIDispatchFS->Invoke( dispid, IID_NULL, LOCALE_SYSTEM_DEFAULT,
  1301. DISPATCH_METHOD, &dispParams,
  1302. NULL, &aExcepInfo, NULL);
  1303. if( DISP_E_EXCEPTION == hResult )
  1304. {
  1305. hResult = aExcepInfo.scode;
  1306. }
  1307. VariantClear( &aVar[ 0 ] );
  1308. }
  1309. VariantClear( &aVar[ 1 ] );
  1310. }
  1311. break;
  1312. }
  1313. if( NULL != pIDispatchFS )
  1314. {
  1315. pIDispatchFS->Release( );
  1316. }
  1317. if( FAILED( hResult ) )
  1318. {
  1319. ErrorOnPutProperty( strFuncSet,
  1320. strProperty,
  1321. strPropValue,
  1322. hResult,
  1323. bUseGeneric,
  1324. m_pDoc->GetUseGetEx( )
  1325. );
  1326. }
  1327. return hResult;
  1328. }
  1329. /***********************************************************
  1330. Function:
  1331. Arguments:
  1332. Return:
  1333. Purpose:
  1334. Author(s):
  1335. Revision:
  1336. Date:
  1337. ***********************************************************/
  1338. HRESULT COleDsObject::PutProperty( CString&, CString& )
  1339. {
  1340. return E_FAIL;
  1341. }
  1342. /***********************************************************
  1343. Function:
  1344. Arguments:
  1345. Return:
  1346. Purpose:
  1347. Author(s):
  1348. Revision:
  1349. Date:
  1350. ***********************************************************/
  1351. CString COleDsObject::GetAttribute( CLASSATTR classAttr )
  1352. {
  1353. CreateClassInfo( );
  1354. if( !m_pDoc->UsePropertiesList( ) )
  1355. {
  1356. return m_pClass->GetAttribute( classAttr );
  1357. }
  1358. else
  1359. {
  1360. return CString( _T("NA") );
  1361. }
  1362. }
  1363. /***********************************************************
  1364. Function:
  1365. Arguments:
  1366. Return:
  1367. Purpose:
  1368. Author(s):
  1369. Revision:
  1370. Date:
  1371. ***********************************************************/
  1372. HRESULT COleDsObject::PutAttribute( CLASSATTR classAttr, CString& rValue )
  1373. {
  1374. CreateClassInfo( );
  1375. return m_pClass->PutAttribute( classAttr, rValue );
  1376. }
  1377. /***********************************************************
  1378. Function:
  1379. Arguments:
  1380. Return:
  1381. Purpose:
  1382. Author(s):
  1383. Revision:
  1384. Date:
  1385. ***********************************************************/
  1386. CString COleDsObject::GetAttribute( int nProp, PROPATTR propAttr )
  1387. {
  1388. IADsPropertyEntry* pPropEntry;
  1389. HRESULT hResult;
  1390. CString strText;
  1391. CreateClassInfo( );
  1392. if( !m_pDoc->UsePropertiesList( ) )
  1393. {
  1394. return m_pClass->GetAttribute( nProp, propAttr );
  1395. }
  1396. ASSERT( nProp < m_nPropertiesCount );
  1397. if( !( nProp < m_nPropertiesCount ) )
  1398. return CString (_T("ERROR") );
  1399. if( NULL == m_ppPropertiesEntries[ nProp ] )
  1400. {
  1401. return CString (_T("ERROR") );
  1402. }
  1403. hResult = m_ppPropertiesEntries[ nProp ]->QueryInterface( IID_IADsPropertyEntry,
  1404. (void**)&pPropEntry );
  1405. ASSERT( SUCCEEDED( hResult ) );
  1406. if( FAILED( hResult ) )
  1407. return CString (_T("ERROR") );
  1408. switch( propAttr )
  1409. {
  1410. case pa_Name:
  1411. case pa_DisplayName:
  1412. {
  1413. TCHAR szName[ 256 ];
  1414. BSTR bstrName;
  1415. pPropEntry->get_Name( &bstrName );
  1416. Convert( szName, bstrName );
  1417. SysFreeString( bstrName );
  1418. strText = szName;
  1419. break;
  1420. }
  1421. case pa_Type:
  1422. {
  1423. long lADsType;
  1424. pPropEntry->get_ADsType( &lADsType );
  1425. strText = StringFromADsType( (ADSTYPE)lADsType );
  1426. break;
  1427. }
  1428. default:
  1429. break;
  1430. }
  1431. pPropEntry->Release( );
  1432. return strText;
  1433. }
  1434. /***********************************************************
  1435. Function:
  1436. Arguments:
  1437. Return:
  1438. Purpose:
  1439. Author(s):
  1440. Revision:
  1441. Date:
  1442. ***********************************************************/
  1443. HRESULT COleDsObject::PutAttribute( int nProp,
  1444. PROPATTR propAttr, CString& rValue )
  1445. {
  1446. CreateClassInfo( );
  1447. return m_pClass->PutAttribute( nProp, propAttr, rValue );
  1448. }
  1449. /***********************************************************
  1450. Function:
  1451. Arguments:
  1452. Return:
  1453. Purpose:
  1454. Author(s):
  1455. Revision:
  1456. Date:
  1457. ***********************************************************/
  1458. CString COleDsObject::GetAttribute( int nProp, METHODATTR methAttr )
  1459. {
  1460. CreateClassInfo( );
  1461. return m_pClass->GetAttribute( nProp, methAttr );
  1462. }
  1463. /***********************************************************
  1464. Function:
  1465. Arguments:
  1466. Return:
  1467. Purpose:
  1468. Author(s):
  1469. Revision:
  1470. Date:
  1471. ***********************************************************/
  1472. HRESULT COleDsObject::PutAttribute( int nProp,
  1473. METHODATTR methAttr, CString& rValue )
  1474. {
  1475. CreateClassInfo( );
  1476. return m_pClass->PutAttribute( nProp, methAttr, rValue );
  1477. }
  1478. /***********************************************************
  1479. Function:
  1480. Arguments:
  1481. Return:
  1482. Purpose:
  1483. Author(s):
  1484. Revision:
  1485. Date:
  1486. ***********************************************************/
  1487. HRESULT COleDsObject::CallMethod( int nMethod )
  1488. {
  1489. CMethod* pMethod;
  1490. IDispatch* pIDispatch;
  1491. IUnknown* pMethodInterf;
  1492. HRESULT hResult;
  1493. CString strCaption;
  1494. CString strMessage;
  1495. BOOL bDisplayMessage = TRUE;
  1496. CreateClassInfo( );
  1497. hResult = m_pIUnk->QueryInterface( m_pClass->GetMethodsInterface( ),
  1498. (void**)&pMethodInterf );
  1499. if( FAILED( hResult ) )
  1500. return hResult;
  1501. pMethod = m_pClass->GetMethod( nMethod );
  1502. hResult = pMethodInterf->QueryInterface( IID_IDispatch,
  1503. (void**)&pIDispatch );
  1504. pMethodInterf->Release( );
  1505. if( SUCCEEDED( hResult ) )
  1506. {
  1507. void* pData;
  1508. pData = LocalAlloc( LMEM_ZEROINIT, 100 );
  1509. hResult = pMethod->CallMethod( pIDispatch, &bDisplayMessage );
  1510. pIDispatch->Release( );
  1511. LocalFree( pData );
  1512. }
  1513. strCaption = m_pClass->GetAttribute( nMethod, ma_Name );
  1514. strMessage = OleDsGetErrorText( hResult );
  1515. if( ! (SUCCEEDED( hResult ) && !bDisplayMessage) )
  1516. {
  1517. AfxGetMainWnd()->MessageBox( strMessage, strCaption, MB_ICONINFORMATION );
  1518. }
  1519. return hResult;
  1520. }
  1521. /***********************************************************
  1522. Function:
  1523. Arguments:
  1524. Return:
  1525. Purpose:
  1526. Author(s):
  1527. Revision:
  1528. Date:
  1529. ***********************************************************/
  1530. HRESULT COleDsObject::GetIDispatchForFuncSet( int nFuncSet,
  1531. IDispatch** ppIDispatchFS )
  1532. {
  1533. IDispatch* pIDisp = NULL;
  1534. IUnknown* pIPrimary = NULL;
  1535. CString strFuncSet;
  1536. CString strPrimaryInterf;
  1537. HRESULT hResult;
  1538. DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
  1539. CLSID PrimaryIID;
  1540. UINT uTypeInfo;
  1541. ITypeInfo* pTypeInfo;
  1542. *ppIDispatchFS = NULL;
  1543. CreateClassInfo( );
  1544. strPrimaryInterf = m_pClass->GetAttribute( ca_PrimaryInterface );
  1545. if( strPrimaryInterf != _T("NA") )
  1546. {
  1547. BSTR bstrPrimaryInterface;
  1548. bstrPrimaryInterface = AllocBSTR( strPrimaryInterf.GetBuffer( 128 ) );
  1549. hResult = CLSIDFromString( bstrPrimaryInterface, &PrimaryIID );
  1550. SysFreeString( bstrPrimaryInterface );
  1551. //ASSERT( SUCCEEDED( hResult ) );
  1552. if( FAILED( hResult ) )
  1553. {
  1554. hResult = S_OK;
  1555. PrimaryIID = IID_IADs;
  1556. //return hResult;
  1557. }
  1558. }
  1559. else
  1560. {
  1561. PrimaryIID = IID_IADs;
  1562. }
  1563. hResult = m_pIUnk->QueryInterface( PrimaryIID, (void**) &pIPrimary );
  1564. ASSERT( SUCCEEDED( hResult ) );
  1565. if( FAILED( hResult ) )
  1566. {
  1567. hResult = m_pIUnk->QueryInterface( IID_IADs, (void**) &pIPrimary );
  1568. ASSERT( SUCCEEDED( hResult ) );
  1569. if( FAILED( hResult ) )
  1570. {
  1571. return hResult;
  1572. }
  1573. }
  1574. hResult = pIPrimary->QueryInterface( IID_IDispatch, (void**) &pIDisp );
  1575. ASSERT( SUCCEEDED( hResult ) );
  1576. if( FAILED( hResult ) )
  1577. {
  1578. return hResult;
  1579. }
  1580. {
  1581. HRESULT hResult_local;
  1582. hResult_local = pIDisp->GetTypeInfoCount( &uTypeInfo );
  1583. hResult_local = pIDisp->GetTypeInfo( 0, LOCALE_SYSTEM_DEFAULT, &pTypeInfo );
  1584. if( SUCCEEDED( hResult_local ) )
  1585. {
  1586. pTypeInfo->Release( );
  1587. }
  1588. }
  1589. *ppIDispatchFS = pIDisp;
  1590. pIDisp->AddRef( );
  1591. pIDisp->Release( );
  1592. pIPrimary->Release( );
  1593. return hResult;
  1594. }
  1595. /***********************************************************
  1596. Function:
  1597. Arguments:
  1598. Return:
  1599. Purpose:
  1600. Author(s):
  1601. Revision:
  1602. Date:
  1603. ***********************************************************/
  1604. HRESULT COleDsObject::GetPropertyFromList( int nProp, CString& strPropValue )
  1605. {
  1606. //IADsPropertyList* pPropList;
  1607. IADsPropertyEntry* pPropEntry;
  1608. HRESULT hResult;
  1609. long lADsType;
  1610. BSTR bstrName;
  1611. VARIANT vValues;
  1612. long lValueCount = 0;
  1613. ASSERT( 0 <= nProp && nProp < m_nPropertiesCount );
  1614. if( 0 > nProp || nProp >= m_nPropertiesCount )
  1615. return E_FAIL;
  1616. hResult = m_ppPropertiesEntries[ nProp ]->QueryInterface( IID_IADsPropertyEntry,
  1617. (void**)&pPropEntry );
  1618. if( FAILED( hResult ) )
  1619. return hResult;
  1620. hResult = pPropEntry->get_Name( &bstrName );
  1621. hResult = pPropEntry->get_ADsType( &lADsType );
  1622. //hResult = pPropEntry->get_ValueCount( &lValueCount );
  1623. hResult = pPropEntry->get_Values( &vValues );
  1624. if( SUCCEEDED( hResult ) )
  1625. {
  1626. COleDsSyntax* pSyntax;
  1627. pSyntax = GetSyntaxHandler( (ADSTYPE)lADsType, strPropValue );
  1628. if( NULL != pSyntax )
  1629. {
  1630. strPropValue = pSyntax->VarToDisplayStringEx( vValues,
  1631. (lValueCount != 1) );
  1632. delete pSyntax;
  1633. }
  1634. }
  1635. pPropEntry->Release( );
  1636. return hResult;
  1637. }
  1638. /***********************************************************
  1639. Function:
  1640. Arguments:
  1641. Return:
  1642. Purpose:
  1643. Author(s):
  1644. Revision:
  1645. Date:
  1646. ***********************************************************/
  1647. HRESULT COleDsObject::PutProperty( CString& strName,
  1648. CString& strVal,
  1649. BOOL bMultiValued,
  1650. ADSTYPE eType )
  1651. {
  1652. HRESULT hResult;
  1653. IADsPropertyList* pPropList = NULL;
  1654. COleDsSyntax* pSyntax = NULL;
  1655. DISPPARAMS dispParams;
  1656. VARIANT aVar[ 20 ];
  1657. CString strText;
  1658. dispParams.rgvarg = aVar;
  1659. while( TRUE )
  1660. {
  1661. hResult = m_pIUnk->QueryInterface( IID_IADsPropertyList,
  1662. (void**)&pPropList );
  1663. if( FAILED( hResult ) )
  1664. break;
  1665. pSyntax = GetSyntaxHandler( eType, strText );
  1666. if( NULL != pSyntax )
  1667. {
  1668. /*BOOL bOK;
  1669. VARIANT var;
  1670. bOK = pSyntax->CreatePropertyItem( strVal,
  1671. var,
  1672. bMultiValued,
  1673. eType );
  1674. bOK = FALSE;
  1675. if( bOK )
  1676. {
  1677. bstrName = AllocBSTR( strName.GetBuffer( 256 ) );
  1678. hResult = pPropList->PutPropertyItem( bstrName,
  1679. (long)ADS_ATTR_UPDATE,
  1680. var );
  1681. VariantClear( &aVar[ 0 ] );
  1682. SysFreeString( bstrName );
  1683. }*/
  1684. delete pSyntax;
  1685. }
  1686. pPropList->Release( );
  1687. break;
  1688. }
  1689. if( FAILED( hResult ) )
  1690. {
  1691. AfxMessageBox( OleDsGetErrorText( hResult ) );
  1692. }
  1693. return hResult;
  1694. }
  1695. /***********************************************************
  1696. Function:
  1697. Arguments:
  1698. Return:
  1699. Purpose:
  1700. Author(s):
  1701. Revision:
  1702. Date:
  1703. ***********************************************************/
  1704. HRESULT COleDsObject::GetProperty( CString& strName,
  1705. CString& strVal,
  1706. BOOL bMultiValued,
  1707. ADSTYPE eType )
  1708. {
  1709. HRESULT hResult;
  1710. IADsPropertyList* pPropList = NULL;
  1711. COleDsSyntax* pSyntax = NULL;
  1712. BSTR bstrName;
  1713. VARIANT aVar;
  1714. CString strText;
  1715. while( TRUE )
  1716. {
  1717. hResult = m_pIUnk->QueryInterface( IID_IADsPropertyList, (void**)&pPropList );
  1718. if( FAILED( hResult ) )
  1719. break;
  1720. bstrName = AllocBSTR( strName.GetBuffer( 256 ) );
  1721. hResult = pPropList->GetPropertyItem( bstrName, (long)eType, &aVar );
  1722. SysFreeString( bstrName );
  1723. if( FAILED( hResult ) )
  1724. {
  1725. pPropList->Release( );
  1726. break;
  1727. }
  1728. pSyntax = GetSyntaxHandler( eType, strText );
  1729. if( NULL != pSyntax )
  1730. {
  1731. strVal = pSyntax->VarToDisplayString( aVar, bMultiValued, TRUE );
  1732. delete pSyntax;
  1733. }
  1734. VariantClear( &aVar );
  1735. pPropList->Release( );
  1736. break;
  1737. }
  1738. if( FAILED( hResult ) )
  1739. {
  1740. AfxMessageBox( OleDsGetErrorText( hResult ) );
  1741. }
  1742. return hResult;
  1743. }
  1744. /***********************************************************
  1745. Function:
  1746. Arguments:
  1747. Return:
  1748. Purpose:
  1749. Author(s):
  1750. Revision:
  1751. Date:
  1752. ***********************************************************/
  1753. HRESULT COleDsObject::GetProperty( int nProp,
  1754. CString& strPropValue,
  1755. BOOL* pbSecurityDescriptor )
  1756. {
  1757. CreateClassInfo( );
  1758. if( IsClassObject( ) )
  1759. {
  1760. return GetPropertyVB( nProp,
  1761. strPropValue,
  1762. pbSecurityDescriptor );
  1763. }
  1764. if( m_pDoc->UsePropertiesList( ) )
  1765. return GetPropertyFromList( nProp,
  1766. strPropValue
  1767. /*pbSecurityDescriptor*/ );
  1768. if( m_pDoc->UseVBStyle( ) )
  1769. {
  1770. return GetPropertyVB( nProp,
  1771. strPropValue,
  1772. pbSecurityDescriptor );
  1773. }
  1774. else
  1775. {
  1776. return GetPropertyCPP( nProp,
  1777. strPropValue,
  1778. pbSecurityDescriptor );
  1779. }
  1780. }
  1781. //***********************************************************
  1782. // Function:
  1783. // Arguments:
  1784. // Return:
  1785. // Purpose:
  1786. // Author(s):
  1787. // Revision:
  1788. // Date:
  1789. //***********************************************************
  1790. HRESULT COleDsObject::GetPropertyVB( int nProp,
  1791. CString& strPropValue,
  1792. BOOL* pbSecurityDescriptor )
  1793. {
  1794. IDispatch* pIDispatchFS = NULL;
  1795. CString strProperty, strFuncSet;
  1796. HRESULT hResult;
  1797. DISPID dispid;
  1798. VARIANT varProp;
  1799. DISPPARAMS dispparamsArgs = {NULL, NULL, 0, 0};
  1800. EXCEPINFO aExcepInfo;
  1801. BSTR bstrGet;
  1802. BOOL bUseGeneric;
  1803. BOOL bSecDescriptor;
  1804. strProperty = GetAttribute( nProp, pa_Name );
  1805. strPropValue = _T("Error");
  1806. hResult = GetIDispatchForFuncSet( 0, &pIDispatchFS );
  1807. bUseGeneric = m_pDoc->GetUseGeneric( );
  1808. bUseGeneric = bUseGeneric && !IsClassObject( );
  1809. while( TRUE )
  1810. {
  1811. if( FAILED( hResult ) )
  1812. break;
  1813. VariantInit( &varProp );
  1814. //if( !strFuncSet.IsEmpty( ) )
  1815. if( !bUseGeneric )
  1816. {
  1817. bstrGet = AllocBSTR( strProperty.GetBuffer( 128 ) );
  1818. hResult = pIDispatchFS->GetIDsOfNames( IID_NULL, &bstrGet,
  1819. 1, LOCALE_SYSTEM_DEFAULT,
  1820. &dispid );
  1821. SysFreeString( bstrGet );
  1822. if( FAILED( hResult ) )
  1823. break;
  1824. hResult = pIDispatchFS->Invoke( dispid, IID_NULL, LOCALE_SYSTEM_DEFAULT,
  1825. DISPATCH_PROPERTYGET, &dispparamsArgs,
  1826. &varProp, &aExcepInfo, NULL);
  1827. }
  1828. else
  1829. {
  1830. // we have the case when the property id not accessed using
  1831. // functional sets.
  1832. bstrGet = AllocBSTR( m_pDoc->GetUseGetEx( ) ? _T("GetEx") : _T("Get") );
  1833. hResult = pIDispatchFS->GetIDsOfNames( IID_NULL, &bstrGet,
  1834. 1, LOCALE_SYSTEM_DEFAULT,
  1835. &dispid );
  1836. SysFreeString( bstrGet );
  1837. // we got the dispid of Put method...
  1838. dispparamsArgs.rgvarg = new VARIANT[ 1 ];
  1839. VariantInit( &dispparamsArgs.rgvarg[ 0 ] );
  1840. V_VT( &dispparamsArgs.rgvarg[ 0 ] ) = VT_BSTR;
  1841. V_BSTR( &dispparamsArgs.rgvarg[ 0 ] ) = AllocBSTR( strProperty.GetBuffer( 128 ) );
  1842. dispparamsArgs.cArgs = 1;
  1843. dispparamsArgs.cNamedArgs = 0;
  1844. hResult = pIDispatchFS->Invoke( dispid, IID_NULL, LOCALE_SYSTEM_DEFAULT,
  1845. DISPATCH_METHOD, &dispparamsArgs,
  1846. &varProp, &aExcepInfo, NULL);
  1847. VariantClear( &dispparamsArgs.rgvarg[ 0 ] );
  1848. delete (dispparamsArgs.rgvarg);
  1849. }
  1850. if( DISP_E_EXCEPTION == hResult )
  1851. {
  1852. hResult = aExcepInfo.scode;
  1853. }
  1854. else
  1855. {
  1856. bSecDescriptor = IsSecurityDescriptor( varProp, m_pDoc->GetUseGetEx( ) );
  1857. if( !bSecDescriptor )
  1858. {
  1859. strPropValue = VarToDisplayString( nProp,
  1860. varProp,
  1861. bUseGeneric && m_pDoc->GetUseGetEx( ) );
  1862. }
  1863. else
  1864. {
  1865. strPropValue = _T("This is a security descriptor");
  1866. }
  1867. VariantClear( &varProp );
  1868. if( NULL != pbSecurityDescriptor )
  1869. {
  1870. *pbSecurityDescriptor = bSecDescriptor;
  1871. }
  1872. }
  1873. break;
  1874. }
  1875. if( FAILED( hResult ) )
  1876. {
  1877. strPropValue = OleDsGetErrorText( hResult );
  1878. //AfxMessageBox( strPropValue );
  1879. }
  1880. if( NULL != pIDispatchFS )
  1881. {
  1882. pIDispatchFS->Release( );
  1883. }
  1884. return hResult;
  1885. }
  1886. //***********************************************************
  1887. // Function:
  1888. // Arguments:
  1889. // Return:
  1890. // Purpose:
  1891. // Author(s):
  1892. // Revision:
  1893. // Date:
  1894. //***********************************************************
  1895. BOOL COleDsObject::IsSecurityDescriptor( VARIANT& rValue, BOOL bUseGetEx )
  1896. {
  1897. BOOL bIsSD = FALSE;
  1898. HRESULT hResult;
  1899. IADsSecurityDescriptor* pDescriptor = NULL;
  1900. if( !bUseGetEx )
  1901. {
  1902. switch( V_VT( &rValue ) )
  1903. {
  1904. case VT_DISPATCH:
  1905. {
  1906. hResult = V_DISPATCH( &rValue )->QueryInterface(
  1907. IID_IADsSecurityDescriptor,
  1908. (void**)&pDescriptor );
  1909. if( SUCCEEDED( hResult ) )
  1910. {
  1911. pDescriptor->Release( );
  1912. bIsSD = TRUE;
  1913. }
  1914. break;
  1915. }
  1916. default:
  1917. break;
  1918. }
  1919. }
  1920. else
  1921. {
  1922. SAFEARRAY* pSafeArray;
  1923. VARIANT var;
  1924. long lBound, uBound;
  1925. if( (VT_ARRAY | VT_VARIANT) != V_VT( &rValue ) )
  1926. return FALSE;
  1927. pSafeArray = V_ARRAY( &rValue );
  1928. hResult = SafeArrayGetLBound(pSafeArray, 1, &lBound);
  1929. ASSERT( SUCCEEDED( hResult ) );
  1930. hResult = SafeArrayGetUBound(pSafeArray, 1, &uBound);
  1931. ASSERT( SUCCEEDED( hResult ) );
  1932. hResult = SafeArrayGetElement( pSafeArray, &lBound, &var );
  1933. if( SUCCEEDED( hResult ) )
  1934. {
  1935. bIsSD = IsSecurityDescriptor( var, FALSE );
  1936. VariantClear( &var );
  1937. }
  1938. }
  1939. return bIsSD;
  1940. }
  1941. /***********************************************************
  1942. Function:
  1943. Arguments:
  1944. Return:
  1945. Purpose:
  1946. Author(s):
  1947. Revision:
  1948. Date:
  1949. ***********************************************************/
  1950. HRESULT COleDsObject::GetPropertyCPP( int nProp, CString& strPropValue,
  1951. BOOL * pbIsDescriptor )
  1952. {
  1953. ADS_ATTR_INFO* pAttrDef;
  1954. BSTR szwAttrName[ 2 ];
  1955. HRESULT hResult;
  1956. DWORD dwAttributes;
  1957. IDirectoryObject* pIADsObject;
  1958. CString strPropName;
  1959. if( m_pfDirty[ nProp ] || m_pfReadValues[ nProp ] )
  1960. {
  1961. strPropValue = m_pCachedValues[ nProp ];
  1962. return S_OK;
  1963. }
  1964. hResult = m_pIUnk->QueryInterface( IID_IDirectoryObject, (void**)&pIADsObject );
  1965. while( TRUE )
  1966. {
  1967. if( FAILED( hResult ) )
  1968. break;
  1969. strPropName = m_pClass->GetAttribute( nProp, pa_Name );
  1970. szwAttrName[ 0 ] = AllocBSTR( strPropName.GetBuffer( 255 ) );
  1971. hResult = pIADsObject->GetObjectAttributes( (LPWSTR*)szwAttrName,
  1972. 1,
  1973. &pAttrDef,
  1974. &dwAttributes );
  1975. if( FAILED( hResult ) )
  1976. {
  1977. strPropValue = OleDsGetErrorText( hResult );
  1978. break;
  1979. }
  1980. if( SUCCEEDED( hResult ) && !dwAttributes )
  1981. {
  1982. TRACE( _T("ERROR: GetObjectAttributes succeeds, but dwAttributes is 0\n") );
  1983. strPropValue = _T("ERROR: GetObjectAttributes succeeds, but dwAttributes is 0");
  1984. //dwAttributes = 1;
  1985. }
  1986. if( !dwAttributes )
  1987. break;
  1988. hResult = CopyAttributeValue( pAttrDef, nProp );
  1989. FreeADsMem( (void*) pAttrDef );
  1990. break;
  1991. }
  1992. //ASSERT( m_pfReadValues[ nProp ] );
  1993. if( m_pfReadValues[ nProp ] )
  1994. {
  1995. strPropValue = m_pCachedValues[ nProp ];
  1996. }
  1997. if( pIADsObject )
  1998. {
  1999. pIADsObject->Release( );
  2000. }
  2001. return hResult;
  2002. }
  2003. /***********************************************************
  2004. Function: COleDsObject::CopyAttributeValue
  2005. Arguments:
  2006. Return:
  2007. Purpose:
  2008. Author(s):
  2009. Revision:
  2010. Date:
  2011. ***********************************************************/
  2012. HRESULT COleDsObject::CopyAttributeValue( ADS_ATTR_INFO* pAttrDef, int nAttribute )
  2013. {
  2014. HRESULT hResult;
  2015. CProperty* pProperty;
  2016. CreateClassInfo( );
  2017. ASSERT( pAttrDef->pszAttrName );
  2018. if( ! pAttrDef->pszAttrName )
  2019. {
  2020. return E_FAIL;
  2021. }
  2022. if( -1 == nAttribute )
  2023. {
  2024. // cool, we must gues the attribute index based on attribute name
  2025. TCHAR szAttrName[ 128 ];
  2026. int nProp;
  2027. CString strPropName;
  2028. Convert( szAttrName, pAttrDef->pszAttrName );
  2029. strPropName = szAttrName;
  2030. nProp = m_pClass->LookupProperty( strPropName );
  2031. ASSERT( -1 != nProp );
  2032. return (-1 == nProp) ?
  2033. E_FAIL : CopyAttributeValue( pAttrDef, nProp );
  2034. }
  2035. pProperty = m_pClass->GetProperty( nAttribute );
  2036. hResult = pProperty->Native2Value( pAttrDef, m_pCachedValues[ nAttribute ] );
  2037. m_pfReadValues[ nAttribute ] = TRUE;
  2038. //m_pCachedValues[ nAttribute ];
  2039. return hResult;
  2040. }
  2041. /***********************************************************
  2042. Function: COleDsObject::CreateAttributeValue
  2043. Arguments:
  2044. Return:
  2045. Purpose:
  2046. Author(s):
  2047. Revision:
  2048. Date:
  2049. ***********************************************************/
  2050. HRESULT COleDsObject::CreateAttributeValue ( ADS_ATTR_INFO* pAttrDef,
  2051. int nAttribute )
  2052. {
  2053. HRESULT hResult = S_OK;
  2054. CProperty* pProperty;
  2055. CString strPropName;
  2056. pProperty = m_pClass->GetProperty( nAttribute );
  2057. strPropName = m_pClass->GetAttribute( nAttribute, pa_Name );
  2058. pAttrDef->pszAttrName = (WCHAR*)AllocADsMem( sizeof(WCHAR) *
  2059. ( strPropName.GetLength() + 1 ) );
  2060. Convert( pAttrDef->pszAttrName, strPropName.GetBuffer( 256 ) );
  2061. pAttrDef->dwControlCode = m_pdwUpdateType[ nAttribute ];
  2062. if( ADS_PROPERTY_CLEAR != m_pdwUpdateType[ nAttribute ] )
  2063. {
  2064. hResult = pProperty->Value2Native( pAttrDef,
  2065. m_pCachedValues[ nAttribute ] );
  2066. }
  2067. return hResult;
  2068. }
  2069. /***********************************************************
  2070. Function:
  2071. Arguments:
  2072. Return:
  2073. Purpose:
  2074. Author(s):
  2075. Revision:
  2076. Date:
  2077. ***********************************************************/
  2078. HRESULT COleDsObject::GetProperty( CString&, CString& )
  2079. {
  2080. return E_FAIL;
  2081. }
  2082. /***********************************************************
  2083. Function:
  2084. Arguments:
  2085. Return:
  2086. Purpose:
  2087. Author(s):
  2088. Revision:
  2089. Date:
  2090. ***********************************************************/
  2091. //void COleDsObject::SetClass( CClass* pClass )
  2092. //{
  2093. // ASSERT( pClass != NULL );
  2094. //
  2095. // m_pClass = pClass;
  2096. //}
  2097. /***********************************************************
  2098. Function:
  2099. Arguments:
  2100. Return:
  2101. Purpose:
  2102. Author(s):
  2103. Revision:
  2104. Date:
  2105. ***********************************************************/
  2106. void COleDsObject::UseSchemaInformation ( BOOL bUse )
  2107. {
  2108. m_bUseSchemaInformation = bUse;
  2109. }
  2110. /***********************************************************
  2111. Function:
  2112. Arguments:
  2113. Return:
  2114. Purpose:
  2115. Author(s):
  2116. Revision:
  2117. Date:
  2118. ***********************************************************/
  2119. int COleDsObject::GetPropertyCount( )
  2120. {
  2121. CreateClassInfo( );
  2122. if( !m_pDoc->UsePropertiesList( ) )
  2123. {
  2124. return m_pClass->GetPropertyCount( );
  2125. }
  2126. else
  2127. {
  2128. return m_nPropertiesCount;
  2129. }
  2130. }
  2131. /***********************************************************
  2132. Function:
  2133. Arguments:
  2134. Return:
  2135. Purpose:
  2136. Author(s):
  2137. Revision:
  2138. Date:
  2139. ***********************************************************/
  2140. CString COleDsObject::VarToDisplayString( int nProp, VARIANT& var, BOOL bUseEx )
  2141. {
  2142. CreateClassInfo( );
  2143. return m_pClass->VarToDisplayString( nProp, var, bUseEx );
  2144. }
  2145. /***********************************************************
  2146. Function:
  2147. Arguments:
  2148. Return:
  2149. Purpose:
  2150. Author(s):
  2151. Revision:
  2152. Date:
  2153. ***********************************************************/
  2154. BOOL COleDsObject::DisplayStringToDispParams( int nProp,
  2155. CString& rString, DISPPARAMS& dp,
  2156. BOOL bUseEx )
  2157. {
  2158. CreateClassInfo( );
  2159. return m_pClass->DisplayStringToDispParams( nProp, rString, dp, bUseEx );
  2160. }
  2161. /***********************************************************
  2162. Function:
  2163. Arguments:
  2164. Return:
  2165. Purpose:
  2166. Author(s):
  2167. Revision:
  2168. Date:
  2169. ***********************************************************/
  2170. BOOL COleDsObject::SupportContainer( void )
  2171. {
  2172. CreateClassInfo( );
  2173. return m_pClass->SupportContainer( );
  2174. }
  2175. /***********************************************************
  2176. Function:
  2177. Arguments:
  2178. Return:
  2179. Purpose:
  2180. Author(s):
  2181. Revision:
  2182. Date:
  2183. ***********************************************************/
  2184. DWORD COleDsObject::GetType( )
  2185. {
  2186. return m_dwType;
  2187. }
  2188. /***********************************************************
  2189. Function:
  2190. Arguments:
  2191. Return:
  2192. Purpose:
  2193. Author(s):
  2194. Revision:
  2195. Date:
  2196. ***********************************************************/
  2197. HRESULT COleDsObject::GetInfo( )
  2198. {
  2199. HRESULT hResult;
  2200. if( m_pDoc->UseVBStyle( ) )
  2201. {
  2202. hResult = GetInfoVB( );
  2203. }
  2204. else
  2205. {
  2206. hResult = GetInfoCPP( );
  2207. }
  2208. ClearPropertiesList( );
  2209. if( FAILED( hResult ) )
  2210. {
  2211. CString strError;
  2212. strError = OleDsGetErrorText( hResult );
  2213. AfxGetMainWnd()->MessageBox( strError, _T("GetInfo ERROR") );
  2214. }
  2215. return hResult;
  2216. }
  2217. /***********************************************************
  2218. Function:
  2219. Arguments:
  2220. Return:
  2221. Purpose:
  2222. Author(s):
  2223. Revision:
  2224. Date:
  2225. ***********************************************************/
  2226. HRESULT COleDsObject::GetInfoVB( )
  2227. {
  2228. IADs* pIOleDs;
  2229. HRESULT hResult;
  2230. hResult = E_FAIL;
  2231. ASSERT( NULL != m_pIUnk );
  2232. if( NULL != m_pIUnk )
  2233. {
  2234. hResult = m_pIUnk->QueryInterface( IID_IADs, (void**) &pIOleDs );
  2235. ASSERT( SUCCEEDED( hResult ) );
  2236. if( SUCCEEDED( hResult ) )
  2237. {
  2238. __try
  2239. {
  2240. hResult = pIOleDs->GetInfo( );
  2241. }
  2242. __except( EXCEPTION_EXECUTE_HANDLER )
  2243. {
  2244. hResult = E_FAIL;
  2245. AfxMessageBox( _T("ERROR: AV caused by GetInfo") );
  2246. }
  2247. pIOleDs->Release( );
  2248. }
  2249. }
  2250. else
  2251. {
  2252. CreateTheObject( );
  2253. if( NULL != m_pIUnk )
  2254. {
  2255. hResult = m_pIUnk->QueryInterface( IID_IADs, (void**) &pIOleDs );
  2256. ASSERT( SUCCEEDED( hResult ) );
  2257. if( SUCCEEDED( hResult ) )
  2258. {
  2259. __try
  2260. {
  2261. hResult = pIOleDs->GetInfo( );
  2262. }
  2263. __except( EXCEPTION_EXECUTE_HANDLER )
  2264. {
  2265. hResult = E_FAIL;
  2266. AfxMessageBox( _T("ERROR: AV caused by GetInfo") );
  2267. }
  2268. pIOleDs->Release( );
  2269. }
  2270. ReleaseIfNotTransient( );
  2271. }
  2272. }
  2273. return hResult;
  2274. }
  2275. /***********************************************************
  2276. Function:
  2277. Arguments:
  2278. Return:
  2279. Purpose:
  2280. Author(s):
  2281. Revision:
  2282. Date:
  2283. ***********************************************************/
  2284. HRESULT COleDsObject::SetInfo( )
  2285. {
  2286. if( m_pDoc->UseVBStyle( ) )
  2287. {
  2288. return SetInfoVB( );
  2289. }
  2290. else
  2291. {
  2292. return SetInfoCPP( );
  2293. }
  2294. }
  2295. /***********************************************************
  2296. Function:
  2297. Arguments:
  2298. Return:
  2299. Purpose:
  2300. Author(s):
  2301. Revision:
  2302. Date:
  2303. ***********************************************************/
  2304. HRESULT COleDsObject::GetInfoCPP( )
  2305. {
  2306. HRESULT hResult;
  2307. ADS_ATTR_INFO* pAttrDef;
  2308. DWORD dwAttributes, dwIter;
  2309. IDirectoryObject* pIADsObject;
  2310. CString strPropName;
  2311. for( dwIter = 0L ;dwIter < (DWORD)m_pClass->GetPropertyCount( );dwIter++ )
  2312. {
  2313. m_pfReadValues[ dwIter ] = FALSE;
  2314. m_pfDirty[ dwIter ] = FALSE;
  2315. }
  2316. hResult = m_pIUnk->QueryInterface( IID_IDirectoryObject, (void**)&pIADsObject );
  2317. while( TRUE )
  2318. {
  2319. if( FAILED( hResult ) )
  2320. break;
  2321. {
  2322. ADS_OBJECT_INFO* pInfo;
  2323. //SMITHA HRESULT hResult;
  2324. TCHAR szText[ 256 ];
  2325. hResult = pIADsObject->GetObjectInformation( &pInfo );
  2326. while( TRUE )
  2327. {
  2328. if( FAILED( hResult ) )
  2329. {
  2330. TRACE( _T("[ADSVW] Error: GetObjectInformation retuns %lx\n"), hResult );
  2331. break;
  2332. }
  2333. if( NULL != pInfo->pszRDN )
  2334. {
  2335. Convert( szText, pInfo->pszRDN );
  2336. TRACE( _T("pszRDN = %s\n"), szText );
  2337. }
  2338. else
  2339. {
  2340. TRACE( _T("pszRDN is NULL\n") );
  2341. }
  2342. if( NULL != pInfo->pszObjectDN )
  2343. {
  2344. Convert( szText, pInfo->pszObjectDN );
  2345. TRACE( _T("pszObjectDN = %s\n"), szText );
  2346. }
  2347. else
  2348. {
  2349. TRACE( _T("pszObjectDN is NULL\n") );
  2350. }
  2351. if( NULL != pInfo->pszParentDN )
  2352. {
  2353. Convert( szText, pInfo->pszParentDN );
  2354. TRACE( _T("pszParentDN = %s\n"), szText );
  2355. }
  2356. else
  2357. {
  2358. TRACE( _T("pszParentDN is NULL\n") );
  2359. }
  2360. if( NULL != pInfo->pszSchemaDN )
  2361. {
  2362. Convert( szText, pInfo->pszSchemaDN );
  2363. TRACE( _T("pszSchemaDN = %s\n"), szText );
  2364. }
  2365. else
  2366. {
  2367. TRACE( _T("pszSchemaDN is NULL\n") );
  2368. }
  2369. if( NULL != pInfo->pszClassName )
  2370. {
  2371. Convert( szText, pInfo->pszClassName );
  2372. TRACE( _T("pszClassName = %s\n"), szText );
  2373. }
  2374. else
  2375. {
  2376. TRACE( _T("pszClassName is NULL\n") );
  2377. }
  2378. FreeADsMem( pInfo );
  2379. break;
  2380. }
  2381. }
  2382. hResult = pIADsObject->GetObjectAttributes( NULL,
  2383. (ULONG)-1L,
  2384. &pAttrDef,
  2385. &dwAttributes );
  2386. ASSERT( SUCCEEDED( hResult ) );
  2387. if( FAILED( hResult ) )
  2388. break;
  2389. for( dwIter = 0L ; dwIter < dwAttributes ; dwIter++ )
  2390. {
  2391. CopyAttributeValue( pAttrDef + dwIter );
  2392. }
  2393. FreeADsMem( (void*) pAttrDef );
  2394. break;
  2395. }
  2396. if( pIADsObject )
  2397. {
  2398. pIADsObject->Release( );
  2399. }
  2400. return hResult;
  2401. }
  2402. /***********************************************************
  2403. Function:
  2404. Arguments:
  2405. Return:
  2406. Purpose:
  2407. Author(s):
  2408. Revision:
  2409. Date:
  2410. ***********************************************************/
  2411. HRESULT COleDsObject::SetInfoVB( )
  2412. {
  2413. IADs* pIOleDs;
  2414. HRESULT hResult;
  2415. hResult = E_FAIL;
  2416. ASSERT( NULL != m_pIUnk );
  2417. if( NULL != m_pIUnk )
  2418. {
  2419. hResult = m_pIUnk->QueryInterface( IID_IADs, (void**) &pIOleDs );
  2420. ASSERT( SUCCEEDED( hResult ) );
  2421. if( SUCCEEDED( hResult ) )
  2422. {
  2423. hResult = pIOleDs->SetInfo( );
  2424. if( FAILED( hResult ) )
  2425. {
  2426. CString strError;
  2427. strError = OleDsGetErrorText( hResult );
  2428. AfxGetMainWnd()->MessageBox( strError, _T("SetInfo ERROR") );
  2429. }
  2430. pIOleDs->Release( );
  2431. }
  2432. }
  2433. else
  2434. {
  2435. CreateTheObject( );
  2436. if( NULL != m_pIUnk )
  2437. {
  2438. hResult = m_pIUnk->QueryInterface( IID_IADs, (void**) &pIOleDs );
  2439. ASSERT( SUCCEEDED( hResult ) );
  2440. if( SUCCEEDED( hResult ) )
  2441. {
  2442. hResult = pIOleDs->SetInfo( );
  2443. pIOleDs->Release( );
  2444. }
  2445. ReleaseIfNotTransient( );
  2446. }
  2447. }
  2448. return hResult;
  2449. }
  2450. /***********************************************************
  2451. Function:
  2452. Arguments:
  2453. Return:
  2454. Purpose:
  2455. Author(s):
  2456. Revision:
  2457. Date:
  2458. ***********************************************************/
  2459. HRESULT COleDsObject::GetDirtyAttributes( PADS_ATTR_INFO* ppAttrDef, DWORD* pdwCount )
  2460. {
  2461. HRESULT hResult = S_OK;
  2462. DWORD dwDirty = 0L;
  2463. DWORD dwIter, dwProps;
  2464. ADS_ATTR_INFO* pAttrDef;
  2465. ADS_ATTR_INFO* pAttrDefCurrent;
  2466. CString strPropName;
  2467. *ppAttrDef = NULL;
  2468. *pdwCount = 0L;
  2469. dwProps = (DWORD)m_pClass->GetPropertyCount( );
  2470. for( dwIter = 0L ; dwIter < dwProps ; dwIter++ )
  2471. {
  2472. if( m_pfDirty[ dwIter ] )
  2473. dwDirty++;
  2474. }
  2475. if( !dwDirty )
  2476. return S_FALSE;
  2477. pAttrDef = (ADS_ATTR_INFO*) AllocADsMem( sizeof(ADS_ATTR_INFO) *dwDirty );
  2478. ASSERT( pAttrDef );
  2479. if( !pAttrDef )
  2480. return E_FAIL;
  2481. pAttrDefCurrent = pAttrDef;
  2482. for( dwIter = 0L ; dwIter < dwProps ; dwIter++ )
  2483. {
  2484. if( m_pfDirty[ dwIter ] )
  2485. {
  2486. CreateAttributeValue( pAttrDefCurrent, dwIter );
  2487. pAttrDefCurrent++;
  2488. }
  2489. }
  2490. *ppAttrDef = pAttrDef;
  2491. *pdwCount = dwDirty;
  2492. return hResult;
  2493. }
  2494. /***********************************************************
  2495. Function:
  2496. Arguments:
  2497. Return:
  2498. Purpose:
  2499. Author(s):
  2500. Revision:
  2501. Date:
  2502. ***********************************************************/
  2503. void COleDsObject::FreeDirtyAttributes( PADS_ATTR_INFO pAttrDef, DWORD dwCount )
  2504. {
  2505. DWORD dwIter;
  2506. CProperty* pProperty;
  2507. CString strPropName;
  2508. TCHAR szPropName[ 128 ];
  2509. ASSERT( NULL != pAttrDef );
  2510. if( NULL == pAttrDef )
  2511. return;
  2512. for( dwIter = 0L ; dwIter < dwCount ; dwIter++ )
  2513. {
  2514. ASSERT( NULL != pAttrDef[ dwIter ].pszAttrName );
  2515. if( NULL != pAttrDef[ dwIter ].pszAttrName )
  2516. {
  2517. int nIdx;
  2518. Convert( szPropName, pAttrDef[ dwIter ].pszAttrName );
  2519. strPropName = szPropName;
  2520. nIdx = m_pClass->LookupProperty( strPropName );
  2521. if( -1 != nIdx )
  2522. {
  2523. pProperty = m_pClass->GetProperty( nIdx );
  2524. pProperty->FreeAttrInfo( pAttrDef + dwIter );
  2525. }
  2526. }
  2527. }
  2528. FreeADsMem( pAttrDef );
  2529. }
  2530. /***********************************************************
  2531. Function:
  2532. Arguments:
  2533. Return:
  2534. Purpose:
  2535. Author(s):
  2536. Revision:
  2537. Date:
  2538. ***********************************************************/
  2539. HRESULT COleDsObject::SetInfoCPP( )
  2540. {
  2541. HRESULT hResult;
  2542. DWORD dwDirty = 0L;
  2543. DWORD dwAttributesModified;
  2544. ADS_ATTR_INFO* pAttrDef;
  2545. IDirectoryObject* pIADsObject;
  2546. hResult = GetDirtyAttributes( &pAttrDef, &dwDirty );
  2547. if( SUCCEEDED( hResult ) )
  2548. {
  2549. hResult = m_pIUnk->QueryInterface( IID_IDirectoryObject, (void**)&pIADsObject );
  2550. if( FAILED( hResult ) )
  2551. return hResult;
  2552. hResult = pIADsObject->SetObjectAttributes( pAttrDef,
  2553. dwDirty,
  2554. &dwAttributesModified );
  2555. pIADsObject->Release( );
  2556. FreeDirtyAttributes( pAttrDef, dwDirty );
  2557. if( FAILED( hResult ) )
  2558. {
  2559. CString strError;
  2560. strError = OleDsGetErrorText( hResult );
  2561. AfxGetMainWnd()->MessageBox( strError, _T("SetObjectAttributes ERROR") );
  2562. }
  2563. }
  2564. return hResult;
  2565. }
  2566. /******************************************************************************
  2567. Function: PurgeObject
  2568. Arguments:
  2569. Return:
  2570. Purpose:
  2571. Author(s):
  2572. Revision:
  2573. Date:
  2574. ******************************************************************************/
  2575. HRESULT COleDsObject::PurgeObject( IADsContainer* pParent,
  2576. IUnknown* pIUnknown,
  2577. LPWSTR pszPrefix
  2578. )
  2579. {
  2580. BSTR bstrName = NULL;
  2581. BSTR bstrClass = NULL;
  2582. VARIANT var;
  2583. HRESULT hResult;
  2584. IUnknown* pIChildUnk = NULL;
  2585. IADs* pIChildOleDs = NULL;
  2586. IADs* pADs;
  2587. BSTR bstrObjName, bstrObjClass;
  2588. IEnumVARIANT* pIEnumVar = NULL;
  2589. IADsContainer* pIContainer = NULL;
  2590. ULONG ulFetch = 0L;
  2591. BOOL bFirst = FALSE;
  2592. TCHAR szName[ 128 ];
  2593. if( NULL == pParent || NULL == pIUnknown )
  2594. return E_FAIL;
  2595. hResult = pIUnknown->QueryInterface( IID_IADs,
  2596. (void**)&pADs );
  2597. if( FAILED( hResult ) )
  2598. return E_FAIL;
  2599. if( NULL == m_pDeleteStatus )
  2600. {
  2601. m_bAbort = FALSE;
  2602. m_pDeleteStatus = new CDeleteStatus;
  2603. m_pDeleteStatus->SetAbortFlag( &m_bAbort );
  2604. m_pDeleteStatus->Create( IDD_DELETESTATUS );
  2605. m_pDeleteStatus->ShowWindow( SW_SHOW );
  2606. m_pDeleteStatus->UpdateWindow( );
  2607. bFirst = TRUE;
  2608. }
  2609. if( !m_bAbort )
  2610. {
  2611. pADs->get_Name( &bstrObjName );
  2612. pADs->get_Class( &bstrObjClass );
  2613. pADs->Release( );
  2614. hResult = pIUnknown->QueryInterface( IID_IADsContainer,
  2615. (void**)&pIContainer );
  2616. if( FAILED( hResult ) )
  2617. {
  2618. Convert( szName, bstrObjName );
  2619. if( NULL != pszPrefix && !_wcsnicmp( bstrObjName, pszPrefix, wcslen(pszPrefix) ) )
  2620. {
  2621. m_pDeleteStatus->SetCurrentObjectText( szName );
  2622. m_pDeleteStatus->SetStatusText( _T("Pending") );
  2623. hResult = pParent->Delete( bstrObjClass, bstrObjName );
  2624. m_pDeleteStatus->SetStatusText( SUCCEEDED( hResult) ?
  2625. _T("OK"):_T("FAIL") );
  2626. TRACE( _T("Delete %S returns %lx\n"), bstrObjName, hResult );
  2627. }
  2628. if( NULL == pszPrefix )
  2629. {
  2630. m_pDeleteStatus->SetCurrentObjectText( szName );
  2631. m_pDeleteStatus->SetStatusText( _T("Pending") );
  2632. hResult = pParent->Delete( bstrObjClass, bstrObjName );
  2633. m_pDeleteStatus->SetStatusText( SUCCEEDED( hResult) ?
  2634. _T("OK"):_T("FAIL") );
  2635. TRACE( _T("Delete %S returns %lx\n"), bstrObjName, hResult );
  2636. }
  2637. SysFreeString( bstrObjClass );
  2638. SysFreeString( bstrObjName );
  2639. return S_OK;
  2640. }
  2641. }
  2642. if( !m_bAbort )
  2643. {
  2644. hResult = ADsBuildEnumerator( pIContainer, &pIEnumVar );
  2645. while( SUCCEEDED( hResult ) && !m_bAbort )
  2646. {
  2647. ulFetch = 0L;
  2648. hResult = ADsEnumerateNext( pIEnumVar, 1, &var, &ulFetch );
  2649. if( FAILED( hResult ) )
  2650. continue;
  2651. if( !ulFetch )
  2652. break;
  2653. V_DISPATCH( &var )->QueryInterface( IID_IUnknown, (void**)&pIChildUnk );
  2654. VariantClear( &var );
  2655. if( NULL != pIChildUnk )
  2656. {
  2657. PurgeObject( pIContainer, pIChildUnk, pszPrefix );
  2658. pIChildUnk->Release( );
  2659. }
  2660. pIChildUnk = NULL;
  2661. }
  2662. if( NULL != pIEnumVar )
  2663. {
  2664. ADsFreeEnumerator( pIEnumVar );
  2665. }
  2666. pIContainer->Release( );
  2667. }
  2668. if( !m_bAbort )
  2669. {
  2670. Convert( szName, bstrObjName );
  2671. m_pDeleteStatus->SetCurrentObjectText( szName );
  2672. m_pDeleteStatus->SetStatusText( _T("Pending") );
  2673. hResult = pParent->Delete( bstrObjClass, bstrObjName );
  2674. m_pDeleteStatus->SetStatusText( SUCCEEDED( hResult) ?
  2675. _T("OK"):_T("FAIL") );
  2676. TRACE( _T("\tDelete %S (%S) ends with %lx\n"), bstrObjName, bstrObjClass );
  2677. SysFreeString( bstrObjClass );
  2678. SysFreeString( bstrObjName );
  2679. }
  2680. if( bFirst )
  2681. {
  2682. m_pDeleteStatus->DestroyWindow( );
  2683. delete m_pDeleteStatus;
  2684. m_pDeleteStatus = NULL;
  2685. }
  2686. return hResult;
  2687. }
  2688.