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.

152 lines
4.0 KiB

  1. //+-------------------------------------------------------------------
  2. //
  3. // File: mixedcf.cxx
  4. //
  5. // Contents: class factory object implementation for implementing
  6. // multiple classes in the same factory code.
  7. //
  8. // Classes: CMixedClassFactory
  9. //
  10. // History: 23-Nov-92 Rickhi Created
  11. //
  12. //--------------------------------------------------------------------
  13. #include <pch.cxx>
  14. #pragma hdrstop
  15. #include <mixedcf.hxx> // class definiton
  16. #include <cqi.hxx> // CQI
  17. #include <cballs.hxx> // CBallCtrlUnk
  18. #include <ccubes.hxx> // CCubes
  19. #include <cloop.hxx> // CLoop
  20. #if 0 // These are defined in the header files, but left here for reference.
  21. const GUID CLSID_QI =
  22. {0x00000140,0x0000,0x0008,{0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46}};
  23. const GUID CLSID_QIHANDLER =
  24. {0x00000141,0x0000,0x0008,{0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46}};
  25. const GUID CLSID_Balls =
  26. {0x0000013a,0x0001,0x0008,{0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46}};
  27. const GUID CLSID_Loop =
  28. {0x0000013c,0x0001,0x0008,{0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46}};
  29. #endif
  30. const GUID CLSID_Cubes =
  31. {0x0000013b,0x0001,0x0008,{0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46}};
  32. //+-------------------------------------------------------------------
  33. //
  34. // Member: CMixedClassFactory::CMixedClassFactory, public
  35. //
  36. // History: 23-Nov-92 Rickhi Created
  37. //
  38. //--------------------------------------------------------------------
  39. CMixedClassFactory::CMixedClassFactory(REFCLSID rclsid) : _clsid(rclsid)
  40. {
  41. ENLIST_TRACKING(CMixedClassFactory);
  42. }
  43. //+-------------------------------------------------------------------
  44. //
  45. // Member: CMixedClassFactory::~CMixedClassFactory, public
  46. //
  47. // History: 23-Nov-92 Rickhi Created
  48. //
  49. //--------------------------------------------------------------------
  50. CMixedClassFactory::~CMixedClassFactory(void)
  51. {
  52. // automatic actions do the rest of the work
  53. }
  54. //+-------------------------------------------------------------------
  55. //
  56. // Member: CMixedClassFactory::QueryInterface, public
  57. //
  58. // Algorithm: if the interface is not one implemented by us,
  59. // pass the request to the proxy manager
  60. //
  61. // History: 23-Nov-92 Rickhi Created
  62. //
  63. //--------------------------------------------------------------------
  64. STDMETHODIMP CMixedClassFactory::QueryInterface(REFIID riid, void **ppUnk)
  65. {
  66. if (IsEqualIID(riid, IID_IUnknown) ||
  67. IsEqualIID(riid, IID_IClassFactory))
  68. {
  69. *ppUnk = (void *)(IClassFactory *) this;
  70. AddRef();
  71. return S_OK;
  72. }
  73. *ppUnk = NULL;
  74. return E_NOINTERFACE;
  75. }
  76. //+-------------------------------------------------------------------
  77. //
  78. // Member: CMixedClassFactory::CreateInstance, public
  79. //
  80. // Synopsis: create a new object with the same class
  81. //
  82. // History: 23-Nov-92 Rickhi Created
  83. //
  84. //--------------------------------------------------------------------
  85. STDMETHODIMP CMixedClassFactory::CreateInstance(IUnknown *punkOuter,
  86. REFIID riid,
  87. void **ppunkObject)
  88. {
  89. HRESULT hr = E_OUTOFMEMORY;
  90. *ppunkObject = NULL; // in case of failure
  91. // create a new object.
  92. IUnknown *pUnk = NULL;
  93. if (IsEqualCLSID(_clsid, CLSID_QI) ||
  94. IsEqualCLSID(_clsid, CLSID_QIHANDLER))
  95. {
  96. pUnk = (IUnknown *) new CQI(_clsid);
  97. }
  98. else if (IsEqualCLSID(_clsid, CLSID_Balls))
  99. {
  100. pUnk = (IUnknown *) new CBallCtrlUnk(NULL);
  101. }
  102. else if (IsEqualCLSID(_clsid, CLSID_Cubes))
  103. {
  104. pUnk = (IUnknown *) new CCube();
  105. }
  106. else if (IsEqualCLSID(_clsid, CLSID_Loop))
  107. {
  108. pUnk = (IUnknown *) new CLoop();
  109. }
  110. if (pUnk)
  111. {
  112. // get the interface the caller wants to use
  113. hr = pUnk->QueryInterface(riid, ppunkObject);
  114. pUnk->Release();
  115. }
  116. return hr;
  117. }
  118. //+-------------------------------------------------------------------
  119. //
  120. // Member: CMixedClassFactory::LockServer, public
  121. //
  122. // Synopsis: create a new object with the same class
  123. //
  124. // History: 23-Nov-92 Rickhi Created
  125. //
  126. //--------------------------------------------------------------------
  127. STDMETHODIMP CMixedClassFactory::LockServer(BOOL fLock)
  128. {
  129. if (fLock)
  130. GlobalRefs(TRUE);
  131. else
  132. GlobalRefs(FALSE);
  133. return S_OK;
  134. }