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.

314 lines
6.0 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(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_IADs))
  74. {
  75. *ppv = (IADs FAR *) this;
  76. }
  77. else if (IsEqualIID(iid, IID_IADsSyntax))
  78. {
  79. *ppv = (IADsSyntax FAR *) this;
  80. }
  81. else
  82. {
  83. *ppv = NULL;
  84. return E_NOINTERFACE;
  85. }
  86. AddRef();
  87. return NOERROR;
  88. }
  89. /* IADs methods */
  90. STDMETHODIMP
  91. CNDSSyntax::SetInfo(THIS)
  92. {
  93. RRETURN(E_NOTIMPL);
  94. }
  95. STDMETHODIMP
  96. CNDSSyntax::GetInfo(THIS)
  97. {
  98. RRETURN(S_OK);
  99. }
  100. STDMETHODIMP
  101. CNDSSyntax::GetInfoEx(THIS_ VARIANT vProperties, long lnReserved)
  102. {
  103. RRETURN(E_NOTIMPL);
  104. }
  105. STDMETHODIMP
  106. CNDSSyntax::Get(THIS_ BSTR bstrName, VARIANT FAR* pvProp)
  107. {
  108. RRETURN(E_NOTIMPL);
  109. }
  110. STDMETHODIMP
  111. CNDSSyntax::Put(THIS_ BSTR bstrName, VARIANT vProp)
  112. {
  113. RRETURN(E_NOTIMPL);
  114. }
  115. STDMETHODIMP
  116. CNDSSyntax::GetEx(THIS_ BSTR bstrName, VARIANT FAR* pvProp)
  117. {
  118. RRETURN(E_NOTIMPL);
  119. }
  120. STDMETHODIMP
  121. CNDSSyntax::PutEx(THIS_ long lnControlCode, BSTR bstrName, VARIANT vProp)
  122. {
  123. RRETURN(E_NOTIMPL);
  124. }
  125. HRESULT
  126. CNDSSyntax::AllocateSyntaxObject(CNDSSyntax FAR * FAR * ppSyntax)
  127. {
  128. CNDSSyntax FAR *pSyntax = NULL;
  129. CDispatchMgr FAR *pDispMgr = NULL;
  130. HRESULT hr = S_OK;
  131. pSyntax = new CNDSSyntax();
  132. if ( pSyntax == NULL )
  133. hr = E_OUTOFMEMORY;
  134. BAIL_ON_FAILURE(hr);
  135. pDispMgr = new CDispatchMgr;
  136. if ( pDispMgr == NULL )
  137. hr = E_OUTOFMEMORY;
  138. BAIL_ON_FAILURE(hr);
  139. hr = LoadTypeInfoEntry( pDispMgr,
  140. LIBID_ADs,
  141. IID_IADsSyntax,
  142. (IADsSyntax *) pSyntax,
  143. DISPID_REGULAR );
  144. BAIL_ON_FAILURE(hr);
  145. pSyntax->_pDispMgr = pDispMgr;
  146. *ppSyntax = pSyntax;
  147. RRETURN(hr);
  148. error:
  149. delete pDispMgr;
  150. delete pSyntax;
  151. RRETURN(hr);
  152. }
  153. STDMETHODIMP
  154. CNDSSyntax::get_OleAutoDataType( THIS_ long FAR *plOleAutoDataType )
  155. {
  156. if ( !plOleAutoDataType )
  157. RRETURN(E_ADS_BAD_PARAMETER);
  158. *plOleAutoDataType = _lOleAutoDataType;
  159. RRETURN(S_OK);
  160. }
  161. STDMETHODIMP
  162. CNDSSyntax::put_OleAutoDataType( THIS_ long lOleAutoDataType )
  163. {
  164. RRETURN(E_ADS_PROPERTY_NOT_SUPPORTED);
  165. }
  166. /******************************************************************/
  167. /* Misc Helpers
  168. /******************************************************************/
  169. HRESULT
  170. MakeVariantFromStringList(
  171. BSTR bstrList,
  172. VARIANT *pvVariant
  173. )
  174. {
  175. HRESULT hr = S_OK;
  176. SAFEARRAY *aList = NULL;
  177. SAFEARRAYBOUND aBound;
  178. BSTR pszTempList = NULL;
  179. if ( (bstrList != NULL) && (*bstrList != 0) )
  180. {
  181. long i = 0;
  182. long nCount = 1;
  183. TCHAR c;
  184. BSTR pszSrc;
  185. hr = ADsAllocString( bstrList, &pszTempList );
  186. BAIL_ON_FAILURE(hr);
  187. while ( c = pszTempList[i] )
  188. {
  189. if ( c == TEXT(','))
  190. {
  191. pszTempList[i] = 0;
  192. nCount++;
  193. }
  194. i++;
  195. }
  196. aBound.lLbound = 0;
  197. aBound.cElements = nCount;
  198. aList = SafeArrayCreate( VT_VARIANT, 1, &aBound );
  199. if ( aList == NULL )
  200. {
  201. hr = E_OUTOFMEMORY;
  202. BAIL_ON_FAILURE(hr);
  203. }
  204. pszSrc = pszTempList;
  205. for ( i = 0; i < nCount; i++ )
  206. {
  207. VARIANT v;
  208. VariantInit(&v);
  209. V_VT(&v) = VT_BSTR;
  210. hr = ADsAllocString( pszSrc, &(V_BSTR(&v)));
  211. BAIL_ON_FAILURE(hr);
  212. hr = SafeArrayPutElement( aList,
  213. &i,
  214. &v );
  215. VariantClear(&v);
  216. BAIL_ON_FAILURE(hr);
  217. pszSrc += _tcslen( pszSrc ) + 1;
  218. }
  219. VariantInit( pvVariant );
  220. V_VT(pvVariant) = VT_ARRAY | VT_VARIANT;
  221. V_ARRAY(pvVariant) = aList;
  222. ADsFreeString( pszTempList );
  223. pszTempList = NULL;
  224. }
  225. else
  226. {
  227. aBound.lLbound = 0;
  228. aBound.cElements = 0;
  229. aList = SafeArrayCreate( VT_VARIANT, 1, &aBound );
  230. if ( aList == NULL )
  231. {
  232. hr = E_OUTOFMEMORY;
  233. BAIL_ON_FAILURE(hr);
  234. }
  235. VariantInit( pvVariant );
  236. V_VT(pvVariant) = VT_ARRAY | VT_VARIANT;
  237. V_ARRAY(pvVariant) = aList;
  238. }
  239. return S_OK;
  240. error:
  241. if ( pszTempList )
  242. ADsFreeString( pszTempList );
  243. if ( aList )
  244. SafeArrayDestroy( aList );
  245. return hr;
  246. }