Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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