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.

257 lines
4.5 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 ( hr )
  26. {
  27. delete lpcc;
  28. RETURN(NULL);
  29. }
  30. RETURN(lpcc);
  31. }
  32. //
  33. // Constructor
  34. //
  35. THISCLASS::THISCLASS( )
  36. {
  37. TraceClsFunc( "QueryPropertyBag( )\n" );
  38. InterlockIncrement( g_cObjects );
  39. TraceFuncExit();
  40. }
  41. //
  42. // Init( )
  43. //
  44. HRESULT
  45. THISCLASS::Init( )
  46. {
  47. TraceClsFunc( "Init( )\n" );
  48. HRESULT hr = S_OK;
  49. // IUnknown stuff
  50. BEGIN_QITABLE_IMP( QueryPropertyBag, IPropertyBag );
  51. QITABLE_IMP( IPropertyBag );
  52. END_QITABLE_IMP( QueryPropertyBag );
  53. Assert( _cRef == 0);
  54. AddRef( );
  55. Assert( !_pszServerName );
  56. Assert( !_pszClientGuid );
  57. HRETURN(hr);
  58. }
  59. //
  60. // Destructor
  61. //
  62. THISCLASS::~THISCLASS( )
  63. {
  64. TraceClsFunc( "~QueryPropertyBag( )\n" );
  65. if ( _pszServerName )
  66. TraceFree( _pszServerName );
  67. if ( _pszClientGuid )
  68. TraceFree( _pszClientGuid );
  69. InterlockDecrement( g_cObjects );
  70. TraceFuncExit();
  71. }
  72. // ************************************************************************
  73. //
  74. // IUnknown
  75. //
  76. // ************************************************************************
  77. //
  78. // QueryInterface()
  79. //
  80. STDMETHODIMP
  81. THISCLASS::QueryInterface(
  82. REFIID riid,
  83. LPVOID *ppv )
  84. {
  85. TraceClsFunc( "" );
  86. HRESULT hr = ::QueryInterface( this, _QITable, riid, ppv );
  87. QIRETURN( hr, riid );
  88. }
  89. //
  90. // AddRef()
  91. //
  92. STDMETHODIMP_(ULONG)
  93. THISCLASS::AddRef( void )
  94. {
  95. TraceClsFunc( "[IUnknown] AddRef( )\n" );
  96. InterlockIncrement( _cRef );
  97. RETURN(_cRef);
  98. }
  99. //
  100. // Release()
  101. //
  102. STDMETHODIMP_(ULONG)
  103. THISCLASS::Release( void )
  104. {
  105. TraceClsFunc( "[IUnknown] Release( )\n" );
  106. InterlockDecrement( _cRef );
  107. if ( _cRef )
  108. RETURN(_cRef);
  109. TraceDo( delete this );
  110. RETURN(0);
  111. }
  112. // ************************************************************************
  113. //
  114. // IQueryForm
  115. //
  116. // ************************************************************************
  117. STDMETHODIMP
  118. THISCLASS::Read(
  119. LPCOLESTR pszPropName,
  120. VARIANT *pVar,
  121. IErrorLog *pErrorLog )
  122. {
  123. TraceClsFunc("Read( )\n" );
  124. HRESULT hr;
  125. if ( !pszPropName || !pVar )
  126. HRETURN(E_POINTER);
  127. if ( V_VT( pVar ) != VT_EMPTY )
  128. HRETURN(OLE_E_CANTCONVERT);
  129. if ( StrCmpI( pszPropName, L"ServerName" ) == 0 )
  130. {
  131. if ( !_pszServerName )
  132. {
  133. hr = HRESULT_FROM_WIN32( ERROR_NOT_FOUND );
  134. }
  135. else
  136. {
  137. V_VT( pVar ) = VT_BSTR;
  138. V_BSTR( pVar ) = SysAllocString( _pszServerName );
  139. hr = S_OK;
  140. }
  141. }
  142. else if ( StrCmpI( pszPropName, L"ClientGuid" ) == 0 )
  143. {
  144. if ( !_pszClientGuid )
  145. {
  146. hr = HRESULT_FROM_WIN32( ERROR_NOT_FOUND );
  147. }
  148. else
  149. {
  150. V_VT( pVar ) = VT_BSTR;
  151. V_BSTR( pVar ) = SysAllocString( _pszClientGuid );
  152. hr = S_OK;
  153. }
  154. }
  155. else
  156. { // something unexpected came in
  157. hr = THR(E_INVALIDARG);
  158. }
  159. HRETURN(hr);
  160. }
  161. STDMETHODIMP
  162. THISCLASS::Write(
  163. LPCOLESTR pszPropName,
  164. VARIANT *pVar )
  165. {
  166. TraceClsFunc("Write( )\n" );
  167. HRESULT hr;
  168. if ( !pszPropName || !pVar )
  169. HRETURN(E_POINTER);
  170. if ( V_VT( pVar ) != VT_BSTR )
  171. HRETURN(OLE_E_CANTCONVERT);
  172. if ( StrCmpI( pszPropName, L"ServerName" ) == 0 )
  173. {
  174. if ( _pszServerName )
  175. {
  176. TraceFree( _pszServerName );
  177. }
  178. _pszServerName = TraceStrDup( V_BSTR( pVar ) );
  179. if ( _pszServerName )
  180. {
  181. hr = S_OK;
  182. }
  183. else
  184. {
  185. hr = E_OUTOFMEMORY;
  186. }
  187. }
  188. else if ( StrCmpI( pszPropName, L"ClientGuid" ) == 0 )
  189. {
  190. if ( _pszClientGuid )
  191. {
  192. TraceFree( _pszClientGuid );
  193. }
  194. _pszClientGuid = TraceStrDup( V_BSTR( pVar) );
  195. if ( _pszClientGuid )
  196. {
  197. hr = S_OK;
  198. }
  199. else
  200. {
  201. hr = E_OUTOFMEMORY;
  202. }
  203. }
  204. else
  205. { // something unexpected came in
  206. hr = THR(E_INVALIDARG);
  207. }
  208. HRETURN(hr);
  209. }