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.

451 lines
12 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1994
  5. //
  6. // File: classf.cxx
  7. //
  8. // Contents: Class factory for standard Filter Object class
  9. //
  10. // History: 6-Jan-1997 MarkZ Created
  11. //
  12. //--------------------------------------------------------------------------
  13. #include <pch.cxx>
  14. #pragma hdrstop
  15. #include "docname.hxx"
  16. #include "classf.hxx"
  17. #include "filterob.hxx"
  18. #include <fsciclnt.h>
  19. #include <dslookup.hxx>
  20. //
  21. // We keep count of the number of filter objects that we've created
  22. // to let OLE know when this DLL is finally free.
  23. //
  24. extern long gulcInstances;
  25. // {aa205a4d-681F-11d0-A243-08002B36FCA4}
  26. extern "C" const GUID guidStorageFilterObject =
  27. { 0xaa205a4d, 0x681f, 0x11d0, { 0xa2, 0x43, 0x8, 0x0, 0x2b, 0x36, 0xfc, 0xa4 } };
  28. extern "C" const GUID guidStorageDocStoreLocatorObject = CLSID_StorageDocStoreLocator;
  29. //+---------------------------------------------------------------------------
  30. //
  31. // Construction and destruction
  32. //
  33. //----------------------------------------------------------------------------
  34. //+-------------------------------------------------------------------------
  35. //
  36. // Method: CStorageFilterObjectCF::CStorageFilterObjectCF
  37. //
  38. // Synopsis: Storage Filter Object class factory constructor
  39. //
  40. // History: 6-Jan-1997 MarkZ Created
  41. //
  42. //+-------------------------------------------------------------------------
  43. CStorageFilterObjectCF::CStorageFilterObjectCF()
  44. : _RefCount( 1 )
  45. {
  46. InterlockedIncrement( &gulcInstances );
  47. }
  48. //+-------------------------------------------------------------------------
  49. //
  50. // Method: CStorageFilterObjectCF::~CStorageFilterObjectCF
  51. //
  52. // Synopsis: Storage Filter Object class factory destructor
  53. //
  54. // History: 6-Jan-1997 MarkZ Created
  55. //
  56. //--------------------------------------------------------------------------
  57. CStorageFilterObjectCF::~CStorageFilterObjectCF()
  58. {
  59. Win4Assert( _RefCount == 0);
  60. Win4Assert( gulcInstances != 0 );
  61. InterlockedDecrement( &gulcInstances );
  62. }
  63. //+---------------------------------------------------------------------------
  64. //
  65. // IUnknown method implementations
  66. //
  67. //----------------------------------------------------------------------------
  68. //+-------------------------------------------------------------------------
  69. //
  70. // Method: CStorageFilterObjectCF::AddRef
  71. //
  72. // Synopsis: Increments refcount
  73. //
  74. // History: 6-Jan-1997 MarkZ Created
  75. //
  76. //--------------------------------------------------------------------------
  77. ULONG STDMETHODCALLTYPE CStorageFilterObjectCF::AddRef()
  78. {
  79. return InterlockedIncrement( &_RefCount );
  80. }
  81. //+-------------------------------------------------------------------------
  82. //
  83. // Method: CStorageFilterObjectCF::Release
  84. //
  85. // Synopsis: Decrement refcount. Delete if necessary.
  86. //
  87. // History: 6-Jan-1997 MarkZ Created
  88. //
  89. //--------------------------------------------------------------------------
  90. ULONG STDMETHODCALLTYPE CStorageFilterObjectCF::Release()
  91. {
  92. Win4Assert( _RefCount != 0 );
  93. LONG RefCount = InterlockedDecrement( &_RefCount );
  94. if ( RefCount <= 0 )
  95. delete this;
  96. return (ULONG) RefCount;
  97. } // Release
  98. //+-------------------------------------------------------------------------
  99. //
  100. // Method: CStorageFilterObjectCF::QueryInterface
  101. //
  102. // Synopsis: Rebind to other interface
  103. //
  104. // Arguments: [riid] -- IID of new interface
  105. // [ppvObject] -- New interface * returned here
  106. //
  107. // Returns: S_OK if bind succeeded, E_NOINTERFACE if bind failed
  108. //
  109. // History: 6-Jan-1997 MarkZ Created
  110. //
  111. //--------------------------------------------------------------------------
  112. STDMETHODIMP CStorageFilterObjectCF::QueryInterface(
  113. REFIID riid,
  114. PVOID* ppvObject )
  115. {
  116. Win4Assert( 0 != ppvObject );
  117. if ( IID_IClassFactory == riid)
  118. *ppvObject = (PVOID) ((IClassFactory *) this );
  119. else if ( IID_IUnknown == riid )
  120. *ppvObject = (PVOID) ((IUnknown *) this );
  121. else
  122. {
  123. *ppvObject = 0;
  124. return E_NOINTERFACE;
  125. }
  126. AddRef();
  127. return S_OK;
  128. }
  129. //+-------------------------------------------------------------------------
  130. //
  131. // Method: CStorageFilterObjectCF::CreateInstance
  132. //
  133. // Synopsis: Create new CStorageFilterObject instance
  134. //
  135. // Arguments: [pUnkOuter] -- 'Outer' IUnknown; IGNORED
  136. // [riid] -- Interface to bind
  137. // [ppvObject] -- Interface returned here
  138. //
  139. // History: 6-Jan-1997 MarkZ Created
  140. //
  141. //--------------------------------------------------------------------------
  142. STDMETHODIMP CStorageFilterObjectCF::CreateInstance(
  143. IUnknown * pUnkOuter,
  144. REFIID riid,
  145. PVOID * ppvObject )
  146. {
  147. CStorageFilterObject * pFilterObject = 0;
  148. SCODE sc = S_OK;
  149. TRANSLATE_EXCEPTIONS;
  150. TRY
  151. {
  152. //
  153. // Create the new object
  154. //
  155. pFilterObject = new CStorageFilterObject;
  156. //
  157. // Obtain the new interface
  158. //
  159. sc = pFilterObject->QueryInterface( riid , ppvObject );
  160. //
  161. // Regardless of whether the QueryInterface succeeded, we
  162. // release the object.
  163. //
  164. pFilterObject->Release();
  165. }
  166. CATCH(CException, e)
  167. {
  168. Win4Assert( 0 == pFilterObject );
  169. switch( e.GetErrorCode() )
  170. {
  171. case E_OUTOFMEMORY:
  172. sc = (E_OUTOFMEMORY);
  173. break;
  174. default:
  175. sc = (E_UNEXPECTED);
  176. }
  177. }
  178. END_CATCH;
  179. UNTRANSLATE_EXCEPTIONS;
  180. return (sc);
  181. }
  182. //+-------------------------------------------------------------------------
  183. //
  184. // Method: CStorageFilterObjectCF::LockServer
  185. //
  186. // Synopsis: Force class factory to remain loaded
  187. //
  188. // Arguments: [fLock] -- TRUE if locking, FALSE if unlocking
  189. //
  190. // Returns: S_OK
  191. //
  192. // History: 6-Jan-1997 MarkZ Created
  193. //
  194. //--------------------------------------------------------------------------
  195. STDMETHODIMP CStorageFilterObjectCF::LockServer( BOOL fLock )
  196. {
  197. if (fLock)
  198. InterlockedIncrement( &gulcInstances );
  199. else
  200. InterlockedDecrement( &gulcInstances );
  201. return(S_OK);
  202. }
  203. //
  204. // ======================== DocStoreLocator Class Factory ==================
  205. //
  206. //+-------------------------------------------------------------------------
  207. //
  208. // Method: CStorageDocStoreLocatorObjectCF::CStorageDocStoreLocatorObjectCF
  209. //
  210. // Synopsis: Storage Filter Object class factory constructor
  211. //
  212. // History: 6-Jan-1997 MarkZ Created
  213. //
  214. //+-------------------------------------------------------------------------
  215. CStorageDocStoreLocatorObjectCF::CStorageDocStoreLocatorObjectCF()
  216. : _RefCount( 1 )
  217. {
  218. InterlockedIncrement( &gulcInstances );
  219. }
  220. //+-------------------------------------------------------------------------
  221. //
  222. // Method: CStorageDocStoreLocatorObjectCF::~CStorageDocStoreLocatorObjectCF
  223. //
  224. // Synopsis: Storage Filter Object class factory destructor
  225. //
  226. // History: 6-Jan-1997 MarkZ Created
  227. //
  228. //--------------------------------------------------------------------------
  229. CStorageDocStoreLocatorObjectCF::~CStorageDocStoreLocatorObjectCF()
  230. {
  231. Win4Assert( _RefCount == 0);
  232. Win4Assert( gulcInstances != 0 );
  233. InterlockedDecrement( &gulcInstances );
  234. }
  235. //+---------------------------------------------------------------------------
  236. //
  237. // IUnknown method implementations
  238. //
  239. //----------------------------------------------------------------------------
  240. //+-------------------------------------------------------------------------
  241. //
  242. // Method: CStorageDocStoreLocatorObjectCF::AddRef
  243. //
  244. // Synopsis: Increments refcount
  245. //
  246. // History: 6-Jan-1997 MarkZ Created
  247. //
  248. //--------------------------------------------------------------------------
  249. ULONG STDMETHODCALLTYPE CStorageDocStoreLocatorObjectCF::AddRef()
  250. {
  251. return InterlockedIncrement( &_RefCount );
  252. }
  253. //+-------------------------------------------------------------------------
  254. //
  255. // Method: CStorageDocStoreLocatorObjectCF::Release
  256. //
  257. // Synopsis: Decrement refcount. Delete if necessary.
  258. //
  259. // History: 6-Jan-1997 MarkZ Created
  260. //
  261. //--------------------------------------------------------------------------
  262. ULONG STDMETHODCALLTYPE CStorageDocStoreLocatorObjectCF::Release()
  263. {
  264. Win4Assert( _RefCount != 0 );
  265. LONG RefCount = InterlockedDecrement( &_RefCount );
  266. if ( RefCount <= 0 )
  267. delete this;
  268. return (ULONG) RefCount;
  269. } // Release
  270. //+-------------------------------------------------------------------------
  271. //
  272. // Method: CStorageDocStoreLocatorObjectCF::QueryInterface
  273. //
  274. // Synopsis: Rebind to other interface
  275. //
  276. // Arguments: [riid] -- IID of new interface
  277. // [ppvObject] -- New interface * returned here
  278. //
  279. // Returns: S_OK if bind succeeded, E_NOINTERFACE if bind failed
  280. //
  281. // History: 6-Jan-1997 MarkZ Created
  282. //
  283. //--------------------------------------------------------------------------
  284. STDMETHODIMP CStorageDocStoreLocatorObjectCF::QueryInterface(
  285. REFIID riid,
  286. PVOID* ppvObject )
  287. {
  288. Win4Assert( 0 != ppvObject );
  289. if ( IID_IClassFactory == riid)
  290. *ppvObject = (PVOID) ((IClassFactory *) this );
  291. else if ( IID_IUnknown == riid )
  292. *ppvObject = (PVOID) ((IUnknown *) this );
  293. else
  294. {
  295. *ppvObject = 0;
  296. return E_NOINTERFACE;
  297. }
  298. AddRef();
  299. return S_OK;
  300. }
  301. //+-------------------------------------------------------------------------
  302. //
  303. // Method: CStorageDocStoreLocatorObjectCF::CreateInstance
  304. //
  305. // Synopsis: Create new CStorageFilterObject instance
  306. //
  307. // Arguments: [pUnkOuter] -- 'Outer' IUnknown; IGNORED
  308. // [riid] -- Interface to bind
  309. // [ppvObject] -- Interface returned here
  310. //
  311. // History: 6-Jan-1997 MarkZ Created
  312. //
  313. //--------------------------------------------------------------------------
  314. STDMETHODIMP CStorageDocStoreLocatorObjectCF::CreateInstance(
  315. IUnknown * pUnkOuter,
  316. REFIID riid,
  317. PVOID * ppvObject )
  318. {
  319. CClientDocStoreLocator * pObject = 0;
  320. SCODE sc = S_OK;
  321. TRANSLATE_EXCEPTIONS;
  322. TRY
  323. {
  324. //
  325. // Create the new object
  326. //
  327. pObject = new CClientDocStoreLocator;
  328. //
  329. // Obtain the new interface
  330. //
  331. sc = pObject->QueryInterface( riid , ppvObject );
  332. //
  333. // Regardless of whether the QueryInterface succeeded, we
  334. // release the object.
  335. //
  336. pObject->Release();
  337. }
  338. CATCH(CException, e)
  339. {
  340. Win4Assert( 0 == pObject );
  341. switch( e.GetErrorCode() )
  342. {
  343. case E_OUTOFMEMORY:
  344. sc = (E_OUTOFMEMORY);
  345. break;
  346. default:
  347. sc = (E_UNEXPECTED);
  348. }
  349. }
  350. END_CATCH;
  351. UNTRANSLATE_EXCEPTIONS;
  352. return (sc);
  353. }
  354. //+-------------------------------------------------------------------------
  355. //
  356. // Method: CStorageDocStoreLocatorObjectCF::LockServer
  357. //
  358. // Synopsis: Force class factory to remain loaded
  359. //
  360. // Arguments: [fLock] -- TRUE if locking, FALSE if unlocking
  361. //
  362. // Returns: S_OK
  363. //
  364. // History: 6-Jan-1997 MarkZ Created
  365. //
  366. //--------------------------------------------------------------------------
  367. STDMETHODIMP CStorageDocStoreLocatorObjectCF::LockServer( BOOL fLock )
  368. {
  369. if (fLock)
  370. InterlockedIncrement( &gulcInstances );
  371. else
  372. InterlockedDecrement( &gulcInstances );
  373. return(S_OK);
  374. }