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.

331 lines
8.5 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. else if ( IID_IUnknown == riid )
  89. *ppvObject = (IUnknown *)(IPersist *)(IPersistFile *)this;
  90. else
  91. sc = E_NOINTERFACE;
  92. if ( SUCCEEDED( sc ) )
  93. AddRef();
  94. return sc;
  95. } //QueryInterface
  96. //+-------------------------------------------------------------------------
  97. //
  98. // Method: CTextIFilterBase::AddRef
  99. //
  100. // Synopsis: Increments refcount
  101. //
  102. // History: 23-Feb-1994 KyleP Created
  103. //
  104. //--------------------------------------------------------------------------
  105. ULONG STDMETHODCALLTYPE CTextIFilterBase::AddRef()
  106. {
  107. return InterlockedIncrement( &_cRefs );
  108. }
  109. //+-------------------------------------------------------------------------
  110. //
  111. // Method: CTextIFilterBase::Release
  112. //
  113. // Synopsis: Decrement refcount. Delete if necessary.
  114. //
  115. // History: 23-Feb-1994 KyleP Created
  116. //
  117. //--------------------------------------------------------------------------
  118. ULONG STDMETHODCALLTYPE CTextIFilterBase::Release()
  119. {
  120. unsigned long uTmp = InterlockedDecrement( &_cRefs );
  121. if ( 0 == uTmp )
  122. delete this;
  123. return(uTmp);
  124. }
  125. //+-------------------------------------------------------------------------
  126. //
  127. // Method: CTextIFilterCF::CTextIFilterCF
  128. //
  129. // Synopsis: Text IFilter class factory constructor
  130. //
  131. // History: 23-Feb-1994 KyleP Created
  132. //
  133. //--------------------------------------------------------------------------
  134. CTextIFilterCF::CTextIFilterCF()
  135. : _cRefs( 1 )
  136. {
  137. InterlockedIncrement( &gulcInstances );
  138. CRegAccess reg( RTL_REGISTRY_CONTROL, wcsRegAdmin );
  139. g_cbMaxTextFilter= reg.Read( wcsMaxTextFilterBytes,
  140. CI_MAX_TEXT_FILTER_BYTES_DEFAULT,
  141. CI_MAX_TEXT_FILTER_BYTES_MIN,
  142. CI_MAX_TEXT_FILTER_BYTES_MAX );
  143. }
  144. //+-------------------------------------------------------------------------
  145. //
  146. // Method: CTextIFilterCF::~CTextIFilterCF
  147. //
  148. // Synopsis: Text IFilter class factory constructor
  149. //
  150. // History: 23-Feb-1994 KyleP Created
  151. //
  152. //--------------------------------------------------------------------------
  153. CTextIFilterCF::~CTextIFilterCF()
  154. {
  155. InterlockedDecrement( &gulcInstances );
  156. }
  157. //+-------------------------------------------------------------------------
  158. //
  159. // Method: CTextIFilterCF::QueryInterface
  160. //
  161. // Synopsis: Rebind to other interface
  162. //
  163. // Arguments: [riid] -- IID of new interface
  164. // [ppvObject] -- New interface * returned here
  165. //
  166. // Returns: S_OK if bind succeeded, E_NOINTERFACE if bind failed
  167. //
  168. // History: 23-Feb-1994 KyleP Created
  169. //
  170. //--------------------------------------------------------------------------
  171. SCODE STDMETHODCALLTYPE CTextIFilterCF::QueryInterface( REFIID riid,
  172. void ** ppvObject )
  173. {
  174. SCODE sc = S_OK;
  175. if ( 0 == ppvObject )
  176. return E_INVALIDARG;
  177. *ppvObject = 0;
  178. if ( IID_IClassFactory == riid )
  179. *ppvObject = (IUnknown *)(IClassFactory *)this;
  180. else if ( IID_IUnknown == riid )
  181. *ppvObject = (IUnknown *)(IClassFactory *)this;
  182. else if ( IID_ITypeLib == riid )
  183. sc = E_NOTIMPL;
  184. else
  185. sc = E_NOINTERFACE;
  186. if ( SUCCEEDED( sc ) )
  187. AddRef();
  188. return sc;
  189. } //QueryInterface
  190. //+-------------------------------------------------------------------------
  191. //
  192. // Method: CTextIFilterCF::AddRef
  193. //
  194. // Synopsis: Increments refcount
  195. //
  196. // History: 23-Feb-1994 KyleP Created
  197. //
  198. //--------------------------------------------------------------------------
  199. ULONG STDMETHODCALLTYPE CTextIFilterCF::AddRef()
  200. {
  201. return InterlockedIncrement( &_cRefs );
  202. }
  203. //+-------------------------------------------------------------------------
  204. //
  205. // Method: CTextIFilterCF::Release
  206. //
  207. // Synopsis: Decrement refcount. Delete if necessary.
  208. //
  209. // History: 23-Feb-1994 KyleP Created
  210. //
  211. //--------------------------------------------------------------------------
  212. ULONG STDMETHODCALLTYPE CTextIFilterCF::Release()
  213. {
  214. unsigned long uTmp = InterlockedDecrement( &_cRefs );
  215. if ( 0 == uTmp )
  216. delete this;
  217. return(uTmp);
  218. }
  219. //+-------------------------------------------------------------------------
  220. //
  221. // Method: CTextIFilterCF::CreateInstance
  222. //
  223. // Synopsis: Creates new TextIFilter object
  224. //
  225. // Arguments: [pUnkOuter] -- 'Outer' IUnknown
  226. // [riid] -- Interface to bind
  227. // [ppvObject] -- Interface returned here
  228. //
  229. // History: 23-Feb-1994 KyleP Created
  230. //
  231. //--------------------------------------------------------------------------
  232. SCODE STDMETHODCALLTYPE CTextIFilterCF::CreateInstance( IUnknown * pUnkOuter,
  233. REFIID riid,
  234. void * * ppvObject )
  235. {
  236. CTextIFilter * pIUnk = 0;
  237. SCODE sc = S_OK;
  238. TRY
  239. {
  240. pIUnk = new CTextIFilter();
  241. sc = pIUnk->QueryInterface( riid , ppvObject );
  242. pIUnk->Release(); // Release extra refcount from QueryInterface
  243. }
  244. CATCH(CException, e)
  245. {
  246. Win4Assert( 0 == pIUnk );
  247. switch( e.GetErrorCode() )
  248. {
  249. case E_OUTOFMEMORY:
  250. sc = (E_OUTOFMEMORY);
  251. break;
  252. default:
  253. sc = (E_UNEXPECTED);
  254. }
  255. }
  256. END_CATCH;
  257. return (sc);
  258. }
  259. //+-------------------------------------------------------------------------
  260. //
  261. // Method: CTextIFilterCF::LockServer
  262. //
  263. // Synopsis: Force class factory to remain loaded
  264. //
  265. // Arguments: [fLock] -- TRUE if locking, FALSE if unlocking
  266. //
  267. // Returns: S_OK
  268. //
  269. // History: 23-Feb-1994 KyleP Created
  270. //
  271. //--------------------------------------------------------------------------
  272. SCODE STDMETHODCALLTYPE CTextIFilterCF::LockServer(BOOL fLock)
  273. {
  274. if(fLock)
  275. InterlockedIncrement( &gulcInstances );
  276. else
  277. InterlockedDecrement( &gulcInstances );
  278. return(S_OK);
  279. }