Sweden-Number/include/objbase.h

469 lines
25 KiB
C

#ifndef __WINE_OBJBASE_H
#define __WINE_OBJBASE_H
/*
* The goal of the following set of definitions is to provide a way to use the same
* header file definitions to provide both a C interface and a C++ object oriented
* interface to COM interfaces. The type of interface is selected automatically
* depending on the language but it is always possible to get the C interface in C++
* by defining CINTERFACE.
*
* It is based on the following assumptions:
* - all COM interfaces derive from IUnknown, this should not be a problem.
* - the header file only defines the interface, the actual fields are defined
* separately in the C file implementing the interface.
* - no COM method returns void. This seems to be the case but otherwise we could support this
* case by having one more set of macros.
*
* The natural approach to this problem would be to make sure we get a C++ class and
* virtual methods in C++ and a structure with a table of pointer to functions in C.
* Unfortunately the layout of the virtual table is compiler specific, the layout of
* g++ virtual tables is not the same as that of an egcs virtual table which is not the
* same as that generated by Visual C+. There are workarounds to make the virtual tables
* compatible via padding but unfortunately the one which is imposed to the WINE emulator
* by the Windows binaries, i.e. the Visual C++ one, is the most compact of all.
*
* So the solution I finally adopted does not use virtual tables. Instead I use inline
* non virtual methods that dereference the method pointer themselves and perform the call.
*
* Let's take Direct3D as an example:
*
* #define ICOM_INTERFACE IDirect3D
* ICOM_BEGIN(IDirect3D,IUnknown)
* ICOM_METHOD1(HRESULT,Initialize, REFIID,);
* ICOM_METHOD2(HRESULT,EnumDevices, LPD3DENUMDEVICESCALLBACK,, LPVOID,);
* ICOM_METHOD2(HRESULT,CreateLight, LPDIRECT3DLIGHT*,, IUnknown*,);
* ICOM_METHOD2(HRESULT,CreateMaterial,LPDIRECT3DMATERIAL*,, IUnknown*,);
* ICOM_METHOD2(HRESULT,CreateViewport,LPDIRECT3DVIEWPORT*,, IUnknown*,);
* ICOM_METHOD2(HRESULT,FindDevice, LPD3DFINDDEVICESEARCH,, LPD3DFINDDEVICERESULT,);
* ICOM_END(IDirect3D)
* #undef ICOM_INTERFACE
*
* #if !defined(__cplusplus) || defined(CINTERFACE)
* // *** IUnknown methods *** //
* #define IDirect3D_QueryInterface(p,a,b) ICOM_ICALL2(IUnknown,QueryInterface,p,a,b)
* #define IDirect3D_AddRef(p) ICOM_ICALL (IUnknown,AddRef,p)
* #define IDirect3D_Release(p) ICOM_ICALL (IUnknown,Release,p)
* // *** IDirect3D methods *** //
* #define IDirect3D_Initialize(p,a) ICOM_CALL1(Initialize,p,a)
* #define IDirect3D_EnumDevices(p,a,b) ICOM_CALL2(EnumDevice,p,a,b)
* #define IDirect3D_CreateLight(p,a,b) ICOM_CALL2(CreateLight,p,a,b)
* #define IDirect3D_CreateMaterial(p,a,b) ICOM_CALL2(CreateMaterial,p,a,b)
* #define IDirect3D_CreateViewport(p,a,b) ICOM_CALL2(CreateViewport,p,a,b)
* #define IDirect3D_FindDevice(p,a,b) ICOM_CALL2(FindDevice,p,a,b)
* #endif
*
* Comments:
* - The ICOM_INTERFACE is used in the ICOM_METHOD macros for the 'this' pointer and to cast
* pointers. Defining this macro here saves us the trouble of having to repeat the interface
* name everywhere. Note haowever that because of the way macros work a macro like ICOM_METHOD1
* cannot use 'ICOM_INTERFACE##_VTABLE' because this would give 'ICOM_INTERFACE_VTABLE' and not
* 'IDirect3D_VTABLE'.
* - ICOM_BEGIN and ICOM_END are responsible for generating whatever structure is appropriate for
* representing the interface in the current language. In C this is a couple of structs in C++
* it's a class. The first parameter is the interface name and the second one is the interface
* we inherit from. The reason why you have to repeat the interface name is because that's the
* only way these macro can successfully output "IDirect3D_VTABLE'. Trying to use ICOM_INTERFACE
* would, as in ICOM_METHOD, only yield 'ICOM_INTERFACE_VTABLE'.
* - With the way ICOM_BEGIN works you don't have to repeat the definitions of the methods of the
* parent interface. They are automatically inherited both in C and in C++.
* - In C++ the ICOM_METHOD macros generate a function prototype and a call to a function pointer
* method. This means using once 't1 p1, t2 p2, ...' and once 'p1, p2' without the types. The
* only way I found to handle this is to have one ICOM_METHOD macro per number of parameters and
* to have it take only the type information (with const if necessary) as parameters.
* The 'undef ICOM_INTERFACE' is here to remind you that using ICOM_INTERFACE in the following
* macros will not work. This time it's because the ICOM_CALL macro expansion is done only once
* the 'IDirect3D_Xxx' macro is expanded. And by that time ICOM_INTERFACE will be long gone
* anyway.
* - You may have noticed the double commas after each parameter type. This allows you to put the
* name of that parameter which I think is good for documentation. It is not required and since
* I did not know what to put there for this example (I could only find doc about IDirect3D2),
* I left them blank.
* - Finally the set of 'IDirect3D_Xxx' macros is a standard set of macros defined to ease access
* to the interface methods in C. Unfortunately I don't see any way to avoid having to duplicate
* the inherited method definitions there. We must use ICOM_ICALL to invoke inherited methods,
* because in C we have to cast the virtual table pointer, and we should use the ICOM_CALL
* method in the other cases. This time I could have used a trick to use only one macro whatever
* the number of parameters but I prefered to have it work the same way as above.
* - You probably have noticed that we don't define the fields we need to actually implement this
* interface: reference count, pointer to other resources and miscellaneous fields. That's
* because it's not needed, and the user will anyway only manipulate pointers to this structure
* so he does not need to know its real size. Of course on the implementation side we have the
* real definition of the interface structure and they should match what the macros yield in
* each language (or conversely).
*
*
* In C this gives:
* typedef struct IDirect3D_VTABLE IDirect3D_VTABLE;
* struct IDirect3D {
* IDirect3D_VTABLE* lpvtbl;
* };
* struct IDirect3D_VTABLE {
* IUnknown_VTABLE bvt;
* HRESULT (*fnInitialize)(IDirect3D* me, REFIID a);
* HRESULT (*fnEnumDevices)(IDirect3D* me, LPD3DENUMDEVICESCALLBACK a, LPVOID b);
* HRESULT (*fnCreateLight)(IDirect3D* me, LPDIRECT3DLIGHT* a, IUnknown* b);
* HRESULT (*fnCreateMaterial)(IDirect3D* me, LPDIRECT3DMATERIAL* a, IUnknown* b);
* HRESULT (*fnCreateViewport)(IDirect3D* me, LPDIRECT3DVIEWPORT* a, IUnknown* b);
* HRESULT (*fnFindDevice)(IDirect3D* me, LPD3DFINDDEVICESEARCH a, LPD3DFINDDEVICERESULT b);
* };
*
* #if !defined(__cplusplus) || defined(CINTERFACE)
* // *** IUnknown methods *** //
* #define IDirect3D_QueryInterface(p,a,b) ((IUnknown_VTABLE*)(p)->lpvtbl)->fnQueryInterface((IUnknown*)p,a,b)
* #define IDirect3D_AddRef(p) ((IUnknown_VTABLE*)(p)->lpvtbl)->fnAddRef((IUnknown*)p)
* #define IDirect3D_Release(p) ((IUnknown_VTABLE*)(p)->lpvtbl)->fnRelease((IUnknown*)p)
* // *** IDirect3D methods *** //
* #define IDirect3D_Initialize(p,a) (p)->lpvtbl->fnInitialize(p,a)
* #define IDirect3D_EnumDevices(p,a,b) (p)->lpvtbl->fnEnumDevice(p,a,b)
* #define IDirect3D_CreateLight(p,a,b) (p)->lpvtbl->fnCreateLight(p,a,b)
* #define IDirect3D_CreateMaterial(p,a,b) (p)->lpvtbl->fnCreateMaterial(p,a,b)
* #define IDirect3D_CreateViewport(p,a,b) (p)->lpvtbl->fnCreateViewport(p,a,b)
* #define IDirect3D_FindDevice(p,a,b) (p)->lpvtbl->fnFindDevice(p,a,b)
* #endif
*
* Comments:
* - IDirect3D only contains a pointer to the IDirect3D virtual/jump table. This is the only thing
* the user needs to know to use the interface. Of course the structure we will define to
* implement this interface will have more fields but the first one will match this pointer.
* - The code generated by ICOM_BEGIN goes up to the bvt field in the IDirect3D virtual table.
* This bvt field is what saves us from having to duplicate the inherited method definitions.
* It's a shame that C (gcc) will not allow unnamed structs. If this was possible we could
* seamlessly inherit and use the parent's interface function pointers.
* - What follows is just a bunch of function pointer definitions generated by the ICOM_METHOD
* macros. The implementation will fill this jump table with appropriate values in a static
* variable and initialize the lpvtbl field to point to this variable.
* - The IDirect3D_Xxx macros then just derefence the lpvtbl pointer and use the function pointer
* corresponding to the macro name. This emulates the behavior of a virtual table and should be
* about as fast. In the case of inherited methods we have some additional casting to do to
* because the inherited methods are defined in the bvt field or maybe further imbricated. Since
* the effect of the bvt field is that we inherit the parent virtual table fields this cast is
* relatively inocuous. A similar cast must be performed on the interface pointer before the
* invoked method will accept it. Despite all these casts there is little chance that you call a
* method on the wrong type of interface because the function names still have to match. But this
* is the only thing that will make the compilation fail.
*
*
* And in C++ (with gcc's g++):
*
* typedef struct IDirect3D: public IUnknown {
* private: HRESULT (*fnInitialize)(IDirect3D* me, REFIID a);
* public: inline HRESULT Initialize(REFIID a) { return ((IDirect3D*)t.lpvtbl)->fnInitialize(this,a); };
* private: HRESULT (*fnEnumDevices)(IDirect3D* me, LPD3DENUMDEVICESCALLBACK a, LPVOID b);
* public: inline HRESULT EnumDevices(LPD3DENUMDEVICESCALLBACK a, LPVOID b)
* { return ((IDirect3D*)t.lpvtbl)->fnEnumDevices(this,a,b); };
* private: HRESULT (*fnCreateLight)(IDirect3D* me, LPDIRECT3DLIGHT* a, IUnknown* b);
* public: inline HRESULT CreateLight(LPDIRECT3DLIGHT* a, IUnknown* b)
* { return ((IDirect3D*)t.lpvtbl)->fnCreateLight(this,a,b); };
* private: HRESULT (*fnCreateMaterial)(IDirect3D* me, LPDIRECT3DMATERIAL* a, IUnknown* b);
* public: inline HRESULT CreateMaterial(LPDIRECT3DMATERIAL* a, IUnknown* b)
* { return ((IDirect3D*)t.lpvtbl)->fnCreateMaterial(this,a,b); };
* private: HRESULT (*fnCreateViewport)(IDirect3D* me, LPDIRECT3DVIEWPORT* a, IUnknown* b);
* public: inline HRESULT CreateViewport(LPDIRECT3DVIEWPORT* a, IUnknown* b)
* { return ((IDirect3D*)t.lpvtbl)->fnCreateViewport(this,a,b); };
* private: HRESULT (*fnFindDevice)(IDirect3D* me, LPD3DFINDDEVICESEARCH a, LPD3DFINDDEVICERESULT b);
* public: inline HRESULT FindDevice(LPD3DFINDDEVICESEARCH a, LPD3DFINDDEVICERESULT b)
* { return ((IDirect3D*)t.lpvtbl)->fnFindDevice(this,a,b); };
* };
*
* Comments:
* - In C++ IDirect3D does double duty as both the virtual/jump table and as the interface
* definition. The reason for this is to avoid having to duplicate the mehod definitions: once
* to have the function pointers in the jump table and once to have the methods in the interface
* class. Here one macro can generate both. This means though that the first pointer, t.lpvtbl
* defined in IUnknown, must be interpreted as the jump table pointer if we interpret the
* structure as the the interface class, and as the function pointer to the QueryInterface
* method, t.fnQueryInterface, if we interpret the structure as the jump table. Fortunately this
* gymnastic is entirely taken care of in the header of IUnknown.
* - Of course in C++ we use inheritance so that we don't have to duplicate the method definitions.
* - Since IDirect3D does double duty, each ICOM_METHOD macro defines both a function pointer and
* a non-vritual inline method which dereferences it and calls it. This way this method behaves
* just like a virtual method but does not create a true C++ virtual table which would break the
* structure layout. If you look at the implementation of these methods you'll notice that they
* would not work for void functions. We have to return something and fortunately this seems to
* be what all the COM methods do (otherwise we would need another set of macros).
* - Note how the ICOM_METHOD generates both function prototypes mixing types and formal parameter
* names and the method invocation using only the formal parameter name. This is the reason why
* we need different macros to handle different numbers of parameters.
* - Finally there is no IDirect3D_Xxx macro. These are not needed in C++ unless the CINTERFACE
* macro is defined in which case we would not be here.
*
*
* Implementing a COM interface.
*
* This continues the above example.I assume the implementation is in C but it would probably
* be similar in C++.
*
* typedef struct _IDirect3D {
* void* lpvtbl;
* // ...
*
* } _IDirect3D;
*
* static ICOM_VTABLE(IDirect3D) d3dvt;
*
* // implement the IDirect3D methods here
*
* int IDirect3D_fnQueryInterface(LPUNKNOWN me)
* {
* ICOM_THIS(IDirect3D,me);
* // ...
* }
*
* // ...
*
* static ICOM_VTABLE(IDirect3D) d3dvt = {
* {
* IDirect3D_fnQueryInterface,
* IUnknown_fnAdd,
* IUnknown_fnAdd2
* },
* IDirect3D_fnInitialize,
* IDirect3D_fnSetWidth
* };
*
* Comments:
* - We first define what the interface really contains. This is th e_IDirect3D structure. The
* first field must of course be the virtual table pointer. Everything else is free.
* - Then we predeclare our static virtual table variable, we will need its address in some
* methods to initialize the virtual table pointer of the returned interface objects.
* - Then we implement the interface methods. To match what has been declared in the header file
* they must take a pointer to a IDirect3D structure so we must cast it to an _IDirect3D so that
* we can manipulate the fields. This is performed by the ICOM_THIS macro.
* - Finally we initialize the virtual table. The inherited methods must be in curly brackets to
* match the parent interface's virtual table definition.
*/
#define ICOM_VTABLE(iface) iface##_VTABLE
#if defined(__cplusplus) && !defined(CINTERFACE)
/* C++ interface */
#define ICOM_BEGIN(iface,ibase) \
typedef struct iface: public ibase {
#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); };
#define ICOM_METHOD1(ret,xfn,ta,na) \
private: ret (CALLBACK *fn##xfn)(ICOM_INTERFACE* me,ta a); \
public: inline ret (CALLBACK xfn)(ta a) { return ((ICOM_INTERFACE*)t.lpvtbl)->fn##xfn(this,a); };
#define ICOM_METHOD2(ret,xfn,ta,na,tb,nb) \
private: ret (CALLBACK *fn##xfn)(ICOM_INTERFACE* me,ta a,tb b); \
public: inline ret (CALLBACK xfn)(ta a,tb b) { return ((ICOM_INTERFACE*)t.lpvtbl)->fn##xfn(this,a,b); };
#define ICOM_METHOD3(ret,xfn,ta,na,tb,nb,tc,nc) \
private: ret (CALLBACK *fn##xfn)(ICOM_INTERFACE* me,ta a,tb b,tc c); \
public: inline ret (CALLBACK xfn)(ta a,tb b,tc c) { return ((ICOM_INTERFACE*)t.lpvtbl)->fn##xfn(this,a,b,c); };
#define ICOM_METHOD4(ret,xfn,ta,na,tb,nb,tc,nc,td,nd) \
private: ret (CALLBACK *fn##xfn)(ICOM_INTERFACE* me,ta a,tb b,tc c,td d); \
public: inline ret (CALLBACK xfn)(ta a,tb b,tc c,td d) { return ((ICOM_INTERFACE*)t.lpvtbl)->fn##xfn(this,a,b,c,d); };
#define ICOM_METHOD5(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne) \
private: ret (CALLBACK *fn##xfn)(ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e); \
public: inline ret (CALLBACK xfn)(ta a,tb b,tc c,td d,te e) { return ((ICOM_INTERFACE*)t.lpvtbl)->fn##xfn(this,a,b,c,d,e); };
#define ICOM_METHOD6(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf) \
private: ret (CALLBACK *fn##xfn)(ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e,tf f); \
public: inline ret (CALLBACK xfn)(ta a,tb b,tc c,td d,te e,tf f) { return ((ICOM_INTERFACE*)t.lpvtbl)->fn##xfn(this,a,b,c,d,e,f); };
#define ICOM_METHOD7(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng) \
private: ret (CALLBACK *fn##xfn)(ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e,tf f,tg g); \
public: inline ret (CALLBACK xfn)(ta a,tb b,tc c,td d,te e,tf f,tg g) { return ((ICOM_INTERFACE*)t.lpvtbl)->fn##xfn(this,a,b,c,d,e,f,g); };
#define ICOM_CMETHOD(ret,xfn) \
private: ret (CALLBACK *fn##xfn)(const ICOM_INTERFACE* me); \
public: inline ret (CALLBACK xfn)(void) const { return ((ICOM_INTERFACE*)t.lpvtbl)->fn##xfn(this); };
#define ICOM_CMETHOD1(ret,xfn,ta,na) \
private: ret (CALLBACK *fn##xfn)(const ICOM_INTERFACE* me,ta a); \
public: inline ret (CALLBACK xfn)(ta a) const { return ((ICOM_INTERFACE*)t.lpvtbl)->fn##xfn(this,a); };
#define ICOM_CMETHOD2(ret,xfn,ta,na,tb,nb) \
private: ret (CALLBACK *fn##xfn)(const ICOM_INTERFACE* me,ta a,tb b); \
public: inline ret (CALLBACK xfn)(ta a,tb b) const { return ((ICOM_INTERFACE*)t.lpvtbl)->fn##xfn(this,a,b); };
#define ICOM_CMETHOD3(ret,xfn,ta,na,tb,nb,tc,nc) \
private: ret (CALLBACK *fn##xfn)(const ICOM_INTERFACE* me,ta a,tb b,tc c); \
public: inline ret (CALLBACK xfn)(ta a,tb b,tc c) const { return ((ICOM_INTERFACE*)t.lpvtbl)->fn##xfn(this,a,b,c); };
#define ICOM_CMETHOD4(ret,xfn,ta,na,tb,nb,tc,nc,td,nd) \
private: ret (CALLBACK *fn##xfn)(const ICOM_INTERFACE* me,ta a,tb b,tc c,td d); \
public: inline ret (CALLBACK xfn)(ta a,tb b,tc c,td d) const { return ((ICOM_INTERFACE*)t.lpvtbl)->fn##xfn(this,a,b,c,d); };
#define ICOM_CMETHOD5(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne) \
private: ret (CALLBACK *fn##xfn)(const ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e); \
public: inline ret (CALLBACK xfn)(ta a,tb b,tc c,td d,te e) const { return ((ICOM_INTERFACE*)t.lpvtbl)->fn##xfn(this,a,b,c,d,e); };
#define ICOM_CMETHOD6(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf) \
private: ret (CALLBACK *fn##xfn)(const ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e,tf f); \
public: inline ret (CALLBACK xfn)(ta a,tb b,tc c,td d,te e,tf f) const { return ((ICOM_INTERFACE*)t.lpvtbl)->fn##xfn(this,a,b,c,d,e,f); };
#define ICOM_CMETHOD7(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng) \
private: ret (CALLBACK *fn##xfn)(const ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e,tf f,tg g); \
public: inline ret (CALLBACK xfn)(ta a,tb b,tc c,td d,te e,tf f,tg g) const { return ((ICOM_INTERFACE*)t.lpvtbl)->fn##xfn(this,a,b,c,d,e,f,g); };
#define ICOM_END(iface) \
};
#define ICOM_ICALL(ibase, xfn, p) this_is_a_syntax_error
#define ICOM_ICALL1(ibase, xfn, p,a) this_is_a_syntax_error
#define ICOM_ICALL2(ibase, xfn, p,a,b) this_is_a_syntax_error
#define ICOM_ICALL3(ibase, xfn, p,a,b,c) this_is_a_syntax_error
#define ICOM_ICALL4(ibase, xfn, p,a,b,c,d) this_is_a_syntax_error
#define ICOM_ICALL5(ibase, xfn, p,a,b,c,d,e) this_is_a_syntax_error
#define ICOM_ICALL6(ibase, xfn, p,a,b,c,d,e,f) this_is_a_syntax_error
#define ICOM_ICALL7(ibase, xfn, p,a,b,c,d,e,f,g) this_is_a_syntax_error
#define ICOM_CALL(xfn, p) this_is_a_syntax_error
#define ICOM_CALL1(xfn, p,a) this_is_a_syntax_error
#define ICOM_CALL2(xfn, p,a,b) this_is_a_syntax_error
#define ICOM_CALL3(xfn, p,a,b,c) this_is_a_syntax_error
#define ICOM_CALL4(xfn, p,a,b,c,d) this_is_a_syntax_error
#define ICOM_CALL5(xfn, p,a,b,c,d,e) this_is_a_syntax_error
#define ICOM_CALL6(xfn, p,a,b,c,d,e,f) this_is_a_syntax_error
#define ICOM_CALL7(xfn, p,a,b,c,d,e,f,g) this_is_a_syntax_error
#else
/* C interface */
#define ICOM_BEGIN(iface,ibase) \
typedef struct ICOM_VTABLE(iface) ICOM_VTABLE(iface); \
struct iface { \
const ICOM_VTABLE(iface)* lpvtbl; \
}; \
struct ICOM_VTABLE(iface) { \
ICOM_VTABLE(ibase) bvt;
#define ICOM_METHOD(ret, xfn) \
ret (CALLBACK *fn##xfn)(ICOM_INTERFACE* me);
#define ICOM_METHOD1(ret,xfn,ta,na) \
ret (CALLBACK *fn##xfn)(ICOM_INTERFACE* me,ta a);
#define ICOM_METHOD2(ret,xfn,ta,na,tb,nb) \
ret (CALLBACK *fn##xfn)(ICOM_INTERFACE* me,ta a,tb b);
#define ICOM_METHOD3(ret,xfn,ta,na,tb,nb,tc,nc) \
ret (CALLBACK *fn##xfn)(ICOM_INTERFACE* me,ta a,tb b,tc c);
#define ICOM_METHOD4(ret,xfn,ta,na,tb,nb,tc,nc,td,nd) \
ret (CALLBACK *fn##xfn)(ICOM_INTERFACE* me,ta a,tb b,tc c,td d);
#define ICOM_METHOD5(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne) \
ret (CALLBACK *fn##xfn)(ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e);
#define ICOM_METHOD6(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf) \
ret (CALLBACK *fn##xfn)(ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e,tf f);
#define ICOM_METHOD7(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng) \
ret (CALLBACK *fn##xfn)(ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e,tf f,tg g);
#define ICOM_CMETHOD(ret, xfn) \
ret (CALLBACK *fn##xfn)(const ICOM_INTERFACE* me);
#define ICOM_CMETHOD1(ret,xfn,ta,na) \
ret (CALLBACK *fn##xfn)(const ICOM_INTERFACE* me,ta a);
#define ICOM_CMETHOD2(ret,xfn,ta,na,tb,nb) \
ret (CALLBACK *fn##xfn)(const ICOM_INTERFACE* me,ta a,tb b);
#define ICOM_CMETHOD3(ret,xfn,ta,na,tb,nb,tc,nc) \
ret (CALLBACK *fn##xfn)(const ICOM_INTERFACE* me,ta a,tb b,tc c);
#define ICOM_CMETHOD4(ret,xfn,ta,na,tb,nb,tc,nc,td,nd) \
ret (CALLBACK *fn##xfn)(const ICOM_INTERFACE* me,ta a,tb b,tc c,td d);
#define ICOM_CMETHOD5(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne) \
ret (CALLBACK *fn##xfn)(const ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e);
#define ICOM_CMETHOD6(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf) \
ret (CALLBACK *fn##xfn)(const ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e,tf f);
#define ICOM_CMETHOD7(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng) \
ret (CALLBACK *fn##xfn)(const ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e,tf f,tg g);
#define ICOM_END(iface) \
};
#define ICOM_ICALL(ibase, xfn, p) ((ICOM_VTABLE(ibase)*)(p)->lpvtbl)->fn##xfn((ibase*)p)
#define ICOM_ICALL1(ibase, xfn, p,a) ((ICOM_VTABLE(ibase)*)(p)->lpvtbl)->fn##xfn((ibase*)p,a)
#define ICOM_ICALL2(ibase, xfn, p,a,b) ((ICOM_VTABLE(ibase)*)(p)->lpvtbl)->fn##xfn((ibase*)p,a,b)
#define ICOM_ICALL3(ibase, xfn, p,a,b,c) ((ICOM_VTABLE(ibase)*)(p)->lpvtbl)->fn##xfn((ibase*)p,a,b,c)
#define ICOM_ICALL4(ibase, xfn, p,a,b,c,d) ((ICOM_VTABLE(ibase)*)(p)->lpvtbl)->fn##xfn((ibase*)p,a,b,c,d)
#define ICOM_ICALL5(ibase, xfn, p,a,b,c,d,e) ((ICOM_VTABLE(ibase)*)(p)->lpvtbl)->fn##xfn((ibase*)p,a,b,c,d,e)
#define ICOM_ICALL6(ibase, xfn, p,a,b,c,d,e,f) ((ICOM_VTABLE(ibase)*)(p)->lpvtbl)->fn##xfn((ibase*)p,a,b,c,d,e,f)
#define ICOM_ICALL7(ibase, xfn, p,a,b,c,d,e,f,g) ((ICOM_VTABLE(ibase)*)(p)->lpvtbl)->fn##xfn((ibase*)p,a,b,c,d,e,f,g)
#define ICOM_CALL(xfn, p) (p)->lpvtbl->fn##xfn(p)
#define ICOM_CALL1(xfn, p,a) (p)->lpvtbl->fn##xfn(p,a)
#define ICOM_CALL2(xfn, p,a,b) (p)->lpvtbl->fn##xfn(p,a,b)
#define ICOM_CALL3(xfn, p,a,b,c) (p)->lpvtbl->fn##xfn(p,a,b,c)
#define ICOM_CALL4(xfn, p,a,b,c,d) (p)->lpvtbl->fn##xfn(p,a,b,c,d)
#define ICOM_CALL5(xfn, p,a,b,c,d,e) (p)->lpvtbl->fn##xfn(p,a,b,c,d,e)
#define ICOM_CALL6(xfn, p,a,b,c,d,e,f) (p)->lpvtbl->fn##xfn(p,a,b,c,d,e,f)
#define ICOM_CALL7(xfn, p,a,b,c,d,e,f,g) (p)->lpvtbl->fn##xfn(p,a,b,c,d,e,f,g)
#define ICOM_THIS(iface,me) struct _##iface* this=(struct _##iface*)me
#define ICOM_CTHIS(iface,me) const _##iface* this=(const _##iface*)me
#endif
/* FIXME: compobj.h seems to be obsolete (replaced by objbase.h!) but it still contains REFIID */
#include "compobj.h"
typedef struct IUnknown IUnknown ,*LPUNKNOWN;
/*****************************************************************************
* IUnknown interface
*/
#define ICOM_INTERFACE IUnknown
#if defined(__cplusplus) && !defined(CINTERFACE)
struct IUnknown {
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); }
#else
typedef struct ICOM_VTABLE(IUnknown) ICOM_VTABLE(IUnknown);
struct IUnknown {
ICOM_VTABLE(IUnknown)* lpvtbl;
};
struct ICOM_VTABLE(IUnknown) {
ICOM_METHOD2(HRESULT,QueryInterface,REFIID,riid, LPVOID*,ppvObj)
#endif
ICOM_METHOD (ULONG,AddRef)
ICOM_METHOD (ULONG,Release)
#ifdef __WRC__
}; /* FIXME: WRC does not support function macros and it is ICOM_END that is supposed to close the class */
#else
ICOM_END(IUnknown)
#endif
#undef ICOM_INTERFACE
#if !defined(__cplusplus) || defined(CINTERFACE)
/*** IUnknown methods ***/
#define IUnknown_QueryInterface(p,a,b) ICOM_CALL2(QueryInterface,p,a,b)
#define IUnknown_AddRef(p) ICOM_CALL (AddRef,p)
#define IUnknown_Release(p) ICOM_CALL (Release,p)
#endif
#endif /* __WINE_OBJBASE_H */