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.

241 lines
5.8 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1994
  5. //
  6. // File: dsocf.cxx
  7. //
  8. // Contents: Class factory for ole-db DSO
  9. //
  10. // History: 6-Jan-1997 MarkZ Created
  11. //
  12. //--------------------------------------------------------------------------
  13. #include <pch.cxx>
  14. #pragma hdrstop
  15. #include "dsocf.hxx"
  16. #include "datasrc.hxx"
  17. //
  18. // We keep count of the number of filter objects that we've created
  19. // to let OLE know when this DLL is finally free.
  20. //
  21. extern long gulcInstances;
  22. // {F9AE8980-7E52-11d0-8964-00C04FD611D7 }
  23. extern "C" const GUID CLSID_CiFwDSO = CLSID_INDEX_SERVER_DSO;
  24. //+-------------------------------------------------------------------------
  25. //
  26. // Method: CDataSrcObjectCF::CDataSrcObjectCF
  27. //
  28. // Synopsis: DSO class factory constructor
  29. //
  30. // History: 6-Jan-1997 MarkZ Created
  31. //
  32. //+-------------------------------------------------------------------------
  33. CDataSrcObjectCF::CDataSrcObjectCF()
  34. : _RefCount( 1 )
  35. {
  36. InterlockedIncrement( &gulcInstances );
  37. END_CONSTRUCTION ( CDataSrcObjectCF );
  38. }
  39. //+-------------------------------------------------------------------------
  40. //
  41. // Method: CDataSrcObjectCF::~CDataSrcObjectCF()
  42. //
  43. // Synopsis: DSO class factory destructor
  44. //
  45. // History: 6-Jan-1997 MarkZ Created
  46. //
  47. //--------------------------------------------------------------------------
  48. CDataSrcObjectCF::~CDataSrcObjectCF()
  49. {
  50. Win4Assert( _RefCount == 0);
  51. Win4Assert( gulcInstances != 0 );
  52. InterlockedDecrement( &gulcInstances );
  53. }
  54. //+---------------------------------------------------------------------------
  55. //
  56. // IUnknown method implementations
  57. //
  58. //----------------------------------------------------------------------------
  59. //+-------------------------------------------------------------------------
  60. //
  61. // Method: CDataSrcObjectCF::AddRef()
  62. //
  63. // Synopsis: Increments refcount
  64. //
  65. // History: 6-Jan-1997 markz Created
  66. //
  67. //--------------------------------------------------------------------------
  68. ULONG STDMETHODCALLTYPE CDataSrcObjectCF::AddRef()
  69. {
  70. return InterlockedIncrement( &_RefCount );
  71. }
  72. //+-------------------------------------------------------------------------
  73. //
  74. // Method: CDataSrcObjectCF::Release
  75. //
  76. // Synopsis: Decrement refcount. Delete if necessary.
  77. //
  78. // History: 6-Jan-1997 markz Created
  79. //
  80. //--------------------------------------------------------------------------
  81. ULONG STDMETHODCALLTYPE CDataSrcObjectCF::Release()
  82. {
  83. Win4Assert( _RefCount != 0 );
  84. LONG RefCount = InterlockedDecrement( &_RefCount );
  85. if ( RefCount <= 0 )
  86. delete this;
  87. return (ULONG) RefCount;
  88. } // Release
  89. //+-------------------------------------------------------------------------
  90. //
  91. // Method: CDataSrcObjectCF::QueryInterface
  92. //
  93. // Synopsis: Rebind to other interface
  94. //
  95. // Arguments: [riid] -- IID of new interface
  96. // [ppvObject] -- New interface * returned here
  97. //
  98. // Returns: S_OK if bind succeeded, E_NOINTERFACE if bind failed
  99. //
  100. // History: 6-Jan-1997 MarkZ Created
  101. // 01-30-98 danleg return E_INVALIDARG if ppvObject is bad
  102. //
  103. //--------------------------------------------------------------------------
  104. STDMETHODIMP CDataSrcObjectCF::QueryInterface(
  105. REFIID riid,
  106. PVOID* ppvObject )
  107. {
  108. if ( !ppvObject )
  109. return E_INVALIDARG;
  110. if ( IID_IUnknown == riid )
  111. {
  112. AddRef( );
  113. *ppvObject = (PVOID) ((IUnknown *) this );
  114. return S_OK;
  115. }
  116. else if ( IID_IClassFactory == riid)
  117. {
  118. AddRef( );
  119. *ppvObject = (PVOID) ((IClassFactory *) this );
  120. return S_OK;
  121. }
  122. else
  123. {
  124. *ppvObject = 0;
  125. return E_NOINTERFACE;
  126. }
  127. }
  128. //+-------------------------------------------------------------------------
  129. //
  130. // Method: CDataSrcObjectCF::CreateInstance
  131. //
  132. // Synopsis: Create new DSO instance
  133. //
  134. // Arguments: [pUnkOuter] -- 'Outer' IUnknown; IGNORED
  135. // [riid] -- Interface to bind
  136. // [ppvObject] -- Interface returned here
  137. //
  138. // History: 6-Jan-1997 MarkZ Created
  139. //
  140. //--------------------------------------------------------------------------
  141. STDMETHODIMP CDataSrcObjectCF::CreateInstance(
  142. IUnknown * pUnkOuter,
  143. REFIID riid,
  144. PVOID * ppvObject )
  145. {
  146. CDataSrc * pDataSrc = 0;
  147. SCODE sc = S_OK;
  148. if (!ppvObject)
  149. return ResultFromScode(E_INVALIDARG);
  150. if( pUnkOuter && riid != IID_IUnknown )
  151. return ResultFromScode(E_NOINTERFACE);
  152. TRANSLATE_EXCEPTIONS;
  153. TRY
  154. {
  155. //
  156. // Create the new object
  157. //
  158. XInterface<IUnknown> xInnerUnk;
  159. pDataSrc = new CDataSrc( pUnkOuter, xInnerUnk.GetPPointer() );
  160. //
  161. // Obtain the new interface. NOTE: pDatasrc is the same object as xInnerUnk
  162. //
  163. sc = xInnerUnk->QueryInterface( riid , ppvObject );
  164. }
  165. CATCH(CException, e)
  166. {
  167. Win4Assert( 0 == pDataSrc );
  168. switch( e.GetErrorCode() )
  169. {
  170. case E_OUTOFMEMORY:
  171. sc = E_OUTOFMEMORY;
  172. break;
  173. default:
  174. sc = E_UNEXPECTED;
  175. }
  176. }
  177. END_CATCH;
  178. UNTRANSLATE_EXCEPTIONS;
  179. return (sc);
  180. }
  181. //+-------------------------------------------------------------------------
  182. //
  183. // Method: CDataSrcObjectCF::LockServer
  184. //
  185. // Synopsis: Force class factory to remain loaded
  186. //
  187. // Arguments: [fLock] -- TRUE if locking, FALSE if unlocking
  188. //
  189. // Returns: S_OK
  190. //
  191. // History: 6-Jan-1997 MarkZ Created
  192. //
  193. //--------------------------------------------------------------------------
  194. STDMETHODIMP CDataSrcObjectCF::LockServer( BOOL fLock )
  195. {
  196. if (fLock)
  197. InterlockedIncrement( &gulcInstances );
  198. else
  199. InterlockedDecrement( &gulcInstances );
  200. return(S_OK);
  201. }