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.

147 lines
3.6 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // File: CLSSFACT.CPP
  4. //
  5. // Implements a class factory object that creates CPropSheetExt objects.
  6. //
  7. //---------------------------------------------------------------------------
  8. #include "clssfact.h"
  9. extern ULONG g_cObj; // See PLUSTAB.CPP
  10. extern ULONG g_cLock; // See PLUSTAB.CPP
  11. //---------------------------------------------------------------------------
  12. // ObjectDestroyed()
  13. //
  14. // Function for the CPropSheetExt object to call when it is destroyed.
  15. // Because we're in a DLL, we only track the number of objects here,
  16. // letting DllCanUnloadNow take care of the rest.
  17. //---------------------------------------------------------------------------
  18. void FAR PASCAL ObjectDestroyed( void )
  19. {
  20. g_cObj--;
  21. return;
  22. }
  23. //---------------------------------------------------------------------------
  24. // Class Member functions
  25. //---------------------------------------------------------------------------
  26. //---------------------------------------------------------------------------
  27. // Constructor
  28. //---------------------------------------------------------------------------
  29. CClassFactory::CClassFactory()
  30. {
  31. m_cRef = 0L;
  32. return;
  33. }
  34. //---------------------------------------------------------------------------
  35. // Destructor
  36. //---------------------------------------------------------------------------
  37. CClassFactory::~CClassFactory( void )
  38. {
  39. return;
  40. }
  41. //---------------------------------------------------------------------------
  42. // QueryInterface()
  43. //---------------------------------------------------------------------------
  44. STDMETHODIMP CClassFactory::QueryInterface( REFIID riid, LPVOID* ppv )
  45. {
  46. *ppv = NULL;
  47. //Any interface on this object is the object pointer.
  48. if( IsEqualIID( riid, IID_IUnknown ) || IsEqualIID( riid, IID_IClassFactory ) )
  49. {
  50. *ppv = (LPVOID)this;
  51. ++m_cRef;
  52. return NOERROR;
  53. }
  54. return E_NOINTERFACE;
  55. }
  56. //---------------------------------------------------------------------------
  57. // AddRef()
  58. //---------------------------------------------------------------------------
  59. STDMETHODIMP_(ULONG) CClassFactory::AddRef()
  60. {
  61. return ++m_cRef;
  62. }
  63. //---------------------------------------------------------------------------
  64. // Release()
  65. //---------------------------------------------------------------------------
  66. STDMETHODIMP_(ULONG) CClassFactory::Release()
  67. {
  68. ULONG cRefT;
  69. cRefT = --m_cRef;
  70. if( 0L == m_cRef )
  71. delete this;
  72. return cRefT;
  73. }
  74. //---------------------------------------------------------------------------
  75. // CreateInstance()
  76. //---------------------------------------------------------------------------
  77. STDMETHODIMP CClassFactory::CreateInstance( LPUNKNOWN pUnkOuter, REFIID riid, LPVOID FAR *ppvObj )
  78. {
  79. CPropSheetExt* pObj;
  80. HRESULT hr = E_OUTOFMEMORY;
  81. *ppvObj = NULL;
  82. // We don't support aggregation at all.
  83. if( pUnkOuter )
  84. {
  85. return CLASS_E_NOAGGREGATION;
  86. }
  87. //Verify that a controlling unknown asks for IShellPropSheetExt
  88. if( IsEqualIID( riid, IID_IShellPropSheetExt ) )
  89. {
  90. //Create the object, passing function to notify on destruction
  91. pObj = new CPropSheetExt( pUnkOuter, ObjectDestroyed );
  92. if( NULL == pObj )
  93. {
  94. return hr;
  95. }
  96. hr = pObj->QueryInterface( riid, ppvObj );
  97. //Kill the object if initial creation or FInit failed.
  98. if( FAILED(hr) )
  99. {
  100. delete pObj;
  101. }
  102. else
  103. {
  104. g_cObj++;
  105. }
  106. return hr;
  107. }
  108. return E_NOINTERFACE;
  109. }
  110. //---------------------------------------------------------------------------
  111. // LockServer()
  112. //---------------------------------------------------------------------------
  113. STDMETHODIMP CClassFactory::LockServer( BOOL fLock )
  114. {
  115. if( fLock )
  116. {
  117. g_cLock++;
  118. }
  119. else
  120. {
  121. g_cLock--;
  122. }
  123. return NOERROR;
  124. }