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.

161 lines
5.2 KiB

  1. /*++
  2. Copyright (c) 1998-1999 Microsoft Corporation
  3. Module Name:
  4. tapibase.h
  5. Abstract:
  6. Declaration of the CTAPIComObjectRoot template
  7. Author:
  8. mquinton 09-23-98
  9. Notes:
  10. Revision History:
  11. --*/
  12. #ifndef __TAPIBASE_H__
  13. #define __TAPIBASE_H__
  14. template <class base, class CComThreadingModel = CComMultiThreadModel>
  15. class CTAPIComObjectRoot :
  16. public CComObjectRootEx<CComThreadingModel>
  17. {
  18. protected:
  19. IUnknown * m_pFTM;
  20. public:
  21. CTAPIComObjectRoot()
  22. {
  23. m_pFTM = NULL;
  24. }
  25. ~CTAPIComObjectRoot()
  26. {
  27. //
  28. // release the free threaded marshaller
  29. //
  30. if ( NULL != m_pFTM )
  31. {
  32. m_pFTM->Release();
  33. }
  34. }
  35. //virtual HRESULT WINAPI IMarshalQI( void * pv, REFIID riid, LPVOID * ppv, DWORD_PTR dw )= 0;
  36. };
  37. template <class base>
  38. class CTAPIComDispatchObject :
  39. public CComObjectRootEx<CComMultiThreadModel>,
  40. public IDispatch
  41. {
  42. protected:
  43. base * m_pBase;
  44. public:
  45. virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, void **ppvObject);
  46. virtual ULONG STDMETHODCALLTYPE AddRef();
  47. virtual ULONG STDMETHODCALLTYPE Release();
  48. void Initialize( base * p )
  49. {
  50. m_pBase = p;
  51. m_pBase->AddRef();
  52. }
  53. void helpme()
  54. {
  55. const _ATL_INTMAP_ENTRY* pEntries = m_pBase->_GetEntries();
  56. while ( pEntries->pFunc != NULL )
  57. {
  58. if (pEntries->pFunc == _ATL_SIMPLEMAPENTRY)
  59. {
  60. IDispatch * pDisp = (IDispatch*)((LONG_PTR)m_pBase+pEntries->dw);
  61. }
  62. pEntries++;
  63. }
  64. }
  65. STDMETHOD(GetTypeInfoCount)(UINT * pctinfo);
  66. STDMETHOD(GetTypeInfo)(
  67. UINT iTInfo,
  68. LCID lcid,
  69. ITypeInfo ** ppTInfo
  70. );
  71. STDMETHOD(GetIDsOfNames)(
  72. REFIID riid,
  73. LPOLESTR * rgszNames,
  74. UINT cNames,
  75. LCID lcid,
  76. DISPID * rgDispId
  77. );
  78. STDMETHOD(Invoke)(
  79. DISPID dispIdMember,
  80. REFIID riid,
  81. LCID lcid,
  82. WORD wFlags,
  83. DISPPARAMS * pDispParams,
  84. VARIANT * pVarResult,
  85. EXCEPINFO * pExcepInfo,
  86. UINT * puArgErr
  87. );
  88. };
  89. #define DECLARE_MARSHALQI(__base__) \
  90. static HRESULT WINAPI IMarshalQI( void * pv, REFIID riid, LPVOID * ppv, DWORD_PTR dw ) \
  91. { \
  92. HRESULT hr; \
  93. IUnknown * pUnk; \
  94. \
  95. __base__ * pObject = (__base__ *)pv; \
  96. \
  97. *ppv = NULL; \
  98. \
  99. pObject->Lock(); \
  100. \
  101. if ( NULL == pObject->m_pFTM ) \
  102. { \
  103. pObject->_InternalQueryInterface(IID_IUnknown, (void **)&pUnk); \
  104. \
  105. hr = CoCreateFreeThreadedMarshaler( \
  106. pUnk, \
  107. &(pObject->m_pFTM) \
  108. ); \
  109. \
  110. pUnk->Release(); \
  111. \
  112. if ( !SUCCEEDED(hr) ) \
  113. { \
  114. pObject->Unlock(); \
  115. \
  116. return E_NOINTERFACE; \
  117. } \
  118. } \
  119. \
  120. pObject->Unlock(); \
  121. \
  122. return S_FALSE; \
  123. } \
  124. #endif