00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #if !defined(AFX_COMOBJECT_H__FC590F3A_2FC9_4CF2_A1CB_9F8B9C89CA4F__INCLUDED_)
00023 #define AFX_COMOBJECT_H__FC590F3A_2FC9_4CF2_A1CB_9F8B9C89CA4F__INCLUDED_
00024
00025 #pragma once
00026
00027
00028 class CComObject : public CCmdTarget
00029 {
00030
00031 public:
00032 CComObject();
00033 virtual ~CComObject();
00034
00035 DECLARE_DYNCREATE(CComObject)
00036
00037
00038 public:
00039 BOOL EnableDispatch(REFIID pIID);
00040 LPUNKNOWN GetInterface(REFIID pIID, BOOL bAddRef = FALSE);
00041 LPDISPATCH GetDispatch(BOOL bAddRef = FALSE);
00042
00043
00044 public:
00045 const CLSID* m_pCLSID;
00046 protected:
00047 CMapPtrToPtr m_pDispatchMap;
00048
00049
00050 protected:
00051 STDMETHOD_(ULONG, ComAddRef)(LPUNKNOWN);
00052 STDMETHOD_(ULONG, ComRelease)(LPUNKNOWN);
00053 STDMETHOD(ComQueryInterface)(LPUNKNOWN, REFIID, LPVOID*);
00054 STDMETHOD(ComGetTypeInfoCount)(LPUNKNOWN, UINT FAR*);
00055 STDMETHOD(ComGetTypeInfo)(LPUNKNOWN, UINT, LCID, LPTYPEINFO FAR*);
00056 STDMETHOD(ComGetIDsOfNames)(LPUNKNOWN, REFIID, OLECHAR FAR* FAR*, UINT, LCID lcid, DISPID FAR*);
00057 STDMETHOD(ComInvoke)(LPUNKNOWN, DISPID, REFIID, LCID, WORD, DISPPARAMS FAR*, VARIANT FAR*, EXCEPINFO FAR*, UINT FAR*);
00058
00059 DECLARE_OLETYPELIB(CComObject)
00060
00061 };
00062
00063 class GUIDX
00064 {
00065 public:
00066 static CString Encode(const void * pInGUID);
00067 static bool Decode(LPCTSTR pszIn, LPVOID pOutGUID);
00068 inline static bool Unhex(LPCTSTR psz, LPBYTE pOut);
00069 };
00070
00071
00072
00073 #define DECLARE_DISPATCH() \
00074 STDMETHOD(GetTypeInfoCount)(UINT FAR*); \
00075 STDMETHOD(GetTypeInfo)(UINT, LCID, LPTYPEINFO FAR*); \
00076 STDMETHOD(GetIDsOfNames)(REFIID, OLECHAR FAR* FAR*, UINT, LCID lcid, DISPID FAR*); \
00077 STDMETHOD(Invoke)(DISPID, REFIID, LCID, WORD, DISPPARAMS FAR*, VARIANT FAR*, EXCEPINFO FAR*, UINT FAR*);
00078
00079 #define IMPLEMENT_UNKNOWN(theClass, localClass) \
00080 STDMETHODIMP_(ULONG) theClass##::X##localClass##::AddRef() \
00081 { \
00082 METHOD_PROLOGUE(theClass, localClass) \
00083 return pThis->ExternalAddRef(); \
00084 } \
00085 STDMETHODIMP_(ULONG) theClass##::X##localClass##::Release() \
00086 { \
00087 METHOD_PROLOGUE(theClass, localClass) \
00088 return pThis->ExternalRelease(); \
00089 } \
00090 STDMETHODIMP theClass##::X##localClass##::QueryInterface(REFIID iid, LPVOID* ppvObj) \
00091 { \
00092 METHOD_PROLOGUE(theClass, localClass) \
00093 return pThis->ExternalQueryInterface( &iid, ppvObj ); \
00094 }
00095
00096 #define IMPLEMENT_DISPATCH_UNKNOWN(theClass, localClass) \
00097 STDMETHODIMP_(ULONG) theClass##::X##localClass##::AddRef() \
00098 { \
00099 METHOD_PROLOGUE(theClass, localClass) \
00100 return pThis->ComAddRef( this ); \
00101 } \
00102 STDMETHODIMP_(ULONG) theClass##::X##localClass##::Release() \
00103 { \
00104 METHOD_PROLOGUE(theClass, localClass) \
00105 return pThis->ComRelease( this ); \
00106 } \
00107 STDMETHODIMP theClass##::X##localClass##::QueryInterface(REFIID iid, LPVOID* ppvObj) \
00108 { \
00109 METHOD_PROLOGUE(theClass, localClass) \
00110 return pThis->ComQueryInterface( this, iid, ppvObj ); \
00111 }
00112
00113 #define IMPLEMENT_DISPATCH_DISPATCH(theClass, localClass) \
00114 STDMETHODIMP theClass##::X##localClass##::GetTypeInfoCount(UINT FAR* pctinfo) \
00115 { \
00116 METHOD_PROLOGUE(theClass, localClass) \
00117 return pThis->ComGetTypeInfoCount( this, pctinfo ); \
00118 } \
00119 STDMETHODIMP theClass##::X##localClass##::GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo FAR* FAR* pptinfo) \
00120 { \
00121 METHOD_PROLOGUE(theClass, localClass) \
00122 return pThis->ComGetTypeInfo( this, itinfo, lcid, pptinfo ); \
00123 } \
00124 STDMETHODIMP theClass##::X##localClass##::GetIDsOfNames(REFIID riid, OLECHAR FAR* FAR* rgszNames, UINT cNames, LCID lcid, DISPID FAR* rgdispid) \
00125 { \
00126 METHOD_PROLOGUE(theClass, localClass) \
00127 return pThis->ComGetIDsOfNames( this, riid, rgszNames, cNames, lcid, rgdispid ); \
00128 } \
00129 STDMETHODIMP theClass##::X##localClass##::Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS FAR* pdispparams, VARIANT FAR* pvarResult, EXCEPINFO FAR* pexcepinfo, UINT FAR* puArgErr) \
00130 { \
00131 METHOD_PROLOGUE(theClass, localClass) \
00132 return pThis->ComInvoke( this, dispidMember, riid, lcid, wFlags, pdispparams, pvarResult, pexcepinfo, puArgErr ); \
00133 } \
00134
00135 #define IMPLEMENT_DISPATCH(theClass, localClass) \
00136 IMPLEMENT_DISPATCH_UNKNOWN(theClass, localClass) \
00137 IMPLEMENT_DISPATCH_DISPATCH(theClass, localClass)
00138
00139 #define INTERFACE_TO_CLASS(icClass, icInterface, icIn, icOut) \
00140 icClass * icOut = (icClass *)( (BYTE*) icIn - offsetof( icClass, m_x##icInterface ) );
00141
00142 #endif // !defined(AFX_COMOBJECT_H__FC590F3A_2FC9_4CF2_A1CB_9F8B9C89CA4F__INCLUDED_)