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.

127 lines
2.6 KiB

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