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.

157 lines
4.1 KiB

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