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.

335 lines
9.1 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1994
  5. //
  6. // File: txtifilt.cxx
  7. //
  8. // Contents: Text filter 'class factory'.
  9. //
  10. // History: 23-Feb-1994 KyleP Created
  11. //
  12. // Notes: Machine generated. Hand modified.
  13. //
  14. //--------------------------------------------------------------------------
  15. #include <pch.cxx>
  16. #pragma hdrstop
  17. #include <tfilt.hxx>
  18. #include <nullfilt.hxx>
  19. #include <params.hxx>
  20. #include <ciregkey.hxx>
  21. #include <regacc.hxx>
  22. extern long gulcInstances;
  23. extern "C" GUID TYPID_CTextIFilter = {
  24. 0xd5355200,
  25. 0x77e3,
  26. 0x101a,
  27. { 0xb5, 0x52, 0x08, 0x00, 0x2b, 0x33, 0xb0, 0xe6 }
  28. };
  29. ULONG g_cbMaxTextFilter = CI_MAX_TEXT_FILTER_BYTES_DEFAULT;
  30. //+-------------------------------------------------------------------------
  31. //
  32. // Method: CTextIFilterBase::CTextIFilterBase
  33. //
  34. // Synopsis: Base constructor
  35. //
  36. // Effects: Manages global refcount
  37. //
  38. // History: 23-Feb-1994 KyleP Created
  39. //
  40. //--------------------------------------------------------------------------
  41. CTextIFilterBase::CTextIFilterBase()
  42. : _cRefs(1)
  43. {
  44. InterlockedIncrement( &gulcInstances );
  45. }
  46. //+-------------------------------------------------------------------------
  47. //
  48. // Method: CTextIFilterBase::~CTextIFilterBase
  49. //
  50. // Synopsis: Base destructor
  51. //
  52. // Effects: Manages global refcount
  53. //
  54. // History: 23-Feb-1994 KyleP Created
  55. //
  56. //--------------------------------------------------------------------------
  57. CTextIFilterBase::~CTextIFilterBase()
  58. {
  59. InterlockedDecrement( &gulcInstances );
  60. }
  61. //+-------------------------------------------------------------------------
  62. //
  63. // Method: CTextIFilterBase::QueryInterface
  64. //
  65. // Synopsis: Rebind to other interface
  66. //
  67. // Arguments: [riid] -- IID of new interface
  68. // [ppvObject] -- New interface * returned here
  69. //
  70. // Returns: S_OK if bind succeeded, E_NOINTERFACE if bind failed
  71. //
  72. // History: 23-Feb-1994 KyleP Created
  73. //
  74. //--------------------------------------------------------------------------
  75. SCODE STDMETHODCALLTYPE CTextIFilterBase::QueryInterface( REFIID riid,
  76. void ** ppvObject)
  77. {
  78. SCODE sc = S_OK;
  79. if ( 0 == ppvObject )
  80. return E_INVALIDARG;
  81. *ppvObject = 0;
  82. if ( IID_IFilter == riid )
  83. *ppvObject = (IUnknown *)(IFilter *)this;
  84. else if ( IID_IPersist == riid )
  85. *ppvObject = (IUnknown *)(IPersist *)(IPersistFile *)this;
  86. else if ( IID_IPersistFile == riid )
  87. *ppvObject = (IUnknown *)(IPersistFile *)this;
  88. #if 0 // not checked in because it might break SQL/Exchange without testing
  89. else if ( IID_IPersistStream == riid )
  90. *ppvObject = (IUnknown *)(IPersistStream *)this;
  91. #endif
  92. else if ( IID_IUnknown == riid )
  93. *ppvObject = (IUnknown *)(IPersist *)(IPersistFile *)this;
  94. else
  95. sc = E_NOINTERFACE;
  96. if ( SUCCEEDED( sc ) )
  97. AddRef();
  98. return sc;
  99. } //QueryInterface
  100. //+-------------------------------------------------------------------------
  101. //
  102. // Method: CTextIFilterBase::AddRef
  103. //
  104. // Synopsis: Increments refcount
  105. //
  106. // History: 23-Feb-1994 KyleP Created
  107. //
  108. //--------------------------------------------------------------------------
  109. ULONG STDMETHODCALLTYPE CTextIFilterBase::AddRef()
  110. {
  111. return InterlockedIncrement( &_cRefs );
  112. }
  113. //+-------------------------------------------------------------------------
  114. //
  115. // Method: CTextIFilterBase::Release
  116. //
  117. // Synopsis: Decrement refcount. Delete if necessary.
  118. //
  119. // History: 23-Feb-1994 KyleP Created
  120. //
  121. //--------------------------------------------------------------------------
  122. ULONG STDMETHODCALLTYPE CTextIFilterBase::Release()
  123. {
  124. unsigned long uTmp = InterlockedDecrement( &_cRefs );
  125. if ( 0 == uTmp )
  126. delete this;
  127. return(uTmp);
  128. }
  129. //+-------------------------------------------------------------------------
  130. //
  131. // Method: CTextIFilterCF::CTextIFilterCF
  132. //
  133. // Synopsis: Text IFilter class factory constructor
  134. //
  135. // History: 23-Feb-1994 KyleP Created
  136. //
  137. //--------------------------------------------------------------------------
  138. CTextIFilterCF::CTextIFilterCF()
  139. : _cRefs( 1 )
  140. {
  141. InterlockedIncrement( &gulcInstances );
  142. CRegAccess reg( RTL_REGISTRY_CONTROL, wcsRegAdmin );
  143. g_cbMaxTextFilter= reg.Read( wcsMaxTextFilterBytes,
  144. CI_MAX_TEXT_FILTER_BYTES_DEFAULT,
  145. CI_MAX_TEXT_FILTER_BYTES_MIN,
  146. CI_MAX_TEXT_FILTER_BYTES_MAX );
  147. }
  148. //+-------------------------------------------------------------------------
  149. //
  150. // Method: CTextIFilterCF::~CTextIFilterCF
  151. //
  152. // Synopsis: Text IFilter class factory constructor
  153. //
  154. // History: 23-Feb-1994 KyleP Created
  155. //
  156. //--------------------------------------------------------------------------
  157. CTextIFilterCF::~CTextIFilterCF()
  158. {
  159. InterlockedDecrement( &gulcInstances );
  160. }
  161. //+-------------------------------------------------------------------------
  162. //
  163. // Method: CTextIFilterCF::QueryInterface
  164. //
  165. // Synopsis: Rebind to other interface
  166. //
  167. // Arguments: [riid] -- IID of new interface
  168. // [ppvObject] -- New interface * returned here
  169. //
  170. // Returns: S_OK if bind succeeded, E_NOINTERFACE if bind failed
  171. //
  172. // History: 23-Feb-1994 KyleP Created
  173. //
  174. //--------------------------------------------------------------------------
  175. SCODE STDMETHODCALLTYPE CTextIFilterCF::QueryInterface( REFIID riid,
  176. void ** ppvObject )
  177. {
  178. SCODE sc = S_OK;
  179. if ( 0 == ppvObject )
  180. return E_INVALIDARG;
  181. *ppvObject = 0;
  182. if ( IID_IClassFactory == riid )
  183. *ppvObject = (IUnknown *)(IClassFactory *)this;
  184. else if ( IID_IUnknown == riid )
  185. *ppvObject = (IUnknown *)(IClassFactory *)this;
  186. else if ( IID_ITypeLib == riid )
  187. sc = E_NOTIMPL;
  188. else
  189. sc = E_NOINTERFACE;
  190. if ( SUCCEEDED( sc ) )
  191. AddRef();
  192. return sc;
  193. } //QueryInterface
  194. //+-------------------------------------------------------------------------
  195. //
  196. // Method: CTextIFilterCF::AddRef
  197. //
  198. // Synopsis: Increments refcount
  199. //
  200. // History: 23-Feb-1994 KyleP Created
  201. //
  202. //--------------------------------------------------------------------------
  203. ULONG STDMETHODCALLTYPE CTextIFilterCF::AddRef()
  204. {
  205. return InterlockedIncrement( &_cRefs );
  206. }
  207. //+-------------------------------------------------------------------------
  208. //
  209. // Method: CTextIFilterCF::Release
  210. //
  211. // Synopsis: Decrement refcount. Delete if necessary.
  212. //
  213. // History: 23-Feb-1994 KyleP Created
  214. //
  215. //--------------------------------------------------------------------------
  216. ULONG STDMETHODCALLTYPE CTextIFilterCF::Release()
  217. {
  218. unsigned long uTmp = InterlockedDecrement( &_cRefs );
  219. if ( 0 == uTmp )
  220. delete this;
  221. return(uTmp);
  222. }
  223. //+-------------------------------------------------------------------------
  224. //
  225. // Method: CTextIFilterCF::CreateInstance
  226. //
  227. // Synopsis: Creates new TextIFilter object
  228. //
  229. // Arguments: [pUnkOuter] -- 'Outer' IUnknown
  230. // [riid] -- Interface to bind
  231. // [ppvObject] -- Interface returned here
  232. //
  233. // History: 23-Feb-1994 KyleP Created
  234. //
  235. //--------------------------------------------------------------------------
  236. SCODE STDMETHODCALLTYPE CTextIFilterCF::CreateInstance( IUnknown * pUnkOuter,
  237. REFIID riid,
  238. void * * ppvObject )
  239. {
  240. CTextIFilter * pIUnk = 0;
  241. SCODE sc = S_OK;
  242. TRY
  243. {
  244. pIUnk = new CTextIFilter();
  245. sc = pIUnk->QueryInterface( riid , ppvObject );
  246. pIUnk->Release(); // Release extra refcount from QueryInterface
  247. }
  248. CATCH(CException, e)
  249. {
  250. Win4Assert( 0 == pIUnk );
  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. return (sc);
  262. }
  263. //+-------------------------------------------------------------------------
  264. //
  265. // Method: CTextIFilterCF::LockServer
  266. //
  267. // Synopsis: Force class factory to remain loaded
  268. //
  269. // Arguments: [fLock] -- TRUE if locking, FALSE if unlocking
  270. //
  271. // Returns: S_OK
  272. //
  273. // History: 23-Feb-1994 KyleP Created
  274. //
  275. //--------------------------------------------------------------------------
  276. SCODE STDMETHODCALLTYPE CTextIFilterCF::LockServer(BOOL fLock)
  277. {
  278. if(fLock)
  279. InterlockedIncrement( &gulcInstances );
  280. else
  281. InterlockedDecrement( &gulcInstances );
  282. return(S_OK);
  283. }