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.

281 lines
4.9 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995
  5. //
  6. // File: cPropertyEntry.cxx
  7. //
  8. // Contents: PropertyEntry object
  9. //
  10. // History: 11-1-95 krishnag Created.
  11. //
  12. //----------------------------------------------------------------------------
  13. #include "oleds.hxx"
  14. #pragma hdrstop
  15. // Class CPropertyEntry
  16. DEFINE_IDispatch_Implementation(CPropertyEntry)
  17. CPropertyEntry::CPropertyEntry():
  18. _pDispMgr(NULL),
  19. _lpName(NULL),
  20. _dwValueCount(0),
  21. _dwADsType(0),
  22. _dwControlCode(0)
  23. {
  24. ENLIST_TRACKING(CPropertyEntry);
  25. }
  26. HRESULT
  27. CPropertyEntry::CreatePropertyEntry(
  28. REFIID riid,
  29. void **ppvObj
  30. )
  31. {
  32. CPropertyEntry FAR * pPropertyEntry = NULL;
  33. HRESULT hr = S_OK;
  34. hr = AllocatePropertyEntryObject(&pPropertyEntry);
  35. BAIL_ON_FAILURE(hr);
  36. hr = pPropertyEntry->QueryInterface(riid, ppvObj);
  37. BAIL_ON_FAILURE(hr);
  38. pPropertyEntry->Release();
  39. RRETURN(hr);
  40. error:
  41. delete pPropertyEntry;
  42. RRETURN_EXP_IF_ERR(hr);
  43. }
  44. CPropertyEntry::~CPropertyEntry( )
  45. {
  46. VariantClear(&_propVar);
  47. if (_lpName) {
  48. FreeADsStr(_lpName);
  49. }
  50. delete _pDispMgr;
  51. }
  52. STDMETHODIMP
  53. CPropertyEntry::QueryInterface(
  54. REFIID iid,
  55. LPVOID FAR* ppv
  56. )
  57. {
  58. if (IsEqualIID(iid, IID_IUnknown))
  59. {
  60. *ppv = (IADsPropertyEntry FAR *) this;
  61. }
  62. else if (IsEqualIID(iid, IID_IADsPropertyEntry))
  63. {
  64. *ppv = (IADsPropertyEntry FAR *) this;
  65. }
  66. else if (IsEqualIID(iid, IID_IDispatch))
  67. {
  68. *ppv = (IADsPropertyEntry FAR *) this;
  69. }
  70. else if (IsEqualIID(iid, IID_ISupportErrorInfo))
  71. {
  72. *ppv = (ISupportErrorInfo FAR *) this;
  73. }
  74. else
  75. {
  76. *ppv = NULL;
  77. return E_NOINTERFACE;
  78. }
  79. AddRef();
  80. return NOERROR;
  81. }
  82. HRESULT
  83. CPropertyEntry::AllocatePropertyEntryObject(
  84. CPropertyEntry ** ppPropertyEntry
  85. )
  86. {
  87. CPropertyEntry FAR * pPropertyEntry = NULL;
  88. CDispatchMgr FAR * pDispMgr = NULL;
  89. HRESULT hr = S_OK;
  90. pPropertyEntry = new CPropertyEntry();
  91. if (pPropertyEntry == NULL) {
  92. hr = E_OUTOFMEMORY;
  93. }
  94. BAIL_ON_FAILURE(hr);
  95. pDispMgr = new CDispatchMgr;
  96. if (pDispMgr == NULL) {
  97. hr = E_OUTOFMEMORY;
  98. }
  99. BAIL_ON_FAILURE(hr);
  100. hr = LoadTypeInfoEntry(
  101. pDispMgr,
  102. LIBID_ADs,
  103. IID_IADsPropertyEntry,
  104. (IADsPropertyEntry *)pPropertyEntry,
  105. DISPID_REGULAR
  106. );
  107. BAIL_ON_FAILURE(hr);
  108. pPropertyEntry->_pDispMgr = pDispMgr;
  109. *ppPropertyEntry = pPropertyEntry;
  110. RRETURN(hr);
  111. error:
  112. delete pDispMgr;
  113. RRETURN_EXP_IF_ERR(hr);
  114. }
  115. //
  116. // ISupportErrorInfo method
  117. //
  118. STDMETHODIMP
  119. CPropertyEntry::InterfaceSupportsErrorInfo(THIS_ REFIID riid)
  120. {
  121. if (IsEqualIID(riid, IID_IADsPropertyEntry)) {
  122. return S_OK;
  123. } else {
  124. return S_FALSE;
  125. }
  126. }
  127. STDMETHODIMP
  128. CPropertyEntry::get_Values(THIS_ VARIANT FAR * retval)
  129. {
  130. HRESULT hr;
  131. VariantInit(retval);
  132. hr = VariantCopy(retval, &_propVar);
  133. RRETURN_EXP_IF_ERR(hr);
  134. }
  135. STDMETHODIMP
  136. CPropertyEntry::put_Values(THIS_ VARIANT vValues)
  137. {
  138. HRESULT hr;
  139. // set the values only if it is valid
  140. if ( (V_VT(&vValues) == (VT_ARRAY | VT_VARIANT))
  141. || (V_VT(&vValues) == (VT_EMPTY))) {
  142. hr = VariantCopy(&_propVar, &vValues);
  143. RRETURN_EXP_IF_ERR(hr);
  144. } else {
  145. RRETURN(hr=E_ADS_BAD_PARAMETER);
  146. }
  147. }
  148. STDMETHODIMP
  149. CPropertyEntry::get_ValueCount(THIS_ long FAR * retval)
  150. {
  151. *retval = _dwValueCount;
  152. RRETURN(S_OK);
  153. }
  154. STDMETHODIMP
  155. CPropertyEntry::put_ValueCount(THIS_ long lnValueCount)
  156. {
  157. _dwValueCount = lnValueCount;
  158. RRETURN(S_OK);
  159. }
  160. STDMETHODIMP
  161. CPropertyEntry::get_ADsType(THIS_ long FAR * retval)
  162. {
  163. *retval = _dwADsType;
  164. RRETURN(S_OK);
  165. }
  166. STDMETHODIMP
  167. CPropertyEntry::put_ADsType(THIS_ long lnADsType)
  168. {
  169. _dwADsType = lnADsType;
  170. RRETURN(S_OK);
  171. }
  172. STDMETHODIMP
  173. CPropertyEntry::get_ControlCode(THIS_ long FAR * retval)
  174. {
  175. *retval = _dwControlCode;
  176. RRETURN(S_OK);
  177. }
  178. STDMETHODIMP
  179. CPropertyEntry::put_ControlCode(THIS_ long lnControlCode)
  180. {
  181. _dwControlCode = lnControlCode;
  182. RRETURN(S_OK);
  183. }
  184. STDMETHODIMP
  185. CPropertyEntry::get_Name(THIS_ BSTR FAR * retval)
  186. {
  187. HRESULT hr = S_OK;
  188. hr = ADsAllocString(_lpName, retval);
  189. RRETURN_EXP_IF_ERR(hr);
  190. }
  191. STDMETHODIMP
  192. CPropertyEntry::put_Name(THIS_ BSTR bstrName)
  193. {
  194. if (!bstrName) {
  195. RRETURN_EXP_IF_ERR(E_ADS_BAD_PARAMETER);
  196. }
  197. if (_lpName) {
  198. FreeADsStr(_lpName);
  199. }
  200. _lpName = AllocADsStr(bstrName);
  201. if (!_lpName) {
  202. RRETURN_EXP_IF_ERR(E_OUTOFMEMORY);
  203. }
  204. RRETURN(S_OK);
  205. }
  206. STDMETHODIMP
  207. CPropertyEntry::Clear(THIS_ )
  208. {
  209. _dwADsType = 0;
  210. _dwControlCode = 0;
  211. _dwValueCount = 0;
  212. VariantClear(&_propVar);
  213. if (_lpName) {
  214. FreeADsStr(_lpName);
  215. _lpName = NULL;
  216. }
  217. RRETURN(S_OK);
  218. }
  219.