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.

252 lines
5.2 KiB

  1. //
  2. // Copyright 1997-199 - Microsoft Corporation
  3. //
  4. //
  5. // QUERYPB.CPP - Property Bag for sending arguments to the DSFind Query Form
  6. //
  7. #include "pch.h"
  8. #include "querypb.h"
  9. DEFINE_MODULE("IMADMUI")
  10. DEFINE_THISCLASS("QueryPropertyBag")
  11. #define THISCLASS QueryPropertyBag
  12. #define LPTHISCLASS LPQUERYPROPERTYBAG
  13. //
  14. // QueryPropertyBag_CreateInstance( )
  15. //
  16. LPVOID
  17. QueryPropertyBag_CreateInstance( void )
  18. {
  19. TraceFunc( "QueryPropertyBag_CreateInstance()\n" );
  20. LPTHISCLASS lpcc = new THISCLASS( );
  21. if ( !lpcc ) {
  22. RETURN(lpcc);
  23. }
  24. HRESULT hr = THR( lpcc->Init( ) );
  25. if ( FAILED(hr) ) {
  26. delete lpcc;
  27. RETURN(NULL);
  28. }
  29. RETURN(lpcc);
  30. }
  31. //
  32. // Constructor
  33. //
  34. THISCLASS::THISCLASS( )
  35. {
  36. TraceClsFunc( "QueryPropertyBag( )\n" );
  37. InterlockIncrement( g_cObjects );
  38. _pszServerName = NULL;
  39. _pszClientGuid = NULL;
  40. TraceFuncExit();
  41. }
  42. //
  43. // Init( )
  44. //
  45. HRESULT
  46. THISCLASS::Init( )
  47. {
  48. TraceClsFunc( "Init( )\n" );
  49. HRESULT hr = S_OK;
  50. // IUnknown stuff
  51. BEGIN_QITABLE_IMP( QueryPropertyBag, IPropertyBag );
  52. QITABLE_IMP( IPropertyBag );
  53. END_QITABLE_IMP( QueryPropertyBag );
  54. Assert( _cRef == 0);
  55. AddRef( );
  56. Assert( !_pszServerName );
  57. Assert( !_pszClientGuid );
  58. HRETURN(hr);
  59. }
  60. //
  61. // Destructor
  62. //
  63. THISCLASS::~THISCLASS( )
  64. {
  65. TraceClsFunc( "~QueryPropertyBag( )\n" );
  66. if ( _pszServerName )
  67. TraceFree( _pszServerName );
  68. if ( _pszClientGuid )
  69. TraceFree( _pszClientGuid );
  70. InterlockDecrement( g_cObjects );
  71. TraceFuncExit();
  72. }
  73. // ************************************************************************
  74. //
  75. // IUnknown
  76. //
  77. // ************************************************************************
  78. //
  79. // QueryInterface()
  80. //
  81. STDMETHODIMP
  82. THISCLASS::QueryInterface(
  83. REFIID riid,
  84. LPVOID *ppv )
  85. {
  86. TraceClsFunc( "" );
  87. HRESULT hr = ::QueryInterface( this, _QITable, riid, ppv );
  88. QIRETURN( hr, riid );
  89. }
  90. //
  91. // AddRef()
  92. //
  93. STDMETHODIMP_(ULONG)
  94. THISCLASS::AddRef( void )
  95. {
  96. TraceClsFunc( "[IUnknown] AddRef( )\n" );
  97. InterlockIncrement( _cRef );
  98. RETURN(_cRef);
  99. }
  100. //
  101. // Release()
  102. //
  103. STDMETHODIMP_(ULONG)
  104. THISCLASS::Release( void )
  105. {
  106. TraceClsFunc( "[IUnknown] Release( )\n" );
  107. InterlockDecrement( _cRef );
  108. if ( _cRef )
  109. RETURN(_cRef);
  110. TraceDo( delete this );
  111. RETURN(0);
  112. }
  113. // ************************************************************************
  114. //
  115. // IQueryForm
  116. //
  117. // ************************************************************************
  118. STDMETHODIMP
  119. THISCLASS::Read(
  120. LPCOLESTR pszPropName,
  121. VARIANT *pVar,
  122. IErrorLog *pErrorLog )
  123. {
  124. TraceClsFunc("Read( )\n" );
  125. HRESULT hr;
  126. if ( !pszPropName || !pVar ) {
  127. HRETURN(E_POINTER);
  128. }
  129. if ( V_VT( pVar ) != VT_EMPTY ) {
  130. HRETURN(OLE_E_CANTCONVERT);
  131. }
  132. if ( _wcsicmp( pszPropName, L"ServerName" ) == 0 ) {
  133. if ( !_pszServerName ) {
  134. hr = HRESULT_FROM_WIN32( ERROR_NOT_FOUND );
  135. } else {
  136. BSTR tmp = SysAllocString( _pszServerName );
  137. if (!tmp) {
  138. hr = E_OUTOFMEMORY;
  139. } else {
  140. V_VT( pVar ) = VT_BSTR;
  141. V_BSTR( pVar ) = tmp;
  142. hr = S_OK;
  143. }
  144. }
  145. } else if ( _wcsicmp( pszPropName, L"ClientGuid" ) == 0 ) {
  146. if ( !_pszClientGuid ) {
  147. hr = HRESULT_FROM_WIN32( ERROR_NOT_FOUND );
  148. } else {
  149. BSTR tmp = SysAllocString( _pszClientGuid );
  150. if (!tmp) {
  151. hr = E_OUTOFMEMORY;
  152. } else {
  153. V_VT( pVar ) = VT_BSTR;
  154. V_BSTR( pVar ) = tmp;
  155. hr = S_OK;
  156. }
  157. }
  158. } else { // something unexpected came in
  159. hr = THR(E_INVALIDARG);
  160. }
  161. HRETURN(hr);
  162. }
  163. STDMETHODIMP
  164. THISCLASS::Write(
  165. LPCOLESTR pszPropName,
  166. VARIANT *pVar )
  167. {
  168. TraceClsFunc("Write( )\n" );
  169. HRESULT hr;
  170. if ( !pszPropName || !pVar ) {
  171. HRETURN(E_POINTER);
  172. }
  173. if ( V_VT( pVar ) != VT_BSTR ) {
  174. HRETURN(OLE_E_CANTCONVERT);
  175. }
  176. if ( _wcsicmp( pszPropName, L"ServerName" ) == 0 ) {
  177. PWSTR tmp = TraceStrDup( V_BSTR( pVar ) );
  178. if (tmp) {
  179. if ( _pszServerName ) {
  180. TraceFree( _pszServerName );
  181. _pszServerName = NULL;
  182. }
  183. _pszServerName = tmp;
  184. hr = S_OK;
  185. } else {
  186. hr = E_OUTOFMEMORY;
  187. }
  188. } else if ( _wcsicmp( pszPropName, L"ClientGuid" ) == 0 ) {
  189. PWSTR tmp = TraceStrDup( V_BSTR( pVar ) );
  190. if (tmp) {
  191. if ( _pszClientGuid ) {
  192. TraceFree( _pszClientGuid );
  193. _pszClientGuid = NULL;
  194. }
  195. _pszClientGuid = tmp;
  196. hr = S_OK;
  197. } else {
  198. hr = E_OUTOFMEMORY;
  199. }
  200. } else { // something unexpected came in
  201. hr = THR(E_INVALIDARG);
  202. }
  203. HRETURN(hr);
  204. }