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.

195 lines
3.3 KiB

  1. //
  2. // Copyright 1997 - Microsoft
  3. //
  4. //
  5. // CFACTORY.CPP - Class Factory Object
  6. //
  7. #include "pch.h"
  8. DEFINE_MODULE("IMADMUI")
  9. DEFINE_THISCLASS("CFactory")
  10. #define THISCLASS CFactory
  11. // ************************************************************************
  12. //
  13. // Constructor / Destructor
  14. //
  15. // ************************************************************************
  16. //
  17. // Constructor
  18. //
  19. THISCLASS::THISCLASS( LPCREATEINST pfn )
  20. {
  21. TraceClsFunc( "CFactory()\n" );
  22. _pfnCreateInstance = pfn;
  23. InterlockIncrement( g_cObjects );
  24. TraceFuncExit();
  25. }
  26. STDMETHODIMP
  27. THISCLASS::Init( )
  28. {
  29. TraceClsFunc( "Init()\n");
  30. //
  31. // IUnknown stuff
  32. //
  33. Assert( _cRef == 0 );
  34. // Build QI Table
  35. BEGIN_QITABLE_IMP( CFactory, IClassFactory );
  36. QITABLE_IMP( IClassFactory );
  37. END_QITABLE_IMP( CFactory );
  38. // Add one count
  39. AddRef( );
  40. //
  41. // Private Members
  42. //
  43. HRETURN(S_OK);
  44. };
  45. //
  46. // Destructor
  47. //
  48. THISCLASS::~THISCLASS( )
  49. {
  50. TraceClsFunc( "~CFactory()\n" );
  51. InterlockDecrement( g_cObjects );
  52. TraceFuncExit();
  53. };
  54. // ************************************************************************
  55. //
  56. // IUnknown
  57. //
  58. // ************************************************************************
  59. //
  60. // QueryInterface()
  61. //
  62. STDMETHODIMP
  63. THISCLASS::QueryInterface(
  64. REFIID riid,
  65. LPVOID *ppv )
  66. {
  67. TraceClsFunc( "" );
  68. HRESULT hr = ::QueryInterface( this, _QITable, riid, ppv );
  69. QIRETURN( hr, riid );
  70. }
  71. //
  72. // AddRef()
  73. //
  74. STDMETHODIMP_(ULONG)
  75. THISCLASS::AddRef( void )
  76. {
  77. TraceClsFunc( "[IUnknown] AddRef( )\n" );
  78. InterlockIncrement( _cRef );
  79. RETURN(_cRef);
  80. }
  81. //
  82. // Release()
  83. //
  84. STDMETHODIMP_(ULONG)
  85. THISCLASS::Release( void )
  86. {
  87. TraceClsFunc( "[IUnknown] Release( )\n" );
  88. InterlockDecrement( _cRef );
  89. if ( _cRef )
  90. RETURN(_cRef);
  91. TraceDo( delete this );
  92. RETURN(0);
  93. }
  94. // ************************************************************************
  95. //
  96. // IClassFactory
  97. //
  98. // ************************************************************************
  99. //
  100. // CreateInstance()
  101. //
  102. STDMETHODIMP
  103. THISCLASS::
  104. CreateInstance(
  105. IUnknown *pUnkOuter,
  106. REFIID riid,
  107. void **ppv )
  108. {
  109. TraceClsFunc( "[IClassFactory] CreateInstance()\n" );
  110. if ( !ppv )
  111. RRETURN(E_POINTER);
  112. *ppv = NULL;
  113. HRESULT hr = E_NOINTERFACE;
  114. IUnknown * pUnk = NULL;
  115. if ( NULL != pUnkOuter )
  116. {
  117. hr = THR(CLASS_E_NOAGGREGATION);
  118. goto Cleanup;
  119. }
  120. Assert( _pfnCreateInstance != NULL );
  121. TraceMsgDo( pUnk = (IUnknown *) _pfnCreateInstance( ), "0x%08x" );
  122. if ( !pUnk )
  123. {
  124. hr = THR(E_OUTOFMEMORY);
  125. goto Cleanup;
  126. }
  127. TraceMsgDo( hr = pUnk->QueryInterface( riid, ppv ), "0x%08x" );
  128. Cleanup:
  129. if ( !!pUnk )
  130. {
  131. ULONG cRef;
  132. TraceMsgDo( cRef = pUnk->Release( ), "%u" );
  133. }
  134. HRETURN(hr);
  135. }
  136. //
  137. // LockServer()
  138. //
  139. STDMETHODIMP
  140. THISCLASS::
  141. LockServer( BOOL fLock )
  142. {
  143. TraceClsFunc( "[IClassFactory] LockServer()\n");
  144. if ( fLock )
  145. {
  146. InterlockIncrement( g_cLock );
  147. }
  148. else
  149. {
  150. InterlockDecrement( g_cLock );
  151. }
  152. HRETURN(S_OK);
  153. }