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.

133 lines
2.7 KiB

  1. //+-------------------------------------------------------------------
  2. //
  3. // File: actcf.cxx
  4. //
  5. // Contents: object activation test class factory
  6. //
  7. // Classes: CActClassFactory
  8. //
  9. // Functions:
  10. //
  11. // History: 23-Nov-92 Ricksa Created
  12. //
  13. //--------------------------------------------------------------------
  14. #include <pch.cxx>
  15. #pragma hdrstop
  16. #include <actcf.hxx> // CActClassFactory
  17. #include <cact.hxx> // CTestAct
  18. const GUID CLSID_TestSingleUse =
  19. {0x99999999,0x0000,0x0008,{0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x50}};
  20. const GUID CLSID_TestMultipleUse =
  21. {0x99999999,0x0000,0x0008,{0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x51}};
  22. const GUID CLSID_DistBind =
  23. {0x99999999,0x0000,0x0008,{0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x55}};
  24. CActClassFactory::CActClassFactory(REFCLSID rclsid, BOOL fServer)
  25. : _fServer(fServer), _clsid(rclsid), _cRefs(1), _cLocks(0)
  26. {
  27. // Header does all the work
  28. }
  29. CActClassFactory::~CActClassFactory()
  30. {
  31. // Default actions are enough
  32. }
  33. STDMETHODIMP CActClassFactory::QueryInterface(REFIID iid, void FAR * FAR * ppv)
  34. {
  35. if (IsEqualIID(iid, IID_IUnknown) ||
  36. IsEqualIID(iid, IID_IClassFactory))
  37. {
  38. *ppv = (IUnknown *) this;
  39. AddRef();
  40. return S_OK;
  41. }
  42. *ppv = NULL;
  43. return E_NOINTERFACE;
  44. }
  45. STDMETHODIMP_(ULONG) CActClassFactory::AddRef(void)
  46. {
  47. InterlockedIncrement(&_cRefs);
  48. if (!_fServer)
  49. {
  50. // This is not being used in a server so we want to bump the
  51. // reference count. In a server we use the lock count rather
  52. // than the reference count to tell whether we should go away.
  53. GlobalRefs(TRUE);
  54. }
  55. return _cRefs;
  56. }
  57. STDMETHODIMP_(ULONG) CActClassFactory::Release(void)
  58. {
  59. BOOL fKeepObject = InterlockedDecrement(&_cRefs);
  60. if (!_fServer)
  61. {
  62. // This is not being used in a server so we want to bump the
  63. // reference count. In a server we use the lock count rather
  64. // than the reference count to tell whether we should go away.
  65. GlobalRefs(FALSE);
  66. }
  67. if (!fKeepObject)
  68. {
  69. delete this;
  70. return 0;
  71. }
  72. return _cRefs;
  73. }
  74. STDMETHODIMP CActClassFactory::CreateInstance(
  75. IUnknown FAR* pUnkOuter,
  76. REFIID iidInterface,
  77. void FAR* FAR* ppv)
  78. {
  79. if (pUnkOuter != NULL)
  80. {
  81. // Object does not support aggregation
  82. return E_NOINTERFACE;
  83. }
  84. CTestAct *ptballs = new CTestAct(_clsid);
  85. HRESULT hr = ptballs->QueryInterface(iidInterface, ppv);
  86. ptballs->Release();
  87. return hr;
  88. }
  89. STDMETHODIMP CActClassFactory::LockServer(BOOL fLock)
  90. {
  91. if (fLock)
  92. {
  93. InterlockedIncrement(&_cLocks);
  94. GlobalRefs(TRUE);
  95. }
  96. else
  97. {
  98. InterlockedDecrement(&_cLocks);
  99. GlobalRefs(FALSE);
  100. }
  101. return S_OK;
  102. }