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.

229 lines
4.3 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1999
  5. //
  6. // File: CDNWithString.cxx
  7. //
  8. // Contents: DNWithString object
  9. //
  10. // History: 4-23-99 AjayR Created.
  11. //
  12. //----------------------------------------------------------------------------
  13. #include "oleds.hxx"
  14. #pragma hdrstop
  15. // Class CDNWithString
  16. DEFINE_IDispatch_Implementation(CDNWithString)
  17. CDNWithString::CDNWithString():
  18. _pszStrVal(NULL),
  19. _pszDNStr(NULL)
  20. {
  21. ENLIST_TRACKING(CDNWithString);
  22. }
  23. HRESULT
  24. CDNWithString::CreateDNWithString(
  25. REFIID riid,
  26. void **ppvObj
  27. )
  28. {
  29. CDNWithString FAR * pDNWithString = NULL;
  30. HRESULT hr = S_OK;
  31. hr = AllocateDNWithStringObject(&pDNWithString);
  32. BAIL_ON_FAILURE(hr);
  33. hr = pDNWithString->QueryInterface(riid, ppvObj);
  34. BAIL_ON_FAILURE(hr);
  35. pDNWithString->Release();
  36. RRETURN(hr);
  37. error:
  38. delete pDNWithString;
  39. RRETURN_EXP_IF_ERR(hr);
  40. }
  41. CDNWithString::~CDNWithString( )
  42. {
  43. delete _pDispMgr;
  44. if (_pszStrVal) {
  45. FreeADsStr(_pszStrVal);
  46. }
  47. if (_pszDNStr) {
  48. FreeADsStr(_pszDNStr);
  49. }
  50. }
  51. STDMETHODIMP
  52. CDNWithString::QueryInterface(
  53. REFIID iid,
  54. LPVOID FAR* ppv
  55. )
  56. {
  57. if (IsEqualIID(iid, IID_IUnknown))
  58. {
  59. *ppv = (IADsDNWithString FAR *) this;
  60. }
  61. else if (IsEqualIID(iid, IID_IADsDNWithString))
  62. {
  63. *ppv = (IADsDNWithString FAR *) this;
  64. }
  65. else if (IsEqualIID(iid, IID_IDispatch))
  66. {
  67. *ppv = (IADsDNWithString FAR *) this;
  68. }
  69. else if (IsEqualIID(iid, IID_ISupportErrorInfo))
  70. {
  71. *ppv = (ISupportErrorInfo FAR *) this;
  72. }
  73. else
  74. {
  75. *ppv = NULL;
  76. return E_NOINTERFACE;
  77. }
  78. AddRef();
  79. return NOERROR;
  80. }
  81. HRESULT
  82. CDNWithString::AllocateDNWithStringObject(
  83. CDNWithString ** ppDNWithString
  84. )
  85. {
  86. CDNWithString FAR * pDNWithString = NULL;
  87. CDispatchMgr FAR * pDispMgr = NULL;
  88. HRESULT hr = S_OK;
  89. pDNWithString = new CDNWithString();
  90. if (pDNWithString == NULL) {
  91. hr = E_OUTOFMEMORY;
  92. }
  93. BAIL_ON_FAILURE(hr);
  94. pDispMgr = new CDispatchMgr;
  95. if (pDispMgr == NULL) {
  96. hr = E_OUTOFMEMORY;
  97. }
  98. BAIL_ON_FAILURE(hr);
  99. hr = LoadTypeInfoEntry(
  100. pDispMgr,
  101. LIBID_ADs,
  102. IID_IADsDNWithString,
  103. (IADsDNWithString *)pDNWithString,
  104. DISPID_REGULAR
  105. );
  106. BAIL_ON_FAILURE(hr);
  107. pDNWithString->_pDispMgr = pDispMgr;
  108. *ppDNWithString = pDNWithString;
  109. RRETURN(hr);
  110. error:
  111. delete pDNWithString;
  112. delete pDispMgr;
  113. RRETURN_EXP_IF_ERR(hr);
  114. }
  115. STDMETHODIMP
  116. CDNWithString::InterfaceSupportsErrorInfo(THIS_ REFIID riid)
  117. {
  118. if (IsEqualIID(riid, IID_IADsDNWithString)) {
  119. return S_OK;
  120. } else {
  121. return S_FALSE;
  122. }
  123. }
  124. //
  125. // Methods to get and put the string part.
  126. //
  127. STDMETHODIMP
  128. CDNWithString::get_StringValue(THIS_ BSTR FAR* pbstrValue)
  129. {
  130. HRESULT hr = S_OK;
  131. if (FAILED(hr = ValidateOutParameter(pbstrValue))){
  132. RRETURN_EXP_IF_ERR(hr);
  133. }
  134. hr = ADsAllocString(_pszStrVal, pbstrValue);
  135. RRETURN_EXP_IF_ERR(hr);
  136. }
  137. STDMETHODIMP
  138. CDNWithString::put_StringValue(THIS_ BSTR bstrValue)
  139. {
  140. HRESULT hr = S_OK;
  141. if (_pszStrVal) {
  142. FreeADsStr(_pszStrVal);
  143. _pszStrVal = NULL;
  144. }
  145. _pszStrVal = AllocADsStr(bstrValue);
  146. if (bstrValue && !_pszStrVal) {
  147. hr = E_OUTOFMEMORY;
  148. }
  149. RRETURN(hr);
  150. }
  151. //
  152. // Methods to get and put the DN string.
  153. //
  154. STDMETHODIMP
  155. CDNWithString::get_DNString(THIS_ BSTR FAR* pbstrDNString)
  156. {
  157. HRESULT hr = S_OK;
  158. if (FAILED(hr = ValidateOutParameter(pbstrDNString))){
  159. RRETURN_EXP_IF_ERR(hr);
  160. }
  161. hr = ADsAllocString(_pszDNStr, pbstrDNString);
  162. RRETURN_EXP_IF_ERR(hr);
  163. }
  164. STDMETHODIMP
  165. CDNWithString::put_DNString(THIS_ BSTR bstrDNString)
  166. {
  167. HRESULT hr = S_OK;
  168. if (_pszDNStr) {
  169. FreeADsStr(_pszDNStr);
  170. _pszDNStr = NULL;
  171. }
  172. _pszDNStr = AllocADsStr(bstrDNString);
  173. if (bstrDNString && !_pszDNStr) {
  174. hr = E_OUTOFMEMORY;
  175. }
  176. RRETURN(hr);
  177. }