From 7204f9c53f4300503319bac628f9bdf56e9481b9 Mon Sep 17 00:00:00 2001 From: Francois Gouget Date: Tue, 6 Apr 1999 07:06:05 +0000 Subject: [PATCH] Added a new implementation of the ICOM macros that use Microsoft style virtual methods to implement the COM interfaces in C++. --- include/wine/obj_base.h | 148 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 143 insertions(+), 5 deletions(-) diff --git a/include/wine/obj_base.h b/include/wine/obj_base.h index 48a05ab0c37..4bbca39fffb 100644 --- a/include/wine/obj_base.h +++ b/include/wine/obj_base.h @@ -312,6 +312,11 @@ inline BOOL operator!=(const GUID& guidOne, const GUID& guidOther) #ifndef ICOM_CINTERFACE /* C++ interface */ +#ifndef ICOM_VIRTUAL_METHODS +/* Uses these macros, i.e. do not define ICOM_VIRTUAL_METHODS, if your C++ compiler does not generate + * virtual tables with the right layout (i.e. currently most g++ derivatives). + */ + #define ICOM_METHOD(ret,xfn) \ private: ret (CALLBACK *fn##xfn)(ICOM_INTERFACE* me); \ public: inline ret (CALLBACK xfn)(void) { return ((ICOM_INTERFACE*)t.lpvtbl)->fn##xfn(this); }; @@ -468,6 +473,136 @@ inline BOOL operator!=(const GUID& guidOne, const GUID& guidOther) public: inline void (CALLBACK xfn)(ta a,tb b,tc c,td d,te e,tf f,tg g,th h) const { ((ICOM_INTERFACE*)t.lpvtbl)->fn##xfn(this,a,b,c,d,e,f,g,h); }; +#define ICOM_DEFINE(iface,ibase) \ + typedef struct iface: public ibase { \ + iface##_METHODS \ + }; + +#else +/* This case can be used if the layout of the virtual tables generated by the C++ + * compiler matches that of Visual C++. + */ + +#define ICOM_METHOD(ret,xfn) \ + virtual ret (CALLBACK xfn)(void) = 0; + +#define ICOM_METHOD1(ret,xfn,ta,na) \ + virtual ret (CALLBACK xfn)(ta a) = 0; + +#define ICOM_METHOD2(ret,xfn,ta,na,tb,nb) \ + virtual ret (CALLBACK xfn)(ta a,tb b) = 0; + +#define ICOM_METHOD3(ret,xfn,ta,na,tb,nb,tc,nc) \ + virtual ret (CALLBACK xfn)(ta a,tb b,tc c) = 0; + +#define ICOM_METHOD4(ret,xfn,ta,na,tb,nb,tc,nc,td,nd) \ + virtual ret (CALLBACK xfn)(ta a,tb b,tc c,td d) = 0; + +#define ICOM_METHOD5(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne) \ + virtual ret (CALLBACK xfn)(ta a,tb b,tc c,td d,te e) = 0; + +#define ICOM_METHOD6(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf) \ + virtual ret (CALLBACK xfn)(ta a,tb b,tc c,td d,te e,tf f) = 0; + +#define ICOM_METHOD7(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng) \ + virtual ret (CALLBACK xfn)(ta a,tb b,tc c,td d,te e,tf f,tg g) = 0; + +#define ICOM_METHOD8(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng,th,nh) \ + virtual ret (CALLBACK xfn)(ta a,tb b,tc c,td d,te e,tf f,tg g,th h) = 0; + +#define ICOM_METHOD9(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng,th,nh,ti,ni) \ + virtual ret (CALLBACK xfn)(ta a,tb b,tc c,td d,te e,tf f,tg g,th h,ti i) = 0; + +#define ICOM_METHOD10(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng,th,nh,ti,ni,tj,nj) \ + virtual ret (CALLBACK xfn)(ta a,tb b,tc c,td d,te e,tf f,tg g,th h,ti i,tj j) = 0; + + +#define ICOM_CMETHOD(ret,xfn) \ + virtual ret (CALLBACK xfn)(void) const = 0; + +#define ICOM_CMETHOD1(ret,xfn,ta,na) \ + virtual ret (CALLBACK xfn)(ta a) const = 0; + +#define ICOM_CMETHOD2(ret,xfn,ta,na,tb,nb) \ + virtual ret (CALLBACK xfn)(ta a,tb b) const = 0; + +#define ICOM_CMETHOD3(ret,xfn,ta,na,tb,nb,tc,nc) \ + virtual ret (CALLBACK xfn)(ta a,tb b,tc c) const = 0; + +#define ICOM_CMETHOD4(ret,xfn,ta,na,tb,nb,tc,nc,td,nd) \ + virtual ret (CALLBACK xfn)(ta a,tb b,tc c,td d) const = 0; + +#define ICOM_CMETHOD5(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne) \ + virtual ret (CALLBACK xfn)(ta a,tb b,tc c,td d,te e) const = 0; + +#define ICOM_CMETHOD6(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf) \ + virtual ret (CALLBACK xfn)(ta a,tb b,tc c,td d,te e,tf f) const = 0; + +#define ICOM_CMETHOD7(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng) \ + virtual ret (CALLBACK xfn)(ta a,tb b,tc c,td d,te e,tf f,tg g) const = 0; + +#define ICOM_CMETHOD8(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng,th,nh) \ + virtual ret (CALLBACK xfn)(ta a,tb b,tc c,td d,te e,tf f,tg g,th h) const = 0; + + +#define ICOM_VMETHOD(xfn) \ + virtual void (CALLBACK xfn)(void) = 0; + +#define ICOM_VMETHOD1(xfn,ta,na) \ + virtual void (CALLBACK xfn)(ta a) = 0; + +#define ICOM_VMETHOD2(xfn,ta,na,tb,nb) \ + virtual void (CALLBACK xfn)(ta a,tb b) = 0; + +#define ICOM_VMETHOD3(xfn,ta,na,tb,nb,tc,nc) \ + virtual void (CALLBACK xfn)(ta a,tb b,tc c) = 0; + +#define ICOM_VMETHOD4(xfn,ta,na,tb,nb,tc,nc,td,nd) \ + virtual void (CALLBACK xfn)(ta a,tb b,tc c,td d) = 0; + +#define ICOM_VMETHOD5(xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne) \ + virtual void (CALLBACK xfn)(ta a,tb b,tc c,td d,te e) = 0; + +#define ICOM_VMETHOD6(xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf) \ + virtual void (CALLBACK xfn)(ta a,tb b,tc c,td d,te e,tf f) = 0; + +#define ICOM_VMETHOD7(xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng) \ + virtual void (CALLBACK xfn)(ta a,tb b,tc c,td d,te e,tf f,tg g) = 0; + +#define ICOM_VMETHOD8(xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng,th,nh) \ + virtual void (CALLBACK xfn)(ta a,tb b,tc c,td d,te e,tf f,tg g,th h) = 0; + + +#define ICOM_CVMETHOD(xfn) \ + virtual void (CALLBACK xfn)(void) const = 0; + +#define ICOM_CVMETHOD1(xfn,ta,na) \ + virtual void (CALLBACK xfn)(ta a) const = 0; + +#define ICOM_CVMETHOD2(xfn,ta,na,tb,nb) \ + virtual void (CALLBACK xfn)(ta a,tb b) const = 0; + +#define ICOM_CVMETHOD3(xfn,ta,na,tb,nb,tc,nc) \ + virtual void (CALLBACK xfn)(ta a,tb b,tc c) const = 0; + +#define ICOM_CVMETHOD4(xfn,ta,na,tb,nb,tc,nc,td,nd) \ + virtual void (CALLBACK xfn)(ta a,tb b,tc c,td d) const = 0; + +#define ICOM_CVMETHOD5(xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne) \ + virtual void (CALLBACK xfn)(ta a,tb b,tc c,td d,te e) const = 0; + +#define ICOM_CVMETHOD6(xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf) \ + virtual void (CALLBACK xfn)(ta a,tb b,tc c,td d,te e,tf f) const = 0; + +#define ICOM_CVMETHOD7(xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng) \ + virtual void (CALLBACK xfn)(ta a,tb b,tc c,td d,te e,tf f,tg g) const = 0; + +#define ICOM_CVMETHOD8(xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng,th,nh) \ + virtual void (CALLBACK xfn)(ta a,tb b,tc c,td d,te e,tf f,tg g,th h) const = 0; + +#endif + + #define ICOM_DEFINE(iface,ibase) \ typedef struct iface: public ibase { \ iface##_METHODS \ @@ -664,17 +799,20 @@ struct IUnknown { }; struct ICOM_VTABLE(IUnknown) { ICOM_METHOD2(HRESULT,QueryInterface,REFIID,riid, LPVOID*,ppvObj); -#else +#else /* ICOM_CINTERFACE */ struct IUnknown { +#ifndef ICOM_VIRTUAL_METHODS union { const void* lpvtbl; HRESULT (CALLBACK *fnQueryInterface)(IUnknown* me, REFIID riid, LPVOID* ppvObj); } t; inline int QueryInterface(REFIID a, LPVOID* b) { return ((IUnknown*)t.lpvtbl)->t.fnQueryInterface(this,a,b); } -#endif - - ICOM_METHOD (ULONG,AddRef); - ICOM_METHOD (ULONG,Release); +#else /* ICOM_VIRTUAL_METHODS */ + ICOM_METHOD2(HRESULT,QueryInterface,REFIID,riid, LPVOID*,ppvObj) +#endif /* ICOM_VIRTUAL_METHODS */ +#endif /* ICOM_CINTERFACE */ + ICOM_METHOD (ULONG,AddRef) + ICOM_METHOD (ULONG,Release) }; #undef ICOM_INTERFACE