Emulates ins/outs correctly for DOS programs.
[wine/multimedia.git] / include / objbase.h
blobf7c569766d894cfaa7716a0e2cb233f8d6b73f12
1 #ifndef __WINE_OBJBASE_H
2 #define __WINE_OBJBASE_H
5 /*
6 * The goal of the following set of definitions is to provide a way to use the same
7 * header file definitions to provide both a C interface and a C++ object oriented
8 * interface to COM interfaces. The type of interface is selected automatically
9 * depending on the language but it is always possible to get the C interface in C++
10 * by defining CINTERFACE.
12 * It is based on the following assumptions:
13 * - all COM interfaces derive from IUnknown, this should not be a problem.
14 * - the header file only defines the interface, the actual fields are defined
15 * separately in the C file implementing the interface.
16 * - no COM method returns void. This seems to be the case but otherwise we could support this
17 * case by having one more set of macros.
19 * The natural approach to this problem would be to make sure we get a C++ class and
20 * virtual methods in C++ and a structure with a table of pointer to functions in C.
21 * Unfortunately the layout of the virtual table is compiler specific, the layout of
22 * g++ virtual tables is not the same as that of an egcs virtual table which is not the
23 * same as that generated by Visual C+. There are workarounds to make the virtual tables
24 * compatible via padding but unfortunately the one which is imposed to the WINE emulator
25 * by the Windows binaries, i.e. the Visual C++ one, is the most compact of all.
27 * So the solution I finally adopted does not use virtual tables. Instead I use inline
28 * non virtual methods that dereference the method pointer themselves and perform the call.
30 * Let's take Direct3D as an example:
32 * #define ICOM_INTERFACE IDirect3D
33 * ICOM_BEGIN(IDirect3D,IUnknown)
34 * ICOM_METHOD1(HRESULT,Initialize, REFIID,);
35 * ICOM_METHOD2(HRESULT,EnumDevices, LPD3DENUMDEVICESCALLBACK,, LPVOID,);
36 * ICOM_METHOD2(HRESULT,CreateLight, LPDIRECT3DLIGHT*,, IUnknown*,);
37 * ICOM_METHOD2(HRESULT,CreateMaterial,LPDIRECT3DMATERIAL*,, IUnknown*,);
38 * ICOM_METHOD2(HRESULT,CreateViewport,LPDIRECT3DVIEWPORT*,, IUnknown*,);
39 * ICOM_METHOD2(HRESULT,FindDevice, LPD3DFINDDEVICESEARCH,, LPD3DFINDDEVICERESULT,);
40 * ICOM_END(IDirect3D)
41 * #undef ICOM_INTERFACE
43 * #if !defined(__cplusplus) || defined(CINTERFACE)
44 * // *** IUnknown methods *** //
45 * #define IDirect3D_QueryInterface(p,a,b) ICOM_ICALL2(IUnknown,QueryInterface,p,a,b)
46 * #define IDirect3D_AddRef(p) ICOM_ICALL (IUnknown,AddRef,p)
47 * #define IDirect3D_Release(p) ICOM_ICALL (IUnknown,Release,p)
48 * // *** IDirect3D methods *** //
49 * #define IDirect3D_Initialize(p,a) ICOM_CALL1(Initialize,p,a)
50 * #define IDirect3D_EnumDevices(p,a,b) ICOM_CALL2(EnumDevice,p,a,b)
51 * #define IDirect3D_CreateLight(p,a,b) ICOM_CALL2(CreateLight,p,a,b)
52 * #define IDirect3D_CreateMaterial(p,a,b) ICOM_CALL2(CreateMaterial,p,a,b)
53 * #define IDirect3D_CreateViewport(p,a,b) ICOM_CALL2(CreateViewport,p,a,b)
54 * #define IDirect3D_FindDevice(p,a,b) ICOM_CALL2(FindDevice,p,a,b)
55 * #endif
57 * Comments:
58 * - The ICOM_INTERFACE is used in the ICOM_METHOD macros for the 'this' pointer and to cast
59 * pointers. Defining this macro here saves us the trouble of having to repeat the interface
60 * name everywhere. Note haowever that because of the way macros work a macro like ICOM_METHOD1
61 * cannot use 'ICOM_INTERFACE##_VTABLE' because this would give 'ICOM_INTERFACE_VTABLE' and not
62 * 'IDirect3D_VTABLE'.
63 * - ICOM_BEGIN and ICOM_END are responsible for generating whatever structure is appropriate for
64 * representing the interface in the current language. In C this is a couple of structs in C++
65 * it's a class. The first parameter is the interface name and the second one is the interface
66 * we inherit from. The reason why you have to repeat the interface name is because that's the
67 * only way these macro can successfully output "IDirect3D_VTABLE'. Trying to use ICOM_INTERFACE
68 * would, as in ICOM_METHOD, only yield 'ICOM_INTERFACE_VTABLE'.
69 * - With the way ICOM_BEGIN works you don't have to repeat the definitions of the methods of the
70 * parent interface. They are automatically inherited both in C and in C++.
71 * - In C++ the ICOM_METHOD macros generate a function prototype and a call to a function pointer
72 * method. This means using once 't1 p1, t2 p2, ...' and once 'p1, p2' without the types. The
73 * only way I found to handle this is to have one ICOM_METHOD macro per number of parameters and
74 * to have it take only the type information (with const if necessary) as parameters.
75 * The 'undef ICOM_INTERFACE' is here to remind you that using ICOM_INTERFACE in the following
76 * macros will not work. This time it's because the ICOM_CALL macro expansion is done only once
77 * the 'IDirect3D_Xxx' macro is expanded. And by that time ICOM_INTERFACE will be long gone
78 * anyway.
79 * - You may have noticed the double commas after each parameter type. This allows you to put the
80 * name of that parameter which I think is good for documentation. It is not required and since
81 * I did not know what to put there for this example (I could only find doc about IDirect3D2),
82 * I left them blank.
83 * - Finally the set of 'IDirect3D_Xxx' macros is a standard set of macros defined to ease access
84 * to the interface methods in C. Unfortunately I don't see any way to avoid having to duplicate
85 * the inherited method definitions there. We must use ICOM_ICALL to invoke inherited methods,
86 * because in C we have to cast the virtual table pointer, and we should use the ICOM_CALL
87 * method in the other cases. This time I could have used a trick to use only one macro whatever
88 * the number of parameters but I prefered to have it work the same way as above.
89 * - You probably have noticed that we don't define the fields we need to actually implement this
90 * interface: reference count, pointer to other resources and miscellaneous fields. That's
91 * because it's not needed, and the user will anyway only manipulate pointers to this structure
92 * so he does not need to know its real size. Of course on the implementation side we have the
93 * real definition of the interface structure and they should match what the macros yield in
94 * each language (or conversely).
97 * In C this gives:
98 * typedef struct IDirect3D_VTABLE IDirect3D_VTABLE;
99 * struct IDirect3D {
100 * IDirect3D_VTABLE* lpvtbl;
101 * };
102 * struct IDirect3D_VTABLE {
103 * IUnknown_VTABLE bvt;
104 * HRESULT (*fnInitialize)(IDirect3D* me, REFIID a);
105 * HRESULT (*fnEnumDevices)(IDirect3D* me, LPD3DENUMDEVICESCALLBACK a, LPVOID b);
106 * HRESULT (*fnCreateLight)(IDirect3D* me, LPDIRECT3DLIGHT* a, IUnknown* b);
107 * HRESULT (*fnCreateMaterial)(IDirect3D* me, LPDIRECT3DMATERIAL* a, IUnknown* b);
108 * HRESULT (*fnCreateViewport)(IDirect3D* me, LPDIRECT3DVIEWPORT* a, IUnknown* b);
109 * HRESULT (*fnFindDevice)(IDirect3D* me, LPD3DFINDDEVICESEARCH a, LPD3DFINDDEVICERESULT b);
110 * };
112 * #if !defined(__cplusplus) || defined(CINTERFACE)
113 * // *** IUnknown methods *** //
114 * #define IDirect3D_QueryInterface(p,a,b) ((IUnknown_VTABLE*)(p)->lpvtbl)->fnQueryInterface((IUnknown*)p,a,b)
115 * #define IDirect3D_AddRef(p) ((IUnknown_VTABLE*)(p)->lpvtbl)->fnAddRef((IUnknown*)p)
116 * #define IDirect3D_Release(p) ((IUnknown_VTABLE*)(p)->lpvtbl)->fnRelease((IUnknown*)p)
117 * // *** IDirect3D methods *** //
118 * #define IDirect3D_Initialize(p,a) (p)->lpvtbl->fnInitialize(p,a)
119 * #define IDirect3D_EnumDevices(p,a,b) (p)->lpvtbl->fnEnumDevice(p,a,b)
120 * #define IDirect3D_CreateLight(p,a,b) (p)->lpvtbl->fnCreateLight(p,a,b)
121 * #define IDirect3D_CreateMaterial(p,a,b) (p)->lpvtbl->fnCreateMaterial(p,a,b)
122 * #define IDirect3D_CreateViewport(p,a,b) (p)->lpvtbl->fnCreateViewport(p,a,b)
123 * #define IDirect3D_FindDevice(p,a,b) (p)->lpvtbl->fnFindDevice(p,a,b)
124 * #endif
126 * Comments:
127 * - IDirect3D only contains a pointer to the IDirect3D virtual/jump table. This is the only thing
128 * the user needs to know to use the interface. Of course the structure we will define to
129 * implement this interface will have more fields but the first one will match this pointer.
130 * - The code generated by ICOM_BEGIN goes up to the bvt field in the IDirect3D virtual table.
131 * This bvt field is what saves us from having to duplicate the inherited method definitions.
132 * It's a shame that C (gcc) will not allow unnamed structs. If this was possible we could
133 * seamlessly inherit and use the parent's interface function pointers.
134 * - What follows is just a bunch of function pointer definitions generated by the ICOM_METHOD
135 * macros. The implementation will fill this jump table with appropriate values in a static
136 * variable and initialize the lpvtbl field to point to this variable.
137 * - The IDirect3D_Xxx macros then just derefence the lpvtbl pointer and use the function pointer
138 * corresponding to the macro name. This emulates the behavior of a virtual table and should be
139 * about as fast. In the case of inherited methods we have some additional casting to do to
140 * because the inherited methods are defined in the bvt field or maybe further imbricated. Since
141 * the effect of the bvt field is that we inherit the parent virtual table fields this cast is
142 * relatively inocuous. A similar cast must be performed on the interface pointer before the
143 * invoked method will accept it. Despite all these casts there is little chance that you call a
144 * method on the wrong type of interface because the function names still have to match. But this
145 * is the only thing that will make the compilation fail.
148 * And in C++ (with gcc's g++):
150 * typedef struct IDirect3D: public IUnknown {
151 * private: HRESULT (*fnInitialize)(IDirect3D* me, REFIID a);
152 * public: inline HRESULT Initialize(REFIID a) { return ((IDirect3D*)t.lpvtbl)->fnInitialize(this,a); };
153 * private: HRESULT (*fnEnumDevices)(IDirect3D* me, LPD3DENUMDEVICESCALLBACK a, LPVOID b);
154 * public: inline HRESULT EnumDevices(LPD3DENUMDEVICESCALLBACK a, LPVOID b)
155 * { return ((IDirect3D*)t.lpvtbl)->fnEnumDevices(this,a,b); };
156 * private: HRESULT (*fnCreateLight)(IDirect3D* me, LPDIRECT3DLIGHT* a, IUnknown* b);
157 * public: inline HRESULT CreateLight(LPDIRECT3DLIGHT* a, IUnknown* b)
158 * { return ((IDirect3D*)t.lpvtbl)->fnCreateLight(this,a,b); };
159 * private: HRESULT (*fnCreateMaterial)(IDirect3D* me, LPDIRECT3DMATERIAL* a, IUnknown* b);
160 * public: inline HRESULT CreateMaterial(LPDIRECT3DMATERIAL* a, IUnknown* b)
161 * { return ((IDirect3D*)t.lpvtbl)->fnCreateMaterial(this,a,b); };
162 * private: HRESULT (*fnCreateViewport)(IDirect3D* me, LPDIRECT3DVIEWPORT* a, IUnknown* b);
163 * public: inline HRESULT CreateViewport(LPDIRECT3DVIEWPORT* a, IUnknown* b)
164 * { return ((IDirect3D*)t.lpvtbl)->fnCreateViewport(this,a,b); };
165 * private: HRESULT (*fnFindDevice)(IDirect3D* me, LPD3DFINDDEVICESEARCH a, LPD3DFINDDEVICERESULT b);
166 * public: inline HRESULT FindDevice(LPD3DFINDDEVICESEARCH a, LPD3DFINDDEVICERESULT b)
167 * { return ((IDirect3D*)t.lpvtbl)->fnFindDevice(this,a,b); };
168 * };
170 * Comments:
171 * - In C++ IDirect3D does double duty as both the virtual/jump table and as the interface
172 * definition. The reason for this is to avoid having to duplicate the mehod definitions: once
173 * to have the function pointers in the jump table and once to have the methods in the interface
174 * class. Here one macro can generate both. This means though that the first pointer, t.lpvtbl
175 * defined in IUnknown, must be interpreted as the jump table pointer if we interpret the
176 * structure as the the interface class, and as the function pointer to the QueryInterface
177 * method, t.fnQueryInterface, if we interpret the structure as the jump table. Fortunately this
178 * gymnastic is entirely taken care of in the header of IUnknown.
179 * - Of course in C++ we use inheritance so that we don't have to duplicate the method definitions.
180 * - Since IDirect3D does double duty, each ICOM_METHOD macro defines both a function pointer and
181 * a non-vritual inline method which dereferences it and calls it. This way this method behaves
182 * just like a virtual method but does not create a true C++ virtual table which would break the
183 * structure layout. If you look at the implementation of these methods you'll notice that they
184 * would not work for void functions. We have to return something and fortunately this seems to
185 * be what all the COM methods do (otherwise we would need another set of macros).
186 * - Note how the ICOM_METHOD generates both function prototypes mixing types and formal parameter
187 * names and the method invocation using only the formal parameter name. This is the reason why
188 * we need different macros to handle different numbers of parameters.
189 * - Finally there is no IDirect3D_Xxx macro. These are not needed in C++ unless the CINTERFACE
190 * macro is defined in which case we would not be here.
193 * Implementing a COM interface.
195 * This continues the above example.I assume the implementation is in C but it would probably
196 * be similar in C++.
198 * typedef struct _IDirect3D {
199 * void* lpvtbl;
200 * // ...
202 * } _IDirect3D;
204 * static ICOM_VTABLE(IDirect3D) d3dvt;
206 * // implement the IDirect3D methods here
208 * int IDirect3D_fnQueryInterface(LPUNKNOWN me)
210 * ICOM_THIS(IDirect3D,me);
211 * // ...
214 * // ...
216 * static ICOM_VTABLE(IDirect3D) d3dvt = {
218 * IDirect3D_fnQueryInterface,
219 * IUnknown_fnAdd,
220 * IUnknown_fnAdd2
221 * },
222 * IDirect3D_fnInitialize,
223 * IDirect3D_fnSetWidth
224 * };
226 * Comments:
227 * - We first define what the interface really contains. This is th e_IDirect3D structure. The
228 * first field must of course be the virtual table pointer. Everything else is free.
229 * - Then we predeclare our static virtual table variable, we will need its address in some
230 * methods to initialize the virtual table pointer of the returned interface objects.
231 * - Then we implement the interface methods. To match what has been declared in the header file
232 * they must take a pointer to a IDirect3D structure so we must cast it to an _IDirect3D so that
233 * we can manipulate the fields. This is performed by the ICOM_THIS macro.
234 * - Finally we initialize the virtual table. The inherited methods must be in curly brackets to
235 * match the parent interface's virtual table definition.
239 #define ICOM_VTABLE(iface) iface##_VTABLE
242 #if defined(__cplusplus) && !defined(CINTERFACE)
243 /* C++ interface */
245 #define ICOM_BEGIN(iface,ibase) \
246 typedef struct iface: public ibase {
248 #define ICOM_METHOD(ret,xfn) \
249 private: ret (CALLBACK *fn##xfn)(ICOM_INTERFACE* me); \
250 public: inline ret (CALLBACK xfn)(void) { return ((ICOM_INTERFACE*)t.lpvtbl)->fn##xfn(this); };
252 #define ICOM_METHOD1(ret,xfn,ta,na) \
253 private: ret (CALLBACK *fn##xfn)(ICOM_INTERFACE* me,ta a); \
254 public: inline ret (CALLBACK xfn)(ta a) { return ((ICOM_INTERFACE*)t.lpvtbl)->fn##xfn(this,a); };
256 #define ICOM_METHOD2(ret,xfn,ta,na,tb,nb) \
257 private: ret (CALLBACK *fn##xfn)(ICOM_INTERFACE* me,ta a,tb b); \
258 public: inline ret (CALLBACK xfn)(ta a,tb b) { return ((ICOM_INTERFACE*)t.lpvtbl)->fn##xfn(this,a,b); };
260 #define ICOM_METHOD3(ret,xfn,ta,na,tb,nb,tc,nc) \
261 private: ret (CALLBACK *fn##xfn)(ICOM_INTERFACE* me,ta a,tb b,tc c); \
262 public: inline ret (CALLBACK xfn)(ta a,tb b,tc c) { return ((ICOM_INTERFACE*)t.lpvtbl)->fn##xfn(this,a,b,c); };
264 #define ICOM_METHOD4(ret,xfn,ta,na,tb,nb,tc,nc,td,nd) \
265 private: ret (CALLBACK *fn##xfn)(ICOM_INTERFACE* me,ta a,tb b,tc c,td d); \
266 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); };
268 #define ICOM_METHOD5(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne) \
269 private: ret (CALLBACK *fn##xfn)(ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e); \
270 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); };
272 #define ICOM_METHOD6(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf) \
273 private: ret (CALLBACK *fn##xfn)(ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e,tf f); \
274 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); };
276 #define ICOM_METHOD7(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng) \
277 private: ret (CALLBACK *fn##xfn)(ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e,tf f,tg g); \
278 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); };
281 #define ICOM_CMETHOD(ret,xfn) \
282 private: ret (CALLBACK *fn##xfn)(const ICOM_INTERFACE* me); \
283 public: inline ret (CALLBACK xfn)(void) const { return ((ICOM_INTERFACE*)t.lpvtbl)->fn##xfn(this); };
285 #define ICOM_CMETHOD1(ret,xfn,ta,na) \
286 private: ret (CALLBACK *fn##xfn)(const ICOM_INTERFACE* me,ta a); \
287 public: inline ret (CALLBACK xfn)(ta a) const { return ((ICOM_INTERFACE*)t.lpvtbl)->fn##xfn(this,a); };
289 #define ICOM_CMETHOD2(ret,xfn,ta,na,tb,nb) \
290 private: ret (CALLBACK *fn##xfn)(const ICOM_INTERFACE* me,ta a,tb b); \
291 public: inline ret (CALLBACK xfn)(ta a,tb b) const { return ((ICOM_INTERFACE*)t.lpvtbl)->fn##xfn(this,a,b); };
293 #define ICOM_CMETHOD3(ret,xfn,ta,na,tb,nb,tc,nc) \
294 private: ret (CALLBACK *fn##xfn)(const ICOM_INTERFACE* me,ta a,tb b,tc c); \
295 public: inline ret (CALLBACK xfn)(ta a,tb b,tc c) const { return ((ICOM_INTERFACE*)t.lpvtbl)->fn##xfn(this,a,b,c); };
297 #define ICOM_CMETHOD4(ret,xfn,ta,na,tb,nb,tc,nc,td,nd) \
298 private: ret (CALLBACK *fn##xfn)(const ICOM_INTERFACE* me,ta a,tb b,tc c,td d); \
299 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); };
301 #define ICOM_CMETHOD5(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne) \
302 private: ret (CALLBACK *fn##xfn)(const ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e); \
303 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); };
305 #define ICOM_CMETHOD6(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf) \
306 private: ret (CALLBACK *fn##xfn)(const ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e,tf f); \
307 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); };
309 #define ICOM_CMETHOD7(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng) \
310 private: ret (CALLBACK *fn##xfn)(const ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e,tf f,tg g); \
311 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); };
314 #define ICOM_END(iface) \
317 #define ICOM_ICALL(ibase, xfn, p) this_is_a_syntax_error
318 #define ICOM_ICALL1(ibase, xfn, p,a) this_is_a_syntax_error
319 #define ICOM_ICALL2(ibase, xfn, p,a,b) this_is_a_syntax_error
320 #define ICOM_ICALL3(ibase, xfn, p,a,b,c) this_is_a_syntax_error
321 #define ICOM_ICALL4(ibase, xfn, p,a,b,c,d) this_is_a_syntax_error
322 #define ICOM_ICALL5(ibase, xfn, p,a,b,c,d,e) this_is_a_syntax_error
323 #define ICOM_ICALL6(ibase, xfn, p,a,b,c,d,e,f) this_is_a_syntax_error
324 #define ICOM_ICALL7(ibase, xfn, p,a,b,c,d,e,f,g) this_is_a_syntax_error
326 #define ICOM_CALL(xfn, p) this_is_a_syntax_error
327 #define ICOM_CALL1(xfn, p,a) this_is_a_syntax_error
328 #define ICOM_CALL2(xfn, p,a,b) this_is_a_syntax_error
329 #define ICOM_CALL3(xfn, p,a,b,c) this_is_a_syntax_error
330 #define ICOM_CALL4(xfn, p,a,b,c,d) this_is_a_syntax_error
331 #define ICOM_CALL5(xfn, p,a,b,c,d,e) this_is_a_syntax_error
332 #define ICOM_CALL6(xfn, p,a,b,c,d,e,f) this_is_a_syntax_error
333 #define ICOM_CALL7(xfn, p,a,b,c,d,e,f,g) this_is_a_syntax_error
336 #else
337 /* C interface */
340 #define ICOM_BEGIN(iface,ibase) \
341 typedef struct ICOM_VTABLE(iface) ICOM_VTABLE(iface); \
342 struct iface { \
343 const ICOM_VTABLE(iface)* lpvtbl; \
344 }; \
345 struct ICOM_VTABLE(iface) { \
346 ICOM_VTABLE(ibase) bvt;
348 #define ICOM_METHOD(ret, xfn) \
349 ret (CALLBACK *fn##xfn)(ICOM_INTERFACE* me);
351 #define ICOM_METHOD1(ret,xfn,ta,na) \
352 ret (CALLBACK *fn##xfn)(ICOM_INTERFACE* me,ta a);
354 #define ICOM_METHOD2(ret,xfn,ta,na,tb,nb) \
355 ret (CALLBACK *fn##xfn)(ICOM_INTERFACE* me,ta a,tb b);
357 #define ICOM_METHOD3(ret,xfn,ta,na,tb,nb,tc,nc) \
358 ret (CALLBACK *fn##xfn)(ICOM_INTERFACE* me,ta a,tb b,tc c);
360 #define ICOM_METHOD4(ret,xfn,ta,na,tb,nb,tc,nc,td,nd) \
361 ret (CALLBACK *fn##xfn)(ICOM_INTERFACE* me,ta a,tb b,tc c,td d);
363 #define ICOM_METHOD5(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne) \
364 ret (CALLBACK *fn##xfn)(ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e);
366 #define ICOM_METHOD6(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf) \
367 ret (CALLBACK *fn##xfn)(ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e,tf f);
369 #define ICOM_METHOD7(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng) \
370 ret (CALLBACK *fn##xfn)(ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e,tf f,tg g);
373 #define ICOM_CMETHOD(ret, xfn) \
374 ret (CALLBACK *fn##xfn)(const ICOM_INTERFACE* me);
376 #define ICOM_CMETHOD1(ret,xfn,ta,na) \
377 ret (CALLBACK *fn##xfn)(const ICOM_INTERFACE* me,ta a);
379 #define ICOM_CMETHOD2(ret,xfn,ta,na,tb,nb) \
380 ret (CALLBACK *fn##xfn)(const ICOM_INTERFACE* me,ta a,tb b);
382 #define ICOM_CMETHOD3(ret,xfn,ta,na,tb,nb,tc,nc) \
383 ret (CALLBACK *fn##xfn)(const ICOM_INTERFACE* me,ta a,tb b,tc c);
385 #define ICOM_CMETHOD4(ret,xfn,ta,na,tb,nb,tc,nc,td,nd) \
386 ret (CALLBACK *fn##xfn)(const ICOM_INTERFACE* me,ta a,tb b,tc c,td d);
388 #define ICOM_CMETHOD5(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne) \
389 ret (CALLBACK *fn##xfn)(const ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e);
391 #define ICOM_CMETHOD6(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf) \
392 ret (CALLBACK *fn##xfn)(const ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e,tf f);
394 #define ICOM_CMETHOD7(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng) \
395 ret (CALLBACK *fn##xfn)(const ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e,tf f,tg g);
397 #define ICOM_END(iface) \
400 #define ICOM_ICALL(ibase, xfn, p) ((ICOM_VTABLE(ibase)*)(p)->lpvtbl)->fn##xfn((ibase*)p)
401 #define ICOM_ICALL1(ibase, xfn, p,a) ((ICOM_VTABLE(ibase)*)(p)->lpvtbl)->fn##xfn((ibase*)p,a)
402 #define ICOM_ICALL2(ibase, xfn, p,a,b) ((ICOM_VTABLE(ibase)*)(p)->lpvtbl)->fn##xfn((ibase*)p,a,b)
403 #define ICOM_ICALL3(ibase, xfn, p,a,b,c) ((ICOM_VTABLE(ibase)*)(p)->lpvtbl)->fn##xfn((ibase*)p,a,b,c)
404 #define ICOM_ICALL4(ibase, xfn, p,a,b,c,d) ((ICOM_VTABLE(ibase)*)(p)->lpvtbl)->fn##xfn((ibase*)p,a,b,c,d)
405 #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)
406 #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)
407 #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)
409 #define ICOM_CALL(xfn, p) (p)->lpvtbl->fn##xfn(p)
410 #define ICOM_CALL1(xfn, p,a) (p)->lpvtbl->fn##xfn(p,a)
411 #define ICOM_CALL2(xfn, p,a,b) (p)->lpvtbl->fn##xfn(p,a,b)
412 #define ICOM_CALL3(xfn, p,a,b,c) (p)->lpvtbl->fn##xfn(p,a,b,c)
413 #define ICOM_CALL4(xfn, p,a,b,c,d) (p)->lpvtbl->fn##xfn(p,a,b,c,d)
414 #define ICOM_CALL5(xfn, p,a,b,c,d,e) (p)->lpvtbl->fn##xfn(p,a,b,c,d,e)
415 #define ICOM_CALL6(xfn, p,a,b,c,d,e,f) (p)->lpvtbl->fn##xfn(p,a,b,c,d,e,f)
416 #define ICOM_CALL7(xfn, p,a,b,c,d,e,f,g) (p)->lpvtbl->fn##xfn(p,a,b,c,d,e,f,g)
419 #define ICOM_THIS(iface,me) struct _##iface* this=(struct _##iface*)me
420 #define ICOM_CTHIS(iface,me) const _##iface* this=(const _##iface*)me
422 #endif
425 /* FIXME: compobj.h seems to be obsolete (replaced by objbase.h!) but it still contains REFIID */
426 #include "compobj.h"
428 typedef struct IUnknown IUnknown ,*LPUNKNOWN;
431 /*****************************************************************************
432 * IUnknown interface
434 #define ICOM_INTERFACE IUnknown
435 #if defined(__cplusplus) && !defined(CINTERFACE)
436 struct IUnknown {
437 union {
438 const void* lpvtbl;
439 HRESULT (CALLBACK *fnQueryInterface)(IUnknown* me, REFIID riid, LPVOID* ppvObj);
440 } t;
441 inline int QueryInterface(REFIID a, LPVOID* b) { return ((IUnknown*)t.lpvtbl)->t.fnQueryInterface(this,a,b); }
442 #else
443 typedef struct ICOM_VTABLE(IUnknown) ICOM_VTABLE(IUnknown);
444 struct IUnknown {
445 ICOM_VTABLE(IUnknown)* lpvtbl;
447 struct ICOM_VTABLE(IUnknown) {
448 ICOM_METHOD2(HRESULT,QueryInterface,REFIID,riid, LPVOID*,ppvObj)
449 #endif
451 ICOM_METHOD (ULONG,AddRef)
452 ICOM_METHOD (ULONG,Release)
453 #ifdef __WRC__
454 }; /* FIXME: WRC does not support function macros and it is ICOM_END that is supposed to close the class */
455 #else
456 ICOM_END(IUnknown)
457 #endif
458 #undef ICOM_INTERFACE
460 #if !defined(__cplusplus) || defined(CINTERFACE)
461 /*** IUnknown methods ***/
462 #define IUnknown_QueryInterface(p,a,b) ICOM_CALL2(QueryInterface,p,a,b)
463 #define IUnknown_AddRef(p) ICOM_CALL (AddRef,p)
464 #define IUnknown_Release(p) ICOM_CALL (Release,p)
465 #endif
468 #endif /* __WINE_OBJBASE_H */