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.

330 lines
6.8 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1996
  5. //
  6. // File: cschema.cxx
  7. //
  8. // Contents: NDS
  9. //
  10. //
  11. // History: 01-09-96 yihsins Created.
  12. //
  13. //----------------------------------------------------------------------------
  14. #include "nds.hxx"
  15. #pragma hdrstop
  16. /******************************************************************/
  17. /* Class CNDSSyntax
  18. /******************************************************************/
  19. DEFINE_IDispatch_Implementation(CNDSSyntax)
  20. DEFINE_IADs_Implementation(CNDSSyntax)
  21. CNDSSyntax::CNDSSyntax()
  22. {
  23. ENLIST_TRACKING(CNDSSyntax);
  24. }
  25. CNDSSyntax::~CNDSSyntax()
  26. {
  27. delete _pDispMgr;
  28. }
  29. HRESULT
  30. CNDSSyntax::CreateSyntax(
  31. BSTR bstrParent,
  32. SYNTAXINFO *pSyntaxInfo,
  33. DWORD dwObjectState,
  34. REFIID riid,
  35. void **ppvObj
  36. )
  37. {
  38. CNDSSyntax FAR *pSyntax = NULL;
  39. HRESULT hr = S_OK;
  40. hr = AllocateSyntaxObject( &pSyntax );
  41. BAIL_ON_FAILURE(hr);
  42. hr = pSyntax->InitializeCoreObject(
  43. bstrParent,
  44. pSyntaxInfo->bstrName,
  45. SYNTAX_CLASS_NAME,
  46. NO_SCHEMA,
  47. CLSID_NDSSyntax,
  48. dwObjectState );
  49. BAIL_ON_FAILURE(hr);
  50. pSyntax->_lOleAutoDataType = pSyntaxInfo->lOleAutoDataType;
  51. hr = pSyntax->QueryInterface( riid, ppvObj );
  52. BAIL_ON_FAILURE(hr);
  53. pSyntax->Release();
  54. RRETURN(hr);
  55. error:
  56. delete pSyntax;
  57. RRETURN_EXP_IF_ERR(hr);
  58. }
  59. STDMETHODIMP
  60. CNDSSyntax::QueryInterface(REFIID iid, LPVOID FAR* ppv)
  61. {
  62. if (ppv == NULL) {
  63. RRETURN(E_POINTER);
  64. }
  65. if (IsEqualIID(iid, IID_IUnknown))
  66. {
  67. *ppv = (IADs FAR *) this;
  68. }
  69. else if (IsEqualIID(iid, IID_IDispatch))
  70. {
  71. *ppv = (IADs FAR *) this;
  72. }
  73. else if (IsEqualIID(iid, IID_ISupportErrorInfo))
  74. {
  75. *ppv = (ISupportErrorInfo FAR *) this;
  76. }
  77. else if (IsEqualIID(iid, IID_IADs))
  78. {
  79. *ppv = (IADs FAR *) this;
  80. }
  81. else if (IsEqualIID(iid, IID_IADsSyntax))
  82. {
  83. *ppv = (IADsSyntax FAR *) this;
  84. }
  85. else
  86. {
  87. *ppv = NULL;
  88. return E_NOINTERFACE;
  89. }
  90. AddRef();
  91. return NOERROR;
  92. }
  93. /* ISupportErrorInfo method */
  94. STDMETHODIMP
  95. CNDSSyntax::InterfaceSupportsErrorInfo(
  96. THIS_ REFIID riid
  97. )
  98. {
  99. if (IsEqualIID(riid, IID_IADs) ||
  100. IsEqualIID(riid, IID_IADsSyntax)) {
  101. RRETURN(S_OK);
  102. } else {
  103. RRETURN(S_FALSE);
  104. }
  105. }
  106. /* IADs methods */
  107. STDMETHODIMP
  108. CNDSSyntax::SetInfo(THIS)
  109. {
  110. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  111. }
  112. STDMETHODIMP
  113. CNDSSyntax::GetInfo(THIS)
  114. {
  115. RRETURN(S_OK);
  116. }
  117. STDMETHODIMP
  118. CNDSSyntax::GetInfoEx(THIS_ VARIANT vProperties, long lnReserved)
  119. {
  120. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  121. }
  122. STDMETHODIMP
  123. CNDSSyntax::Get(THIS_ BSTR bstrName, VARIANT FAR* pvProp)
  124. {
  125. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  126. }
  127. STDMETHODIMP
  128. CNDSSyntax::Put(THIS_ BSTR bstrName, VARIANT vProp)
  129. {
  130. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  131. }
  132. STDMETHODIMP
  133. CNDSSyntax::GetEx(THIS_ BSTR bstrName, VARIANT FAR* pvProp)
  134. {
  135. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  136. }
  137. STDMETHODIMP
  138. CNDSSyntax::PutEx(THIS_ long lnControlCode, BSTR bstrName, VARIANT vProp)
  139. {
  140. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  141. }
  142. HRESULT
  143. CNDSSyntax::AllocateSyntaxObject(CNDSSyntax FAR * FAR * ppSyntax)
  144. {
  145. CNDSSyntax FAR *pSyntax = NULL;
  146. CDispatchMgr FAR *pDispMgr = NULL;
  147. HRESULT hr = S_OK;
  148. pSyntax = new CNDSSyntax();
  149. if ( pSyntax == NULL )
  150. hr = E_OUTOFMEMORY;
  151. BAIL_ON_FAILURE(hr);
  152. pDispMgr = new CDispatchMgr;
  153. if ( pDispMgr == NULL )
  154. hr = E_OUTOFMEMORY;
  155. BAIL_ON_FAILURE(hr);
  156. hr = LoadTypeInfoEntry( pDispMgr,
  157. LIBID_ADs,
  158. IID_IADsSyntax,
  159. (IADsSyntax *) pSyntax,
  160. DISPID_REGULAR );
  161. BAIL_ON_FAILURE(hr);
  162. pSyntax->_pDispMgr = pDispMgr;
  163. *ppSyntax = pSyntax;
  164. RRETURN(hr);
  165. error:
  166. delete pDispMgr;
  167. delete pSyntax;
  168. RRETURN(hr);
  169. }
  170. STDMETHODIMP
  171. CNDSSyntax::get_OleAutoDataType( THIS_ long FAR *plOleAutoDataType )
  172. {
  173. if ( !plOleAutoDataType )
  174. RRETURN_EXP_IF_ERR(E_ADS_BAD_PARAMETER);
  175. *plOleAutoDataType = _lOleAutoDataType;
  176. RRETURN(S_OK);
  177. }
  178. STDMETHODIMP
  179. CNDSSyntax::put_OleAutoDataType( THIS_ long lOleAutoDataType )
  180. {
  181. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  182. }
  183. /******************************************************************/
  184. /* Misc Helpers
  185. /******************************************************************/
  186. HRESULT
  187. MakeVariantFromStringList(
  188. BSTR bstrList,
  189. VARIANT *pvVariant
  190. )
  191. {
  192. HRESULT hr = S_OK;
  193. SAFEARRAY *aList = NULL;
  194. SAFEARRAYBOUND aBound;
  195. BSTR pszTempList = NULL;
  196. if ( (bstrList != NULL) && (*bstrList != 0) )
  197. {
  198. long i = 0;
  199. long nCount = 1;
  200. TCHAR c;
  201. BSTR pszSrc;
  202. hr = ADsAllocString( bstrList, &pszTempList );
  203. BAIL_ON_FAILURE(hr);
  204. while ( c = pszTempList[i] )
  205. {
  206. if ( c == TEXT(','))
  207. {
  208. pszTempList[i] = 0;
  209. nCount++;
  210. }
  211. i++;
  212. }
  213. aBound.lLbound = 0;
  214. aBound.cElements = nCount;
  215. aList = SafeArrayCreate( VT_VARIANT, 1, &aBound );
  216. if ( aList == NULL )
  217. {
  218. hr = E_OUTOFMEMORY;
  219. BAIL_ON_FAILURE(hr);
  220. }
  221. pszSrc = pszTempList;
  222. for ( i = 0; i < nCount; i++ )
  223. {
  224. VARIANT v;
  225. VariantInit(&v);
  226. V_VT(&v) = VT_BSTR;
  227. hr = ADsAllocString( pszSrc, &(V_BSTR(&v)));
  228. BAIL_ON_FAILURE(hr);
  229. hr = SafeArrayPutElement( aList,
  230. &i,
  231. &v );
  232. VariantClear(&v);
  233. BAIL_ON_FAILURE(hr);
  234. pszSrc += _tcslen( pszSrc ) + 1;
  235. }
  236. VariantInit( pvVariant );
  237. V_VT(pvVariant) = VT_ARRAY | VT_VARIANT;
  238. V_ARRAY(pvVariant) = aList;
  239. ADsFreeString( pszTempList );
  240. pszTempList = NULL;
  241. }
  242. else
  243. {
  244. aBound.lLbound = 0;
  245. aBound.cElements = 0;
  246. aList = SafeArrayCreate( VT_VARIANT, 1, &aBound );
  247. if ( aList == NULL )
  248. {
  249. hr = E_OUTOFMEMORY;
  250. BAIL_ON_FAILURE(hr);
  251. }
  252. VariantInit( pvVariant );
  253. V_VT(pvVariant) = VT_ARRAY | VT_VARIANT;
  254. V_ARRAY(pvVariant) = aList;
  255. }
  256. RRETURN(S_OK);
  257. error:
  258. if ( pszTempList )
  259. ADsFreeString( pszTempList );
  260. if ( aList )
  261. SafeArrayDestroy( aList );
  262. return hr;
  263. }