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.

160 lines
3.9 KiB

  1. //+---------------------------------------------------------------------
  2. //
  3. // File: stdfact.cxx
  4. //
  5. // Contents: Standard IClassFactory implementation
  6. //
  7. // Classes: StdClassFactory
  8. //
  9. //----------------------------------------------------------------------
  10. #include "headers.hxx"
  11. #pragma hdrstop
  12. //+---------------------------------------------------------------
  13. //
  14. // Member: StdClassFactory::StdClassFactory, public
  15. //
  16. // Synopsis: Constructor for StdUnknown class
  17. //
  18. //----------------------------------------------------------------
  19. StdClassFactory::StdClassFactory(void)
  20. {
  21. _ulRefs = 0;
  22. _ulLocks = 0;
  23. }
  24. //+---------------------------------------------------------------
  25. //
  26. // Member: StdClassFactory::AddRef, public
  27. //
  28. // Synopsis: Method of IUnknown interface
  29. //
  30. //----------------------------------------------------------------
  31. STDMETHODIMP_(ULONG)
  32. StdClassFactory::AddRef(void)
  33. {
  34. return ++_ulRefs;
  35. }
  36. //+---------------------------------------------------------------
  37. //
  38. // Member: StdClassFactory::Release, public
  39. //
  40. // Synopsis: Method of IUnknown interface
  41. //
  42. //----------------------------------------------------------------
  43. STDMETHODIMP_(ULONG)
  44. StdClassFactory::Release(void)
  45. {
  46. Assert(_ulRefs > 0);
  47. --_ulRefs;
  48. #if DBG
  49. if(_ulRefs == 0)
  50. DOUT(TEXT("StdClassFactory::Release _ulRefs == 0\r\n"));
  51. #endif
  52. return _ulRefs;
  53. }
  54. //+---------------------------------------------------------------
  55. //
  56. // Member: StdClassFactory::QueryInterface, public
  57. //
  58. // Synopsis: Method of IUnknown interface
  59. //
  60. //----------------------------------------------------------------
  61. STDMETHODIMP
  62. StdClassFactory::QueryInterface(REFIID riid, LPVOID FAR* ppv)
  63. {
  64. #if DBG
  65. TCHAR achBuffer[256];
  66. wsprintf(achBuffer,
  67. TEXT("StdClassFactory::QueryInterface (%lx)\r\n"),
  68. riid.Data1);
  69. DOUT(achBuffer);
  70. #endif
  71. if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_IClassFactory))
  72. {
  73. AddRef();
  74. *ppv = (LPCLASSFACTORY)this;
  75. return NOERROR;
  76. }
  77. *ppv = NULL;
  78. DOUT(TEXT("StdClassFactory::QueryInterface returning E_NOINTERFACE\r\n"));
  79. return E_NOINTERFACE;
  80. }
  81. //+---------------------------------------------------------------
  82. //
  83. // Member: StdClassFactory::LockServer, public
  84. //
  85. // Synopsis: Method of IClassFactory interface
  86. //
  87. //----------------------------------------------------------------
  88. STDMETHODIMP
  89. StdClassFactory::LockServer (BOOL fLock)
  90. {
  91. if (fLock)
  92. {
  93. _ulLocks++;
  94. }
  95. else
  96. {
  97. Assert(_ulLocks > 0);
  98. _ulLocks--;
  99. }
  100. return NOERROR;
  101. }
  102. #ifdef DOCGEN
  103. //+---------------------------------------------------------------
  104. //
  105. // Member: StdClassFactory::CreateInstance, public
  106. //
  107. // Synopsis: Manufactures an instance of the class
  108. //
  109. // Notes: This pure virtual function must be overridden by the inheriting
  110. // class because the base class does not know what class to
  111. // instantiate.
  112. //
  113. //----------------------------------------------------------------
  114. STDMETHODIMP
  115. StdClassFactory::CreateInstance(LPUNKNOWN pUnkOuter,
  116. REFIID iid,
  117. LPVOID FAR* ppv) {};
  118. //REVIEW: how to enforce ref counting of Class factory in object
  119. // constructor/destructor? Can we do this in a conjunction of StdUnknown
  120. // with StdClassFactory.
  121. #endif // DOCGEN
  122. //+---------------------------------------------------------------
  123. //
  124. // Member: StdClassFactory::CanUnload, public
  125. //
  126. // Synopsis: Returns TRUE iff there are no extant instances of
  127. // this class, outstanding references on the class factory,
  128. // or locks on the class factory.
  129. //
  130. // Notes: This function is for use in the standard DllCanUnloadNow
  131. // function.
  132. //
  133. //----------------------------------------------------------------
  134. BOOL
  135. StdClassFactory::CanUnload(void)
  136. {
  137. return _ulRefs == 0 && _ulLocks == 0;
  138. }