FEBDispatch.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. //
  24. // FEBDispatch class is a template class which, when inherited from, can implement the
  25. // IDispatch for a COM object with a type library.
  26. //
  27. #ifndef _FEBDISPATCH_H__
  28. #define _FEBDISPATCH_H__
  29. #include <atlbase.h>
  30. extern CComModule _Module;
  31. #include <atlcom.h>
  32. #include <comutil.h> // For _bstr_t.
  33. #include "oleauto.h"
  34. template <class T, class C, const IID *I>
  35. class FEBDispatch :
  36. public CComObjectRootEx<CComSingleThreadModel>,
  37. public CComCoClass<T>,
  38. public C
  39. {
  40. public:
  41. BEGIN_COM_MAP(T)
  42. COM_INTERFACE_ENTRY(C)
  43. COM_INTERFACE_ENTRY_AGGREGATE(IID_IDispatch, m_dispatch)
  44. END_COM_MAP()
  45. FEBDispatch()
  46. {
  47. m_ptinfo = NULL;
  48. m_dispatch = NULL;
  49. ITypeLib *ptlib;
  50. HRESULT hr;
  51. HRESULT TypeLibraryLoadResult;
  52. char filename[256];
  53. GetModuleFileName(NULL, filename, sizeof(filename));
  54. _bstr_t bstr(filename);
  55. TypeLibraryLoadResult = LoadTypeLib(bstr, &ptlib);
  56. DEBUG_ASSERTCRASH(TypeLibraryLoadResult == 0, ("Can't load type library for Embedded Browser"));
  57. if (TypeLibraryLoadResult == S_OK)
  58. {
  59. hr = ptlib->GetTypeInfoOfGuid(*I, &m_ptinfo);
  60. ptlib->Release();
  61. if (hr == S_OK)
  62. {
  63. hr = CreateStdDispatch(static_cast<IUnknown*>(this), static_cast<C*>(this), m_ptinfo, &m_dispatch);
  64. m_dispatch->AddRef();
  65. // Don't release the IUnknown from CreateStdDispatch without calling AddRef.
  66. // It looks like CreateStdDispatch doesn't call AddRef on the IUnknown it returns.
  67. }
  68. }
  69. if ( (m_dispatch == NULL) )
  70. {
  71. DEBUG_LOG(("Error creating Dispatch for Web interface\n"));
  72. }
  73. }
  74. virtual ~FEBDispatch()
  75. {
  76. if (m_ptinfo)
  77. m_ptinfo->Release();
  78. if (m_dispatch)
  79. m_dispatch->Release();
  80. }
  81. IUnknown *m_dispatch;
  82. private:
  83. ITypeInfo *m_ptinfo;
  84. };
  85. #endif