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.

151 lines
3.3 KiB

  1. //+-------------------------------------------------------------------
  2. //
  3. // File: ballscf.cxx
  4. //
  5. // Contents: test class factory object implementation
  6. //
  7. // Classes: CBallClassFactory
  8. //
  9. // Functions:
  10. //
  11. // History: 23-Nov-92 Rickhi Created
  12. //
  13. //--------------------------------------------------------------------
  14. #include <pch.cxx>
  15. #pragma hdrstop
  16. #include <ballscf.hxx> // class definiton
  17. #include <cballs.hxx> // CBalls defines
  18. const GUID CLSID_Balls =
  19. {0x0000013a,0x0001,0x0008,{0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46}};
  20. //+-------------------------------------------------------------------
  21. //
  22. // Member: CBallClassFactory::CBallClassFactory, public
  23. //
  24. // Algorithm:
  25. //
  26. // History: 23-Nov-92 Rickhi Created
  27. //
  28. //--------------------------------------------------------------------
  29. CBallClassFactory::CBallClassFactory(IUnknown *punkOuter) :
  30. _punkOuter(punkOuter)
  31. {
  32. ENLIST_TRACKING(CBallClassFactory);
  33. }
  34. //+-------------------------------------------------------------------
  35. //
  36. // Member: CBallClassFactory::~CBallClassFactory, public
  37. //
  38. // Algorithm:
  39. //
  40. // History: 23-Nov-92 Rickhi Created
  41. //
  42. //--------------------------------------------------------------------
  43. CBallClassFactory::~CBallClassFactory(void)
  44. {
  45. // automatic actions do the rest of the work
  46. }
  47. //+-------------------------------------------------------------------
  48. //
  49. // Member: CBallClassFactory::QueryInterface, public
  50. //
  51. // Algorithm: if the interface is not one implemented by us,
  52. // pass the request to the proxy manager
  53. //
  54. // History: 23-Nov-92 Rickhi Created
  55. //
  56. //--------------------------------------------------------------------
  57. STDMETHODIMP CBallClassFactory::QueryInterface(REFIID riid, void **ppUnk)
  58. {
  59. SCODE sc = S_OK;
  60. if (IsEqualIID(riid, IID_IUnknown) ||
  61. IsEqualIID(riid, IID_IClassFactory))
  62. {
  63. *ppUnk = (void *)(IClassFactory *) this;
  64. AddRef();
  65. }
  66. else
  67. {
  68. if (_punkOuter)
  69. {
  70. sc = _punkOuter->QueryInterface(riid, ppUnk);
  71. }
  72. else
  73. {
  74. *ppUnk = NULL;
  75. sc = E_NOINTERFACE;
  76. }
  77. }
  78. return sc;
  79. }
  80. //+-------------------------------------------------------------------
  81. //
  82. // Member: CBallClassFactory::CreateInstance, public
  83. //
  84. // Synopsis: create a new object with the same class
  85. //
  86. // History: 23-Nov-92 Rickhi Created
  87. //
  88. //--------------------------------------------------------------------
  89. STDMETHODIMP CBallClassFactory::CreateInstance(IUnknown *punkOuter,
  90. REFIID riid,
  91. void **ppunkObject)
  92. {
  93. SCODE sc = E_OUTOFMEMORY;
  94. *ppunkObject = NULL; // in case of failure
  95. // create a ball object.
  96. IUnknown *punk = (IUnknown *) new CBallCtrlUnk(punkOuter);
  97. if (punk)
  98. {
  99. // get the interface the caller wants to use
  100. sc = punk->QueryInterface(riid, ppunkObject);
  101. // release our hold on the ball, since the QI got a hold for
  102. // the client.
  103. punk->Release();
  104. }
  105. return sc;
  106. }
  107. //+-------------------------------------------------------------------
  108. //
  109. // Member: CBallClassFactory::LockServer, public
  110. //
  111. // Synopsis: create a new object with the same class
  112. //
  113. // History: 23-Nov-92 Rickhi Created
  114. //
  115. //--------------------------------------------------------------------
  116. STDMETHODIMP CBallClassFactory::LockServer(BOOL fLock)
  117. {
  118. if (fLock)
  119. GlobalRefs(TRUE);
  120. else
  121. GlobalRefs(FALSE);
  122. return S_OK;
  123. }