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.

1400 lines
31 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1996
  5. //
  6. // File: cschema.cxx
  7. //
  8. // Contents: Windows NT 3.51
  9. //
  10. //
  11. // History: 01-09-96 yihsins Created.
  12. //
  13. //----------------------------------------------------------------------------
  14. #include "nwcompat.hxx"
  15. #pragma hdrstop
  16. /******************************************************************/
  17. /* Class CNWCOMPATSchema
  18. /******************************************************************/
  19. DEFINE_IDispatch_Implementation(CNWCOMPATSchema)
  20. DEFINE_IADs_Implementation(CNWCOMPATSchema)
  21. CNWCOMPATSchema::CNWCOMPATSchema()
  22. {
  23. VariantInit( &_vFilter );
  24. ENLIST_TRACKING(CNWCOMPATSchema);
  25. }
  26. CNWCOMPATSchema::~CNWCOMPATSchema()
  27. {
  28. VariantClear( &_vFilter );
  29. delete _pDispMgr;
  30. }
  31. HRESULT
  32. CNWCOMPATSchema::CreateSchema(
  33. BSTR bstrParent,
  34. BSTR bstrName,
  35. DWORD dwObjectState,
  36. REFIID riid,
  37. void **ppvObj
  38. )
  39. {
  40. CNWCOMPATSchema FAR *pSchema = NULL;
  41. HRESULT hr = S_OK;
  42. hr = AllocateSchemaObject( &pSchema );
  43. BAIL_ON_FAILURE(hr);
  44. hr = pSchema->InitializeCoreObject(
  45. bstrParent,
  46. bstrName,
  47. SCHEMA_CLASS_NAME,
  48. NO_SCHEMA,
  49. CLSID_NWCOMPATSchema,
  50. dwObjectState );
  51. BAIL_ON_FAILURE(hr);
  52. hr = pSchema->QueryInterface( riid, ppvObj );
  53. BAIL_ON_FAILURE(hr);
  54. pSchema->Release();
  55. RRETURN(hr);
  56. error:
  57. delete pSchema;
  58. RRETURN_EXP_IF_ERR(hr);
  59. }
  60. STDMETHODIMP
  61. CNWCOMPATSchema::QueryInterface(REFIID iid, LPVOID FAR* ppv)
  62. {
  63. if (ppv == NULL) {
  64. RRETURN(E_POINTER);
  65. }
  66. if (IsEqualIID(iid, IID_IUnknown))
  67. {
  68. *ppv = (IADs FAR *) this;
  69. }
  70. else if (IsEqualIID(iid, IID_IDispatch))
  71. {
  72. *ppv = (IADs FAR *)this;
  73. }
  74. else if (IsEqualIID(iid, IID_ISupportErrorInfo))
  75. {
  76. *ppv = (ISupportErrorInfo FAR *) this;
  77. }
  78. else if (IsEqualIID(iid, IID_IADsContainer))
  79. {
  80. *ppv = (IADsContainer FAR *)this;
  81. }
  82. else if (IsEqualIID(iid, IID_IADs))
  83. {
  84. *ppv = (IADs FAR *) this;
  85. }
  86. else
  87. {
  88. *ppv = NULL;
  89. return E_NOINTERFACE;
  90. }
  91. AddRef();
  92. return NOERROR;
  93. }
  94. /* ISupportErrorInfo method */
  95. STDMETHODIMP
  96. CNWCOMPATSchema::InterfaceSupportsErrorInfo(
  97. THIS_ REFIID riid
  98. )
  99. {
  100. if (IsEqualIID(riid, IID_IADs) ||
  101. IsEqualIID(riid, IID_IADsContainer)) {
  102. RRETURN(S_OK);
  103. } else {
  104. RRETURN(S_FALSE);
  105. }
  106. }
  107. /* IADs methods */
  108. STDMETHODIMP
  109. CNWCOMPATSchema::SetInfo(THIS)
  110. {
  111. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  112. }
  113. STDMETHODIMP
  114. CNWCOMPATSchema::GetInfo(THIS)
  115. {
  116. RRETURN(S_OK);
  117. }
  118. /* IADsContainer methods */
  119. STDMETHODIMP
  120. CNWCOMPATSchema::get_Count(long FAR* retval)
  121. {
  122. HRESULT hr;
  123. if ( !retval )
  124. RRETURN_EXP_IF_ERR(E_ADS_BAD_PARAMETER);
  125. *retval = g_cNWCOMPATClasses + g_cNWCOMPATSyntax;
  126. RRETURN(S_OK);
  127. }
  128. STDMETHODIMP
  129. CNWCOMPATSchema::get_Filter(THIS_ VARIANT FAR* pVar)
  130. {
  131. HRESULT hr;
  132. if ( !pVar )
  133. RRETURN_EXP_IF_ERR(E_ADS_BAD_PARAMETER);
  134. VariantInit( pVar );
  135. hr = VariantCopy( pVar, &_vFilter );
  136. RRETURN_EXP_IF_ERR(hr);
  137. }
  138. STDMETHODIMP
  139. CNWCOMPATSchema::put_Filter(THIS_ VARIANT Var)
  140. {
  141. HRESULT hr;
  142. hr = VariantCopy( &_vFilter, &Var );
  143. RRETURN_EXP_IF_ERR(hr);
  144. }
  145. STDMETHODIMP
  146. CNWCOMPATSchema::put_Hints(THIS_ VARIANT Var)
  147. {
  148. RRETURN_EXP_IF_ERR( E_NOTIMPL);
  149. }
  150. STDMETHODIMP
  151. CNWCOMPATSchema::get_Hints(THIS_ VARIANT FAR* pVar)
  152. {
  153. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  154. }
  155. STDMETHODIMP
  156. CNWCOMPATSchema::GetObject(
  157. THIS_ BSTR ClassName,
  158. BSTR RelativeName,
  159. IDispatch * FAR* ppObject)
  160. {
  161. TCHAR szBuffer[MAX_PATH];
  162. HRESULT hr = S_OK;
  163. if (!RelativeName || !*RelativeName) {
  164. RRETURN_EXP_IF_ERR(E_ADS_UNKNOWN_OBJECT);
  165. }
  166. memset(szBuffer, 0, sizeof(szBuffer));
  167. wcscpy(szBuffer, _ADsPath);
  168. wcscat(szBuffer, L"/");
  169. wcscat(szBuffer, RelativeName);
  170. if (ClassName && *ClassName) {
  171. wcscat(szBuffer,L",");
  172. wcscat(szBuffer, ClassName);
  173. }
  174. hr = ::GetObject(
  175. szBuffer,
  176. (LPVOID *)ppObject
  177. );
  178. BAIL_ON_FAILURE(hr);
  179. error:
  180. RRETURN_EXP_IF_ERR(hr);
  181. }
  182. STDMETHODIMP
  183. CNWCOMPATSchema::get__NewEnum(THIS_ IUnknown * FAR* retval)
  184. {
  185. HRESULT hr;
  186. IEnumVARIANT *penum = NULL;
  187. if ( !retval )
  188. RRETURN_EXP_IF_ERR(E_ADS_BAD_PARAMETER);
  189. *retval = NULL;
  190. //
  191. // Create new enumerator for items currently
  192. // in collection and QI for IUnknown
  193. //
  194. hr = CNWCOMPATSchemaEnum::Create( (CNWCOMPATSchemaEnum **)&penum,
  195. _ADsPath,
  196. _Name,
  197. _vFilter );
  198. BAIL_ON_FAILURE(hr);
  199. hr = penum->QueryInterface( IID_IUnknown, (VOID FAR* FAR*)retval );
  200. BAIL_ON_FAILURE(hr);
  201. if ( penum )
  202. penum->Release();
  203. RRETURN(hr);
  204. error:
  205. if ( penum )
  206. delete penum;
  207. RRETURN_EXP_IF_ERR(hr);
  208. }
  209. STDMETHODIMP
  210. CNWCOMPATSchema::Create(
  211. THIS_ BSTR ClassName,
  212. BSTR RelativeName,
  213. IDispatch * FAR* ppObject)
  214. {
  215. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  216. }
  217. STDMETHODIMP
  218. CNWCOMPATSchema::Delete(THIS_ BSTR SourceName, BSTR Type)
  219. {
  220. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  221. }
  222. STDMETHODIMP
  223. CNWCOMPATSchema::CopyHere(
  224. THIS_ BSTR SourceName,
  225. BSTR NewName,
  226. IDispatch * FAR* ppObject
  227. )
  228. {
  229. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  230. }
  231. STDMETHODIMP
  232. CNWCOMPATSchema::MoveHere(
  233. THIS_ BSTR SourceName,
  234. BSTR NewName,
  235. IDispatch * FAR* ppObject
  236. )
  237. {
  238. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  239. }
  240. HRESULT
  241. CNWCOMPATSchema::AllocateSchemaObject(CNWCOMPATSchema FAR * FAR * ppSchema)
  242. {
  243. CNWCOMPATSchema FAR *pSchema = NULL;
  244. CAggregatorDispMgr FAR *pDispMgr = NULL;
  245. HRESULT hr = S_OK;
  246. pSchema = new CNWCOMPATSchema();
  247. if ( pSchema == NULL )
  248. hr = E_OUTOFMEMORY;
  249. BAIL_ON_FAILURE(hr);
  250. pDispMgr = new CAggregatorDispMgr;
  251. if ( pDispMgr == NULL )
  252. hr = E_OUTOFMEMORY;
  253. BAIL_ON_FAILURE(hr);
  254. hr = LoadTypeInfoEntry( pDispMgr,
  255. LIBID_ADs,
  256. IID_IADs,
  257. (IADs *) pSchema,
  258. DISPID_REGULAR );
  259. BAIL_ON_FAILURE(hr);
  260. hr = LoadTypeInfoEntry( pDispMgr,
  261. LIBID_ADs,
  262. IID_IADsContainer,
  263. (IADsContainer *) pSchema,
  264. DISPID_NEWENUM );
  265. BAIL_ON_FAILURE(hr);
  266. pSchema->_pDispMgr = pDispMgr;
  267. *ppSchema = pSchema;
  268. RRETURN(hr);
  269. error:
  270. delete pDispMgr;
  271. delete pSchema;
  272. RRETURN(hr);
  273. }
  274. /******************************************************************/
  275. /* Class CNWCOMPATClass
  276. /******************************************************************/
  277. DEFINE_IDispatch_Implementation(CNWCOMPATClass)
  278. DEFINE_IADs_Implementation(CNWCOMPATClass)
  279. CNWCOMPATClass::CNWCOMPATClass()
  280. : _pDispMgr( NULL ),
  281. _aPropertyInfo( NULL ),
  282. _cPropertyInfo( 0 ),
  283. _bstrCLSID( NULL ),
  284. _bstrOID( NULL ),
  285. _bstrPrimaryInterface( NULL ),
  286. _fAbstract( FALSE ),
  287. _fContainer( FALSE ),
  288. _bstrHelpFileName( NULL ),
  289. _lHelpFileContext( 0 )
  290. {
  291. VariantInit( &_vMandatoryProperties );
  292. VariantInit( &_vOptionalProperties );
  293. VariantInit( &_vPossSuperiors );
  294. VariantInit( &_vContainment );
  295. VariantInit( &_vFilter );
  296. ENLIST_TRACKING(CNWCOMPATClass);
  297. }
  298. CNWCOMPATClass::~CNWCOMPATClass()
  299. {
  300. if ( _bstrCLSID ) {
  301. ADsFreeString( _bstrCLSID );
  302. }
  303. if ( _bstrOID ) {
  304. ADsFreeString( _bstrOID );
  305. }
  306. if ( _bstrPrimaryInterface ) {
  307. ADsFreeString( _bstrPrimaryInterface );
  308. }
  309. if ( _bstrHelpFileName ) {
  310. ADsFreeString( _bstrHelpFileName );
  311. }
  312. VariantClear( &_vMandatoryProperties );
  313. VariantClear( &_vOptionalProperties );
  314. VariantClear( &_vPossSuperiors );
  315. VariantClear( &_vContainment );
  316. VariantClear( &_vFilter );
  317. delete _pDispMgr;
  318. }
  319. HRESULT
  320. CNWCOMPATClass::CreateClass(
  321. BSTR bstrParent,
  322. CLASSINFO *pClassInfo,
  323. DWORD dwObjectState,
  324. REFIID riid,
  325. void **ppvObj
  326. )
  327. {
  328. CNWCOMPATClass FAR *pClass = NULL;
  329. HRESULT hr = S_OK;
  330. BSTR bstrTmp = NULL;
  331. hr = AllocateClassObject( &pClass );
  332. BAIL_ON_FAILURE(hr);
  333. pClass->_aPropertyInfo = pClassInfo->aPropertyInfo;
  334. pClass->_cPropertyInfo = pClassInfo->cPropertyInfo;
  335. pClass->_lHelpFileContext = pClassInfo->lHelpFileContext;
  336. pClass->_fContainer = (VARIANT_BOOL) pClassInfo->fContainer;
  337. pClass->_fAbstract = (VARIANT_BOOL) pClassInfo->fAbstract;
  338. hr = StringFromCLSID( (REFCLSID) *(pClassInfo->pPrimaryInterfaceGUID),
  339. &bstrTmp );
  340. BAIL_ON_FAILURE(hr);
  341. hr = ADsAllocString( bstrTmp,
  342. &pClass->_bstrPrimaryInterface );
  343. BAIL_ON_FAILURE(hr);
  344. CoTaskMemFree( bstrTmp );
  345. bstrTmp = NULL;
  346. hr = StringFromCLSID( (REFCLSID) *(pClassInfo->pCLSID),
  347. &bstrTmp );
  348. BAIL_ON_FAILURE(hr);
  349. hr = ADsAllocString( bstrTmp,
  350. &pClass->_bstrCLSID );
  351. BAIL_ON_FAILURE(hr);
  352. CoTaskMemFree( bstrTmp );
  353. bstrTmp = NULL;
  354. hr = ADsAllocString( pClassInfo->bstrOID, &pClass->_bstrOID);
  355. BAIL_ON_FAILURE(hr);
  356. hr = MakeVariantFromStringList( pClassInfo->bstrMandatoryProperties,
  357. &(pClass->_vMandatoryProperties));
  358. BAIL_ON_FAILURE(hr);
  359. hr = MakeVariantFromStringList( pClassInfo->bstrOptionalProperties,
  360. &(pClass->_vOptionalProperties));
  361. BAIL_ON_FAILURE(hr);
  362. hr = MakeVariantFromStringList( pClassInfo->bstrPossSuperiors,
  363. &(pClass->_vPossSuperiors));
  364. BAIL_ON_FAILURE(hr);
  365. hr = MakeVariantFromStringList( pClassInfo->bstrContainment,
  366. &(pClass->_vContainment));
  367. BAIL_ON_FAILURE(hr);
  368. hr = ADsAllocString( pClassInfo->bstrHelpFileName,
  369. &pClass->_bstrHelpFileName);
  370. BAIL_ON_FAILURE(hr);
  371. hr = pClass->InitializeCoreObject(
  372. bstrParent,
  373. pClassInfo->bstrName,
  374. CLASS_CLASS_NAME,
  375. NO_SCHEMA,
  376. CLSID_NWCOMPATClass,
  377. dwObjectState );
  378. BAIL_ON_FAILURE(hr);
  379. hr = pClass->QueryInterface( riid, ppvObj );
  380. BAIL_ON_FAILURE(hr);
  381. pClass->Release();
  382. RRETURN(hr);
  383. error:
  384. if ( bstrTmp != NULL )
  385. CoTaskMemFree( bstrTmp );
  386. delete pClass;
  387. RRETURN_EXP_IF_ERR(hr);
  388. }
  389. STDMETHODIMP
  390. CNWCOMPATClass::QueryInterface(REFIID iid, LPVOID FAR* ppv)
  391. {
  392. if (ppv == NULL) {
  393. RRETURN(E_POINTER);
  394. }
  395. if (IsEqualIID(iid, IID_IUnknown))
  396. {
  397. *ppv = (IADsClass FAR * ) this;
  398. }
  399. else if (IsEqualIID(iid, IID_IDispatch))
  400. {
  401. *ppv = (IADs FAR *) this;
  402. }
  403. else if (IsEqualIID(iid, IID_ISupportErrorInfo))
  404. {
  405. *ppv = (ISupportErrorInfo FAR *) this;
  406. }
  407. else if (IsEqualIID(iid, IID_IADs))
  408. {
  409. *ppv = (IADs FAR *) this;
  410. }
  411. else if (IsEqualIID(iid, IID_IADsClass))
  412. {
  413. *ppv = (IADsClass FAR *) this;
  414. }
  415. else
  416. {
  417. *ppv = NULL;
  418. return E_NOINTERFACE;
  419. }
  420. AddRef();
  421. return NOERROR;
  422. }
  423. /* ISupportErrorInfo method */
  424. STDMETHODIMP
  425. CNWCOMPATClass::InterfaceSupportsErrorInfo(
  426. THIS_ REFIID riid
  427. )
  428. {
  429. if (IsEqualIID(riid, IID_IADs) ||
  430. IsEqualIID(riid, IID_IADsClass)) {
  431. RRETURN(S_OK);
  432. } else {
  433. RRETURN(S_FALSE);
  434. }
  435. }
  436. /* IADs methods */
  437. STDMETHODIMP
  438. CNWCOMPATClass::SetInfo(THIS)
  439. {
  440. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  441. }
  442. STDMETHODIMP
  443. CNWCOMPATClass::GetInfo(THIS)
  444. {
  445. RRETURN(S_OK);
  446. }
  447. /* IADsClass methods */
  448. STDMETHODIMP
  449. CNWCOMPATClass::get_PrimaryInterface( THIS_ BSTR FAR *pbstrGUID )
  450. {
  451. HRESULT hr;
  452. if ( !pbstrGUID )
  453. RRETURN_EXP_IF_ERR(E_ADS_BAD_PARAMETER);
  454. hr = ADsAllocString( _bstrPrimaryInterface, pbstrGUID );
  455. RRETURN_EXP_IF_ERR(hr);
  456. }
  457. STDMETHODIMP
  458. CNWCOMPATClass::get_CLSID( THIS_ BSTR FAR *pbstrCLSID )
  459. {
  460. HRESULT hr;
  461. if ( !pbstrCLSID )
  462. RRETURN_EXP_IF_ERR(E_ADS_BAD_PARAMETER);
  463. hr = ADsAllocString( _bstrCLSID, pbstrCLSID );
  464. RRETURN_EXP_IF_ERR(hr);
  465. }
  466. STDMETHODIMP
  467. CNWCOMPATClass::put_CLSID( THIS_ BSTR bstrCLSID )
  468. {
  469. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  470. }
  471. STDMETHODIMP
  472. CNWCOMPATClass::get_OID( THIS_ BSTR FAR *pbstrOID )
  473. {
  474. HRESULT hr;
  475. if ( !pbstrOID )
  476. RRETURN_EXP_IF_ERR(E_ADS_BAD_PARAMETER);
  477. hr = ADsAllocString( _bstrOID, pbstrOID );
  478. RRETURN_EXP_IF_ERR(hr);
  479. }
  480. STDMETHODIMP
  481. CNWCOMPATClass::put_OID( THIS_ BSTR bstrOID )
  482. {
  483. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  484. }
  485. STDMETHODIMP
  486. CNWCOMPATClass::get_Abstract( THIS_ VARIANT_BOOL FAR *pfAbstract )
  487. {
  488. if ( !pfAbstract )
  489. RRETURN_EXP_IF_ERR(E_ADS_BAD_PARAMETER);
  490. *pfAbstract = _fAbstract? VARIANT_TRUE : VARIANT_FALSE;
  491. RRETURN(S_OK);
  492. }
  493. STDMETHODIMP
  494. CNWCOMPATClass::put_Abstract( THIS_ VARIANT_BOOL fAbstract )
  495. {
  496. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  497. }
  498. STDMETHODIMP
  499. CNWCOMPATClass::get_Auxiliary( THIS_ VARIANT_BOOL FAR *pfAuxiliary )
  500. {
  501. if ( !pfAuxiliary )
  502. RRETURN_EXP_IF_ERR(E_ADS_BAD_PARAMETER);
  503. *pfAuxiliary = VARIANT_FALSE;
  504. RRETURN(S_OK);
  505. }
  506. STDMETHODIMP
  507. CNWCOMPATClass::put_Auxiliary( THIS_ VARIANT_BOOL fAuxiliary )
  508. {
  509. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  510. }
  511. STDMETHODIMP
  512. CNWCOMPATClass::get_MandatoryProperties( THIS_ VARIANT FAR *pvMandatoryProperties )
  513. {
  514. HRESULT hr;
  515. VariantInit( pvMandatoryProperties );
  516. hr = VariantCopy( pvMandatoryProperties, &_vMandatoryProperties );
  517. RRETURN_EXP_IF_ERR(hr);
  518. }
  519. STDMETHODIMP
  520. CNWCOMPATClass::put_MandatoryProperties( THIS_ VARIANT vMandatoryProperties )
  521. {
  522. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  523. }
  524. STDMETHODIMP
  525. CNWCOMPATClass::get_DerivedFrom( THIS_ VARIANT FAR *pvDerivedFrom )
  526. {
  527. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  528. }
  529. STDMETHODIMP
  530. CNWCOMPATClass::put_DerivedFrom( THIS_ VARIANT vDerivedFrom )
  531. {
  532. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  533. }
  534. STDMETHODIMP
  535. CNWCOMPATClass::get_AuxDerivedFrom( THIS_ VARIANT FAR *pvAuxDerivedFrom )
  536. {
  537. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  538. }
  539. STDMETHODIMP
  540. CNWCOMPATClass::put_AuxDerivedFrom( THIS_ VARIANT vAuxDerivedFrom )
  541. {
  542. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  543. }
  544. STDMETHODIMP
  545. CNWCOMPATClass::get_PossibleSuperiors( THIS_ VARIANT FAR *pvPossSuperiors )
  546. {
  547. HRESULT hr;
  548. VariantInit( pvPossSuperiors );
  549. hr = VariantCopy( pvPossSuperiors, &_vPossSuperiors );
  550. RRETURN_EXP_IF_ERR(hr);
  551. }
  552. STDMETHODIMP
  553. CNWCOMPATClass::put_PossibleSuperiors( THIS_ VARIANT vPossSuperiors )
  554. {
  555. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  556. }
  557. STDMETHODIMP
  558. CNWCOMPATClass::get_Containment( THIS_ VARIANT FAR *pvContainment )
  559. {
  560. HRESULT hr;
  561. VariantInit( pvContainment );
  562. hr = VariantCopy( pvContainment, &_vContainment );
  563. RRETURN_EXP_IF_ERR(hr);
  564. }
  565. STDMETHODIMP
  566. CNWCOMPATClass::put_Containment( THIS_ VARIANT vContainment )
  567. {
  568. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  569. }
  570. STDMETHODIMP
  571. CNWCOMPATClass::get_Container( THIS_ VARIANT_BOOL FAR *pfContainer )
  572. {
  573. if ( !pfContainer )
  574. RRETURN_EXP_IF_ERR(E_ADS_BAD_PARAMETER);
  575. *pfContainer = _fContainer? VARIANT_TRUE : VARIANT_FALSE;
  576. RRETURN(S_OK);
  577. }
  578. STDMETHODIMP
  579. CNWCOMPATClass::put_Container( THIS_ VARIANT_BOOL fContainer )
  580. {
  581. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  582. }
  583. STDMETHODIMP
  584. CNWCOMPATClass::get_HelpFileName( THIS_ BSTR FAR *pbstrHelpFileName )
  585. {
  586. HRESULT hr;
  587. if ( !pbstrHelpFileName )
  588. RRETURN_EXP_IF_ERR(E_ADS_BAD_PARAMETER);
  589. hr = ADsAllocString( _bstrHelpFileName, pbstrHelpFileName );
  590. RRETURN_EXP_IF_ERR(hr);
  591. }
  592. STDMETHODIMP
  593. CNWCOMPATClass::put_HelpFileName( THIS_ BSTR bstrHelpFile )
  594. {
  595. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  596. }
  597. STDMETHODIMP
  598. CNWCOMPATClass::get_HelpFileContext( THIS_ long FAR *plHelpContext )
  599. {
  600. if ( !plHelpContext )
  601. RRETURN_EXP_IF_ERR(E_ADS_BAD_PARAMETER);
  602. *plHelpContext = _lHelpFileContext;
  603. RRETURN(S_OK);
  604. }
  605. STDMETHODIMP
  606. CNWCOMPATClass::put_HelpFileContext( THIS_ long lHelpContext )
  607. {
  608. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  609. }
  610. STDMETHODIMP
  611. CNWCOMPATClass::Qualifiers(THIS_ IADsCollection FAR* FAR* ppQualifiers)
  612. {
  613. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  614. }
  615. HRESULT
  616. CNWCOMPATClass::AllocateClassObject(CNWCOMPATClass FAR * FAR * ppClass)
  617. {
  618. CNWCOMPATClass FAR *pClass = NULL;
  619. CAggregatorDispMgr FAR *pDispMgr = NULL;
  620. HRESULT hr = S_OK;
  621. pClass = new CNWCOMPATClass();
  622. if ( pClass == NULL )
  623. hr = E_OUTOFMEMORY;
  624. BAIL_ON_FAILURE(hr);
  625. pDispMgr = new CAggregatorDispMgr;
  626. if ( pDispMgr == NULL )
  627. hr = E_OUTOFMEMORY;
  628. BAIL_ON_FAILURE(hr);
  629. hr = LoadTypeInfoEntry( pDispMgr,
  630. LIBID_ADs,
  631. IID_IADs,
  632. (IADs *) pClass,
  633. DISPID_REGULAR );
  634. BAIL_ON_FAILURE(hr);
  635. hr = LoadTypeInfoEntry( pDispMgr,
  636. LIBID_ADs,
  637. IID_IADsClass,
  638. (IADsClass *) pClass,
  639. DISPID_REGULAR );
  640. BAIL_ON_FAILURE(hr);
  641. pClass->_pDispMgr = pDispMgr;
  642. *ppClass = pClass;
  643. RRETURN(hr);
  644. error:
  645. delete pDispMgr;
  646. delete pClass;
  647. RRETURN(hr);
  648. }
  649. /******************************************************************/
  650. /* Class CNWCOMPATProperty
  651. /******************************************************************/
  652. DEFINE_IDispatch_Implementation(CNWCOMPATProperty)
  653. DEFINE_IADs_Implementation(CNWCOMPATProperty)
  654. CNWCOMPATProperty::CNWCOMPATProperty()
  655. : _pDispMgr( NULL ),
  656. _bstrOID( NULL ),
  657. _bstrSyntax( NULL ),
  658. _lMaxRange( 0 ),
  659. _lMinRange( 0 ),
  660. _fMultiValued( FALSE )
  661. {
  662. ENLIST_TRACKING(CNWCOMPATProperty);
  663. }
  664. CNWCOMPATProperty::~CNWCOMPATProperty()
  665. {
  666. if ( _bstrOID ) {
  667. ADsFreeString( _bstrOID );
  668. }
  669. if ( _bstrSyntax ) {
  670. ADsFreeString( _bstrSyntax );
  671. }
  672. delete _pDispMgr;
  673. }
  674. HRESULT
  675. CNWCOMPATProperty::CreateProperty(
  676. BSTR bstrParent,
  677. PROPERTYINFO *pPropertyInfo,
  678. DWORD dwObjectState,
  679. REFIID riid,
  680. void **ppvObj
  681. )
  682. {
  683. CNWCOMPATProperty FAR * pProperty = NULL;
  684. HRESULT hr = S_OK;
  685. hr = AllocatePropertyObject( &pProperty );
  686. BAIL_ON_FAILURE(hr);
  687. hr = ADsAllocString( pPropertyInfo->bstrOID, &pProperty->_bstrOID);
  688. BAIL_ON_FAILURE(hr);
  689. hr = ADsAllocString( pPropertyInfo->bstrSyntax, &pProperty->_bstrSyntax);
  690. BAIL_ON_FAILURE(hr);
  691. pProperty->_lMaxRange = pPropertyInfo->lMaxRange;
  692. pProperty->_lMinRange = pPropertyInfo->lMinRange;
  693. pProperty->_fMultiValued = (VARIANT_BOOL) pPropertyInfo->fMultiValued;
  694. hr = pProperty->InitializeCoreObject(
  695. bstrParent,
  696. pPropertyInfo->szPropertyName,
  697. PROPERTY_CLASS_NAME,
  698. NO_SCHEMA,
  699. CLSID_NWCOMPATProperty,
  700. dwObjectState );
  701. BAIL_ON_FAILURE(hr);
  702. hr = pProperty->QueryInterface( riid, ppvObj );
  703. BAIL_ON_FAILURE(hr);
  704. pProperty->Release();
  705. RRETURN(hr);
  706. error:
  707. delete pProperty;
  708. RRETURN_EXP_IF_ERR(hr);
  709. }
  710. STDMETHODIMP
  711. CNWCOMPATProperty::QueryInterface(REFIID iid, LPVOID FAR* ppv)
  712. {
  713. if (ppv == NULL) {
  714. RRETURN(E_POINTER);
  715. }
  716. if (IsEqualIID(iid, IID_IUnknown))
  717. {
  718. *ppv = (IADsProperty FAR *) this;
  719. }
  720. else if (IsEqualIID(iid, IID_IDispatch))
  721. {
  722. *ppv = (IADs FAR *) this;
  723. }
  724. else if (IsEqualIID(iid, IID_ISupportErrorInfo))
  725. {
  726. *ppv = (ISupportErrorInfo FAR *) this;
  727. }
  728. else if (IsEqualIID(iid, IID_IADs))
  729. {
  730. *ppv = (IADs FAR *) this;
  731. }
  732. else if (IsEqualIID(iid, IID_IADsProperty))
  733. {
  734. *ppv = (IADsProperty FAR *) this;
  735. }
  736. else
  737. {
  738. *ppv = NULL;
  739. return E_NOINTERFACE;
  740. }
  741. AddRef();
  742. return NOERROR;
  743. }
  744. /* ISupportErrorInfo method */
  745. STDMETHODIMP
  746. CNWCOMPATProperty::InterfaceSupportsErrorInfo(
  747. THIS_ REFIID riid
  748. )
  749. {
  750. if (IsEqualIID(riid, IID_IADs) ||
  751. IsEqualIID(riid, IID_IADsProperty)) {
  752. RRETURN(S_OK);
  753. } else {
  754. RRETURN(S_FALSE);
  755. }
  756. }
  757. /* IADs methods */
  758. STDMETHODIMP
  759. CNWCOMPATProperty::SetInfo(THIS)
  760. {
  761. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  762. }
  763. STDMETHODIMP
  764. CNWCOMPATProperty::GetInfo(THIS)
  765. {
  766. RRETURN(S_OK);
  767. }
  768. /* IADsProperty methods */
  769. STDMETHODIMP
  770. CNWCOMPATProperty::get_OID( THIS_ BSTR FAR *pbstrOID )
  771. {
  772. HRESULT hr;
  773. if ( !pbstrOID )
  774. RRETURN_EXP_IF_ERR(E_ADS_BAD_PARAMETER);
  775. hr = ADsAllocString( _bstrOID, pbstrOID );
  776. RRETURN_EXP_IF_ERR(hr);
  777. }
  778. STDMETHODIMP
  779. CNWCOMPATProperty::put_OID( THIS_ BSTR bstrOID )
  780. {
  781. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  782. }
  783. STDMETHODIMP
  784. CNWCOMPATProperty::get_Syntax( THIS_ BSTR FAR *pbstrSyntax )
  785. {
  786. HRESULT hr;
  787. if ( !pbstrSyntax )
  788. RRETURN_EXP_IF_ERR(E_ADS_BAD_PARAMETER);
  789. hr = ADsAllocString( _bstrSyntax, pbstrSyntax );
  790. RRETURN_EXP_IF_ERR(hr);
  791. }
  792. STDMETHODIMP
  793. CNWCOMPATProperty::put_Syntax( THIS_ BSTR bstrSyntax )
  794. {
  795. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  796. }
  797. STDMETHODIMP
  798. CNWCOMPATProperty::get_MaxRange( THIS_ long FAR *plMaxRange )
  799. {
  800. if ( !plMaxRange )
  801. RRETURN_EXP_IF_ERR(E_ADS_BAD_PARAMETER);
  802. *plMaxRange = _lMaxRange;
  803. RRETURN(S_OK);
  804. }
  805. STDMETHODIMP
  806. CNWCOMPATProperty::put_MaxRange( THIS_ long lMaxRange )
  807. {
  808. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  809. }
  810. STDMETHODIMP
  811. CNWCOMPATProperty::get_MinRange( THIS_ long FAR *plMinRange )
  812. {
  813. if ( !plMinRange )
  814. RRETURN_EXP_IF_ERR(E_ADS_BAD_PARAMETER);
  815. *plMinRange = _lMinRange;
  816. RRETURN(S_OK);
  817. }
  818. STDMETHODIMP
  819. CNWCOMPATProperty::put_MinRange( THIS_ long lMinRange )
  820. {
  821. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  822. }
  823. STDMETHODIMP
  824. CNWCOMPATProperty::get_MultiValued( THIS_ VARIANT_BOOL FAR *pfMultiValued )
  825. {
  826. if ( !pfMultiValued )
  827. RRETURN_EXP_IF_ERR(E_ADS_BAD_PARAMETER);
  828. *pfMultiValued = _fMultiValued? VARIANT_TRUE: VARIANT_FALSE;
  829. RRETURN(S_OK);
  830. }
  831. STDMETHODIMP
  832. CNWCOMPATProperty::put_MultiValued( THIS_ VARIANT_BOOL fMultiValued )
  833. {
  834. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  835. }
  836. STDMETHODIMP
  837. CNWCOMPATProperty::Qualifiers(THIS_ IADsCollection FAR* FAR* ppQualifiers)
  838. {
  839. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  840. }
  841. HRESULT
  842. CNWCOMPATProperty::AllocatePropertyObject(CNWCOMPATProperty FAR * FAR * ppProperty)
  843. {
  844. CNWCOMPATProperty FAR *pProperty = NULL;
  845. CAggregatorDispMgr FAR *pDispMgr = NULL;
  846. HRESULT hr = S_OK;
  847. pProperty = new CNWCOMPATProperty();
  848. if ( pProperty == NULL )
  849. hr = E_OUTOFMEMORY;
  850. BAIL_ON_FAILURE(hr);
  851. pDispMgr = new CAggregatorDispMgr;
  852. if ( pDispMgr == NULL )
  853. hr = E_OUTOFMEMORY;
  854. BAIL_ON_FAILURE(hr);
  855. hr = LoadTypeInfoEntry( pDispMgr,
  856. LIBID_ADs,
  857. IID_IADs,
  858. (IADs *) pProperty,
  859. DISPID_REGULAR );
  860. BAIL_ON_FAILURE(hr);
  861. hr = LoadTypeInfoEntry( pDispMgr,
  862. LIBID_ADs,
  863. IID_IADsProperty,
  864. (IADsProperty *) pProperty,
  865. DISPID_REGULAR );
  866. BAIL_ON_FAILURE(hr);
  867. pProperty->_pDispMgr = pDispMgr;
  868. *ppProperty = pProperty;
  869. RRETURN(hr);
  870. error:
  871. delete pDispMgr;
  872. delete pProperty;
  873. RRETURN(hr);
  874. }
  875. /******************************************************************/
  876. /* Class CNWCOMPATSyntax
  877. /******************************************************************/
  878. DEFINE_IDispatch_Implementation(CNWCOMPATSyntax)
  879. DEFINE_IADs_Implementation(CNWCOMPATSyntax)
  880. CNWCOMPATSyntax::CNWCOMPATSyntax()
  881. {
  882. ENLIST_TRACKING(CNWCOMPATSyntax);
  883. }
  884. CNWCOMPATSyntax::~CNWCOMPATSyntax()
  885. {
  886. delete _pDispMgr;
  887. }
  888. HRESULT
  889. CNWCOMPATSyntax::CreateSyntax(
  890. BSTR bstrParent,
  891. SYNTAXINFO *pSyntaxInfo,
  892. DWORD dwObjectState,
  893. REFIID riid,
  894. void **ppvObj
  895. )
  896. {
  897. CNWCOMPATSyntax FAR *pSyntax = NULL;
  898. HRESULT hr = S_OK;
  899. hr = AllocateSyntaxObject( &pSyntax );
  900. BAIL_ON_FAILURE(hr);
  901. hr = pSyntax->InitializeCoreObject(
  902. bstrParent,
  903. pSyntaxInfo->bstrName,
  904. SYNTAX_CLASS_NAME,
  905. NO_SCHEMA,
  906. CLSID_NWCOMPATSyntax,
  907. dwObjectState );
  908. BAIL_ON_FAILURE(hr);
  909. pSyntax->_lOleAutoDataType = pSyntaxInfo->lOleAutoDataType;
  910. hr = pSyntax->QueryInterface( riid, ppvObj );
  911. BAIL_ON_FAILURE(hr);
  912. pSyntax->Release();
  913. RRETURN(hr);
  914. error:
  915. delete pSyntax;
  916. RRETURN_EXP_IF_ERR(hr);
  917. }
  918. STDMETHODIMP
  919. CNWCOMPATSyntax::QueryInterface(REFIID iid, LPVOID FAR* ppv)
  920. {
  921. if (ppv == NULL) {
  922. RRETURN(E_POINTER);
  923. }
  924. if (IsEqualIID(iid, IID_IUnknown))
  925. {
  926. *ppv = (IADs FAR *) this;
  927. }
  928. else if (IsEqualIID(iid, IID_IDispatch))
  929. {
  930. *ppv = (IADs FAR *) this;
  931. }
  932. else if (IsEqualIID(iid, IID_ISupportErrorInfo))
  933. {
  934. *ppv = (ISupportErrorInfo FAR *) this;
  935. }
  936. else if (IsEqualIID(iid, IID_IADs))
  937. {
  938. *ppv = (IADs FAR *) this;
  939. }
  940. else if (IsEqualIID(iid, IID_IADsSyntax))
  941. {
  942. *ppv = (IADsSyntax FAR *) this;
  943. }
  944. else
  945. {
  946. *ppv = NULL;
  947. return E_NOINTERFACE;
  948. }
  949. AddRef();
  950. return NOERROR;
  951. }
  952. /* ISupportErrorInfo method */
  953. STDMETHODIMP
  954. CNWCOMPATSyntax::InterfaceSupportsErrorInfo(
  955. THIS_ REFIID riid
  956. )
  957. {
  958. if (IsEqualIID(riid, IID_IADs) ||
  959. IsEqualIID(riid, IID_IADsSyntax)) {
  960. RRETURN(S_OK);
  961. } else {
  962. RRETURN(S_FALSE);
  963. }
  964. }
  965. /* IADs methods */
  966. STDMETHODIMP
  967. CNWCOMPATSyntax::SetInfo(THIS)
  968. {
  969. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  970. }
  971. STDMETHODIMP
  972. CNWCOMPATSyntax::GetInfo(THIS)
  973. {
  974. RRETURN(S_OK);
  975. }
  976. HRESULT
  977. CNWCOMPATSyntax::AllocateSyntaxObject(CNWCOMPATSyntax FAR * FAR * ppSyntax)
  978. {
  979. CNWCOMPATSyntax FAR *pSyntax = NULL;
  980. CAggregatorDispMgr FAR *pDispMgr = NULL;
  981. HRESULT hr = S_OK;
  982. pSyntax = new CNWCOMPATSyntax();
  983. if ( pSyntax == NULL )
  984. hr = E_OUTOFMEMORY;
  985. BAIL_ON_FAILURE(hr);
  986. pDispMgr = new CAggregatorDispMgr;
  987. if ( pDispMgr == NULL )
  988. hr = E_OUTOFMEMORY;
  989. BAIL_ON_FAILURE(hr);
  990. hr = LoadTypeInfoEntry( pDispMgr,
  991. LIBID_ADs,
  992. IID_IADsSyntax,
  993. (IADsSyntax *) pSyntax,
  994. DISPID_REGULAR );
  995. BAIL_ON_FAILURE(hr);
  996. pSyntax->_pDispMgr = pDispMgr;
  997. *ppSyntax = pSyntax;
  998. RRETURN(hr);
  999. error:
  1000. delete pDispMgr;
  1001. delete pSyntax;
  1002. RRETURN(hr);
  1003. }
  1004. STDMETHODIMP
  1005. CNWCOMPATSyntax::get_OleAutoDataType( THIS_ long FAR *plOleAutoDataType )
  1006. {
  1007. if ( !plOleAutoDataType )
  1008. RRETURN_EXP_IF_ERR(E_ADS_BAD_PARAMETER);
  1009. *plOleAutoDataType = _lOleAutoDataType;
  1010. RRETURN(S_OK);
  1011. }
  1012. STDMETHODIMP
  1013. CNWCOMPATSyntax::put_OleAutoDataType( THIS_ long lOleAutoDataType )
  1014. {
  1015. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  1016. }
  1017. /******************************************************************/
  1018. /* Misc Helpers
  1019. /******************************************************************/
  1020. HRESULT
  1021. MakeVariantFromStringList(
  1022. BSTR bstrList,
  1023. VARIANT *pvVariant
  1024. )
  1025. {
  1026. HRESULT hr = S_OK;
  1027. SAFEARRAY *aList = NULL;
  1028. SAFEARRAYBOUND aBound;
  1029. BSTR pszTempList = NULL;
  1030. if ( bstrList != NULL )
  1031. {
  1032. long i = 0;
  1033. long nCount = 1;
  1034. TCHAR c;
  1035. BSTR pszSrc;
  1036. hr = ADsAllocString( bstrList, &pszTempList );
  1037. BAIL_ON_FAILURE(hr);
  1038. while ( c = pszTempList[i] )
  1039. {
  1040. if ( c == TEXT(','))
  1041. {
  1042. pszTempList[i] = 0;
  1043. nCount++;
  1044. }
  1045. i++;
  1046. }
  1047. aBound.lLbound = 0;
  1048. aBound.cElements = nCount;
  1049. aList = SafeArrayCreate( VT_VARIANT, 1, &aBound );
  1050. if ( aList == NULL )
  1051. {
  1052. hr = E_OUTOFMEMORY;
  1053. BAIL_ON_FAILURE(hr);
  1054. }
  1055. pszSrc = pszTempList;
  1056. for ( i = 0; i < nCount; i++ )
  1057. {
  1058. VARIANT v;
  1059. VariantInit(&v);
  1060. V_VT(&v) = VT_BSTR;
  1061. hr = ADsAllocString( pszSrc, &(V_BSTR(&v)));
  1062. BAIL_ON_FAILURE(hr);
  1063. hr = SafeArrayPutElement( aList,
  1064. &i,
  1065. &v );
  1066. VariantClear(&v);
  1067. BAIL_ON_FAILURE(hr);
  1068. pszSrc += _tcslen( pszSrc ) + 1;
  1069. }
  1070. VariantInit( pvVariant );
  1071. V_VT(pvVariant) = VT_ARRAY | VT_VARIANT;
  1072. V_ARRAY(pvVariant) = aList;
  1073. ADsFreeString( pszTempList );
  1074. pszTempList = NULL;
  1075. }
  1076. else
  1077. {
  1078. aBound.lLbound = 0;
  1079. aBound.cElements = 0;
  1080. aList = SafeArrayCreate( VT_VARIANT, 1, &aBound );
  1081. if ( aList == NULL )
  1082. {
  1083. hr = E_OUTOFMEMORY;
  1084. BAIL_ON_FAILURE(hr);
  1085. }
  1086. VariantInit( pvVariant );
  1087. V_VT(pvVariant) = VT_ARRAY | VT_VARIANT;
  1088. V_ARRAY(pvVariant) = aList;
  1089. }
  1090. RRETURN(S_OK);
  1091. error:
  1092. if ( pszTempList )
  1093. ADsFreeString( pszTempList );
  1094. if ( aList )
  1095. SafeArrayDestroy( aList );
  1096. return hr;
  1097. }
  1098. STDMETHODIMP
  1099. CNWCOMPATClass::get_OptionalProperties( THIS_ VARIANT FAR *retval )
  1100. {
  1101. HRESULT hr;
  1102. VariantInit( retval);
  1103. hr = VariantCopy( retval, &_vOptionalProperties );
  1104. RRETURN_EXP_IF_ERR(hr);
  1105. }
  1106. STDMETHODIMP
  1107. CNWCOMPATClass::put_OptionalProperties( THIS_ VARIANT vOptionalProperties )
  1108. {
  1109. HRESULT hr = E_NOTIMPL;
  1110. RRETURN_EXP_IF_ERR(hr);
  1111. }
  1112. STDMETHODIMP
  1113. CNWCOMPATClass::get_NamingProperties( THIS_ VARIANT FAR *retval )
  1114. {
  1115. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  1116. }
  1117. STDMETHODIMP
  1118. CNWCOMPATClass::put_NamingProperties( THIS_ VARIANT vNamingProperties )
  1119. {
  1120. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  1121. }