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.

341 lines
9.0 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997 - 1998.
  5. //
  6. // File: isrchcf.cxx
  7. //
  8. // Contents: Contains the implementation of ICiControl interface.
  9. //
  10. // History: 1-17-97 srikants Created
  11. //
  12. //----------------------------------------------------------------------------
  13. #include <pch.cxx>
  14. #pragma hdrstop
  15. #include <isrchcf.hxx>
  16. #include <isearch.hxx>
  17. const GUID clsidISearchCreator = CLSID_ISearchCreator;
  18. extern long gulcInstances;
  19. //+---------------------------------------------------------------------------
  20. //
  21. // Member: CCiISearchCreator::QueryInterface
  22. //
  23. // Synopsis: Returns interfaces to IID_IUknown, IID_ICiControl
  24. //
  25. // History: 01-17-97 srikants Created
  26. //
  27. //----------------------------------------------------------------------------
  28. STDMETHODIMP CCiISearchCreator::QueryInterface(
  29. REFIID riid,
  30. void **ppvObject)
  31. {
  32. Win4Assert( 0 != ppvObject );
  33. if ( IID_ICiISearchCreator == riid )
  34. *ppvObject = (void *)((ICiISearchCreator *)this);
  35. else if ( IID_IUnknown == riid )
  36. *ppvObject = (void *)((IUnknown *) (ICiISearchCreator *) this);
  37. else
  38. {
  39. *ppvObject = 0;
  40. return E_NOINTERFACE;
  41. }
  42. AddRef();
  43. return S_OK;
  44. } //QueryInterface
  45. //+---------------------------------------------------------------------------
  46. //
  47. // Member: CCiISearchCreator::AddRef
  48. //
  49. // History: 01-17-97 srikants Created
  50. //
  51. //----------------------------------------------------------------------------
  52. STDMETHODIMP_(ULONG) CCiISearchCreator::AddRef()
  53. {
  54. return InterlockedIncrement(&_refCount);
  55. } //AddRef
  56. //+---------------------------------------------------------------------------
  57. //
  58. // Member: CCiISearchCreator::Release
  59. //
  60. // History: 01-17-97 srikants Created
  61. //
  62. //----------------------------------------------------------------------------
  63. STDMETHODIMP_(ULONG) CCiISearchCreator::Release()
  64. {
  65. Win4Assert( _refCount > 0 );
  66. LONG refCount = InterlockedDecrement(&_refCount);
  67. if ( refCount <= 0 )
  68. delete this;
  69. return refCount;
  70. } //Release
  71. //+---------------------------------------------------------------------------
  72. //
  73. // Member: CCiISearchCreator::CreateISearch
  74. //
  75. // Synopsis: Creates an object and returns its ISearch interface.
  76. //
  77. // Arguments: [pRst] - [in] The Restriction
  78. // [pILangRes] - [in] Language resources to use
  79. // [pIOpenedDoc] - [in] The "opened document"
  80. // [ppISearch] - [out] If successful, the ISearch interface
  81. //
  82. // Returns: S_OK if successful; Error code otherwise.
  83. //
  84. // History: 2-26-97 srikants Created
  85. //
  86. //----------------------------------------------------------------------------
  87. STDMETHODIMP CCiISearchCreator::CreateISearch(
  88. DBCOMMANDTREE * pRst,
  89. ICiCLangRes * pILangRes,
  90. ICiCOpenedDoc * pIOpenedDoc,
  91. ISearchQueryHits ** ppISearch )
  92. {
  93. if ( 0 == pRst || 0 == pILangRes || 0 == ppISearch )
  94. return E_INVALIDARG;
  95. *ppISearch = 0;
  96. SCODE sc = S_OK;
  97. TRY
  98. {
  99. CSearch * pSearch = new CSearch( pRst, pILangRes, pIOpenedDoc );
  100. *ppISearch = pSearch;
  101. }
  102. CATCH( CException, e )
  103. {
  104. ciDebugOut(( DEB_ERROR, "Failed to create CCiManager. Error (0x%X)\n",
  105. e.GetErrorCode() ));
  106. sc = e.GetErrorCode();
  107. }
  108. END_CATCH
  109. return sc;
  110. }
  111. //+---------------------------------------------------------------------------
  112. //
  113. // Construction and destruction
  114. //
  115. //----------------------------------------------------------------------------
  116. //+-------------------------------------------------------------------------
  117. //
  118. // Method: CCiISearchCreatorCF::CCiISearchCreatorCF
  119. //
  120. // Synopsis: Storage Filter Object class factory constructor
  121. //
  122. // History: 17-Jan-1997 Srikants Created
  123. //
  124. //+-------------------------------------------------------------------------
  125. CCiISearchCreatorCF::CCiISearchCreatorCF()
  126. : _RefCount( 1 )
  127. {
  128. InterlockedIncrement( &gulcInstances );
  129. }
  130. //+-------------------------------------------------------------------------
  131. //
  132. // Method: CCiISearchCreatorCF::~CCiISearchCreatorCF
  133. //
  134. // Synopsis: Storage Filter Object class factory destructor
  135. //
  136. // History: 6-Jan-1997 Srikants Created
  137. //
  138. //--------------------------------------------------------------------------
  139. CCiISearchCreatorCF::~CCiISearchCreatorCF()
  140. {
  141. Win4Assert( _RefCount == 0);
  142. Win4Assert( gulcInstances != 0 );
  143. InterlockedDecrement( &gulcInstances );
  144. }
  145. //+---------------------------------------------------------------------------
  146. //
  147. // IUnknown method implementations
  148. //
  149. //----------------------------------------------------------------------------
  150. //+-------------------------------------------------------------------------
  151. //
  152. // Method: CCiISearchCreatorCF::AddRef
  153. //
  154. // Synopsis: Increments refcount
  155. //
  156. // History: 17-Jan-1997 Srikants Created
  157. //
  158. //--------------------------------------------------------------------------
  159. ULONG STDMETHODCALLTYPE CCiISearchCreatorCF::AddRef()
  160. {
  161. return InterlockedIncrement( &_RefCount );
  162. }
  163. //+-------------------------------------------------------------------------
  164. //
  165. // Method: CCiISearchCreatorCF::Release
  166. //
  167. // Synopsis: Decrement refcount. Delete if necessary.
  168. //
  169. // History: 6-Jan-1997 Srikants Created
  170. //
  171. //--------------------------------------------------------------------------
  172. ULONG STDMETHODCALLTYPE CCiISearchCreatorCF::Release()
  173. {
  174. Win4Assert( _RefCount != 0 );
  175. LONG RefCount = InterlockedDecrement( &_RefCount );
  176. if ( RefCount <= 0 )
  177. delete this;
  178. return (ULONG) RefCount;
  179. } // Release
  180. //+-------------------------------------------------------------------------
  181. //
  182. // Method: CCiISearchCreatorCF::QueryInterface
  183. //
  184. // Synopsis: Rebind to other interface
  185. //
  186. // Arguments: [riid] -- IID of new interface
  187. // [ppvObject] -- New interface * returned here
  188. //
  189. // Returns: S_OK if bind succeeded, E_NOINTERFACE if bind failed
  190. //
  191. // History: 17-Jan-1997 Srikants Created
  192. //
  193. //--------------------------------------------------------------------------
  194. STDMETHODIMP CCiISearchCreatorCF::QueryInterface(
  195. REFIID riid,
  196. PVOID* ppvObject )
  197. {
  198. Win4Assert( 0 != ppvObject );
  199. *ppvObject = 0;
  200. if ( IID_IUnknown == riid )
  201. *ppvObject = (PVOID) ((IUnknown *) this );
  202. else if ( IID_IClassFactory == riid)
  203. *ppvObject = (PVOID) ((IClassFactory *) this );
  204. else
  205. return E_NOINTERFACE;
  206. AddRef( );
  207. return S_OK;
  208. }
  209. //+-------------------------------------------------------------------------
  210. //
  211. // Method: CCiISearchCreatorCF::CreateInstance
  212. //
  213. // Synopsis: Create new CStorageFilterObject instance
  214. //
  215. // Arguments: [pUnkOuter] -- 'Outer' IUnknown; IGNORED
  216. // [riid] -- Interface to bind
  217. // [ppvObject] -- Interface returned here
  218. //
  219. // History: 17-Jan-1997 Srikants Created
  220. //
  221. //--------------------------------------------------------------------------
  222. STDMETHODIMP CCiISearchCreatorCF::CreateInstance(
  223. IUnknown * pUnkOuter,
  224. REFIID riid,
  225. PVOID * ppvObject )
  226. {
  227. if ( 0 != pUnkOuter )
  228. return ResultFromScode( CLASS_E_NOAGGREGATION );
  229. CCiISearchCreator * pObject = 0;
  230. SCODE sc = S_OK;
  231. TRANSLATE_EXCEPTIONS;
  232. TRY
  233. {
  234. //
  235. // Create the new object
  236. //
  237. pObject = new CCiISearchCreator;
  238. //
  239. // Obtain the new interface
  240. //
  241. sc = pObject->QueryInterface( riid , ppvObject );
  242. //
  243. // Regardless of whether the QueryInterface succeeded, we
  244. // release the object.
  245. //
  246. pObject->Release();
  247. }
  248. CATCH(CException, e)
  249. {
  250. Win4Assert( 0 == pObject );
  251. switch( e.GetErrorCode() )
  252. {
  253. case E_OUTOFMEMORY:
  254. sc = (E_OUTOFMEMORY);
  255. break;
  256. default:
  257. sc = (E_UNEXPECTED);
  258. }
  259. }
  260. END_CATCH;
  261. UNTRANSLATE_EXCEPTIONS;
  262. return sc;
  263. }
  264. //+-------------------------------------------------------------------------
  265. //
  266. // Method: CCiISearchCreatorCF::LockServer
  267. //
  268. // Synopsis: Force class factory to remain loaded
  269. //
  270. // Arguments: [fLock] -- TRUE if locking, FALSE if unlocking
  271. //
  272. // Returns: S_OK
  273. //
  274. // History: 17-Jan-1997 Srikants Created
  275. //
  276. //--------------------------------------------------------------------------
  277. STDMETHODIMP CCiISearchCreatorCF::LockServer( BOOL fLock )
  278. {
  279. if (fLock)
  280. InterlockedIncrement( &gulcInstances );
  281. else
  282. InterlockedDecrement( &gulcInstances );
  283. return S_OK;
  284. }