Added an ICOM_FN that generates either fn##xfn or sfn as appropriate.
[wine.git] / include / wine / obj_base.h
blob74982b860dff12731916ece1de3a17613eb6c57f
1 /*
2 * This file defines the macros and types necessary to define COM interfaces,
3 * and the three most basic COM interfaces: IUnknown, IMalloc and IClassFactory.
4 */
6 #ifndef __WINE_WINE_OBJ_BASE_H
7 #define __WINE_WINE_OBJ_BASE_H
9 /*****************************************************************************
10 * define ICOM_MSVTABLE_COMPAT
11 * to implement the microsoft com vtable compatibility workaround for g++.
13 * NOTE: Turning this option on will produce a winelib that is incompatible
14 * with the binary emulator.
16 * If the compiler supports the com_interface attribute, leave this off, and
17 * define the ICOM_USE_COM_INTERFACE_ATTRIBUTE macro below. This may also
18 * require the addition of the -vtable-thunks option for g++.
20 * If you aren't interested in Winelib C++ compatibility at all, leave both
21 * options off.
23 * The preferable method for using ICOM_USE_COM_INTERFACE_ATTRIBUTE macro
24 * would be to define it only for your Winelib application. This allows you
25 * to have both binary and Winelib compatibility for C and C++ at the same
26 * time :)
28 /* #define ICOM_MSVTABLE_COMPAT 1 */
29 /* #define ICOM_USE_COM_INTERFACE_ATTRIBUTE 1 */
31 /*****************************************************************************
32 * Defines the basic types
34 #include "wtypes.h"
35 #include "guiddef.h"
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
42 #ifndef NONAMELESSSTRUCT
43 #define LISet32(li, v) ((li).HighPart = (v) < 0 ? -1 : 0, (li).LowPart = (v))
44 #define ULISet32(li, v) ((li).HighPart = 0, (li).LowPart = (v))
45 #else
46 #define LISet32(li, v) ((li).s.HighPart = (v) < 0 ? -1 : 0, (li).s.LowPart = (v))
47 #define ULISet32(li, v) ((li).s.HighPart = 0, (li).s.LowPart = (v))
48 #endif
50 /*****************************************************************************
51 * GUID API
53 HRESULT WINAPI StringFromCLSID16(REFCLSID id, LPOLESTR16*);
54 HRESULT WINAPI StringFromCLSID(REFCLSID id, LPOLESTR*);
56 HRESULT WINAPI CLSIDFromString16(LPCOLESTR16, CLSID *);
57 HRESULT WINAPI CLSIDFromString(LPCOLESTR, CLSID *);
59 HRESULT WINAPI CLSIDFromProgID16(LPCOLESTR16 progid, LPCLSID riid);
60 HRESULT WINAPI CLSIDFromProgID(LPCOLESTR progid, LPCLSID riid);
62 HRESULT WINAPI ProgIDFromCLSID(REFCLSID clsid, LPOLESTR *lplpszProgID);
65 INT WINAPI StringFromGUID2(REFGUID id, LPOLESTR str, INT cmax);
68 /*****************************************************************************
69 * Macros to define a COM interface
72 * The goal of the following set of definitions is to provide a way to use the same
73 * header file definitions to provide both a C interface and a C++ object oriented
74 * interface to COM interfaces. The type of interface is selected automatically
75 * depending on the language but it is always possible to get the C interface in C++
76 * by defining CINTERFACE.
78 * It is based on the following assumptions:
79 * - all COM interfaces derive from IUnknown, this should not be a problem.
80 * - the header file only defines the interface, the actual fields are defined
81 * separately in the C file implementing the interface.
83 * The natural approach to this problem would be to make sure we get a C++ class and
84 * virtual methods in C++ and a structure with a table of pointer to functions in C.
85 * Unfortunately the layout of the virtual table is compiler specific, the layout of
86 * g++ virtual tables is not the same as that of an egcs virtual table which is not the
87 * same as that generated by Visual C+. There are workarounds to make the virtual tables
88 * compatible via padding but unfortunately the one which is imposed to the WINE emulator
89 * by the Windows binaries, i.e. the Visual C++ one, is the most compact of all.
91 * So the solution I finally adopted does not use virtual tables. Instead I use inline
92 * non virtual methods that dereference the method pointer themselves and perform the call.
94 * Let's take Direct3D as an example:
96 * #define ICOM_INTERFACE IDirect3D
97 * #define IDirect3D_METHODS \
98 * ICOM_METHOD1(HRESULT,Initialize, REFIID,) \
99 * ICOM_METHOD2(HRESULT,EnumDevices, LPD3DENUMDEVICESCALLBACK,, LPVOID,) \
100 * ICOM_METHOD2(HRESULT,CreateLight, LPDIRECT3DLIGHT*,, IUnknown*,) \
101 * ICOM_METHOD2(HRESULT,CreateMaterial,LPDIRECT3DMATERIAL*,, IUnknown*,) \
102 * ICOM_METHOD2(HRESULT,CreateViewport,LPDIRECT3DVIEWPORT*,, IUnknown*,) \
103 * ICOM_METHOD2(HRESULT,FindDevice, LPD3DFINDDEVICESEARCH,, LPD3DFINDDEVICERESULT,)
104 * #define IDirect3D_IMETHODS \
105 * IUnknown_IMETHODS \
106 * IDirect3D_METHODS
107 * ICOM_DEFINE(IDirect3D,IUnknown)
108 * #undef ICOM_INTERFACE
110 * #ifdef ICOM_CINTERFACE
111 * // *** IUnknown methods *** //
112 * #define IDirect3D_QueryInterface(p,a,b) ICOM_CALL2(QueryInterface,p,a,b)
113 * #define IDirect3D_AddRef(p) ICOM_CALL (AddRef,p)
114 * #define IDirect3D_Release(p) ICOM_CALL (Release,p)
115 * // *** IDirect3D methods *** //
116 * #define IDirect3D_Initialize(p,a) ICOM_CALL1(Initialize,p,a)
117 * #define IDirect3D_EnumDevices(p,a,b) ICOM_CALL2(EnumDevice,p,a,b)
118 * #define IDirect3D_CreateLight(p,a,b) ICOM_CALL2(CreateLight,p,a,b)
119 * #define IDirect3D_CreateMaterial(p,a,b) ICOM_CALL2(CreateMaterial,p,a,b)
120 * #define IDirect3D_CreateViewport(p,a,b) ICOM_CALL2(CreateViewport,p,a,b)
121 * #define IDirect3D_FindDevice(p,a,b) ICOM_CALL2(FindDevice,p,a,b)
122 * #endif
124 * Comments:
125 * - The ICOM_INTERFACE macro is used in the ICOM_METHOD macros to define the type of the 'this'
126 * pointer. Defining this macro here saves us the trouble of having to repeat the interface
127 * name everywhere. Note however that because of the way macros work, a macro like ICOM_METHOD1
128 * cannot use 'ICOM_INTERFACE##_VTABLE' because this would give 'ICOM_INTERFACE_VTABLE' and not
129 * 'IDirect3D_VTABLE'.
130 * - ICOM_METHODS defines the methods specific to this interface. It is then aggregated with the
131 * inherited methods to form ICOM_IMETHODS.
132 * - ICOM_IMETHODS defines the list of methods that are inheritable from this interface. It must
133 * be written manually (rather than using a macro to generate the equivalent code) to avoid
134 * macro recursion (which compilers don't like).
135 * - The ICOM_DEFINE finally declares all the structures necessary for the interface. We have to
136 * explicitly use the interface name for macro expansion reasons again.
137 * Inherited methods are inherited in C by using the IDirect3D_METHODS macro and the parent's
138 * Xxx_IMETHODS macro. In C++ we need only use the IDirect3D_METHODS since method inheritance
139 * is taken care of by the language.
140 * - In C++ the ICOM_METHOD macros generate a function prototype and a call to a function pointer
141 * method. This means using once 't1 p1, t2 p2, ...' and once 'p1, p2' without the types. The
142 * only way I found to handle this is to have one ICOM_METHOD macro per number of parameters and
143 * to have it take only the type information (with const if necessary) as parameters.
144 * The 'undef ICOM_INTERFACE' is here to remind you that using ICOM_INTERFACE in the following
145 * macros will not work. This time it's because the ICOM_CALL macro expansion is done only once
146 * the 'IDirect3D_Xxx' macro is expanded. And by that time ICOM_INTERFACE will be long gone
147 * anyway.
148 * - You may have noticed the double commas after each parameter type. This allows you to put the
149 * name of that parameter which I think is good for documentation. It is not required and since
150 * I did not know what to put there for this example (I could only find doc about IDirect3D2),
151 * I left them blank.
152 * - Finally the set of 'IDirect3D_Xxx' macros is a standard set of macros defined to ease access
153 * to the interface methods in C. Unfortunately I don't see any way to avoid having to duplicate
154 * the inherited method definitions there. This time I could have used a trick to use only one
155 * macro whatever the number of parameters but I prefered to have it work the same way as above.
156 * - You probably have noticed that we don't define the fields we need to actually implement this
157 * interface: reference count, pointer to other resources and miscellaneous fields. That's
158 * because these interfaces are just that: interfaces. They may be implemented more than once, in
159 * different contexts and sometimes not even in Wine. Thus it would not make sense to impose
160 * that the interface contains some specific fields.
163 * In C this gives:
164 * typedef struct IDirect3DVtbl IDirect3DVtbl;
165 * struct IDirect3D {
166 * IDirect3DVtbl* lpVtbl;
167 * };
168 * struct IDirect3DVtbl {
169 * HRESULT (*fnQueryInterface)(IDirect3D* me, REFIID riid, LPVOID* ppvObj);
170 * ULONG (*fnQueryInterface)(IDirect3D* me);
171 * ULONG (*fnQueryInterface)(IDirect3D* me);
172 * HRESULT (*fnInitialize)(IDirect3D* me, REFIID a);
173 * HRESULT (*fnEnumDevices)(IDirect3D* me, LPD3DENUMDEVICESCALLBACK a, LPVOID b);
174 * HRESULT (*fnCreateLight)(IDirect3D* me, LPDIRECT3DLIGHT* a, IUnknown* b);
175 * HRESULT (*fnCreateMaterial)(IDirect3D* me, LPDIRECT3DMATERIAL* a, IUnknown* b);
176 * HRESULT (*fnCreateViewport)(IDirect3D* me, LPDIRECT3DVIEWPORT* a, IUnknown* b);
177 * HRESULT (*fnFindDevice)(IDirect3D* me, LPD3DFINDDEVICESEARCH a, LPD3DFINDDEVICERESULT b);
178 * };
180 * #ifdef ICOM_CINTERFACE
181 * // *** IUnknown methods *** //
182 * #define IDirect3D_QueryInterface(p,a,b) (p)->lpVtbl->fnQueryInterface(p,a,b)
183 * #define IDirect3D_AddRef(p) (p)->lpVtbl->fnAddRef(p)
184 * #define IDirect3D_Release(p) (p)->lpVtbl->fnRelease(p)
185 * // *** IDirect3D methods *** //
186 * #define IDirect3D_Initialize(p,a) (p)->lpVtbl->fnInitialize(p,a)
187 * #define IDirect3D_EnumDevices(p,a,b) (p)->lpVtbl->fnEnumDevice(p,a,b)
188 * #define IDirect3D_CreateLight(p,a,b) (p)->lpVtbl->fnCreateLight(p,a,b)
189 * #define IDirect3D_CreateMaterial(p,a,b) (p)->lpVtbl->fnCreateMaterial(p,a,b)
190 * #define IDirect3D_CreateViewport(p,a,b) (p)->lpVtbl->fnCreateViewport(p,a,b)
191 * #define IDirect3D_FindDevice(p,a,b) (p)->lpVtbl->fnFindDevice(p,a,b)
192 * #endif
194 * Comments:
195 * - IDirect3D only contains a pointer to the IDirect3D virtual/jump table. This is the only thing
196 * the user needs to know to use the interface. Of course the structure we will define to
197 * implement this interface will have more fields but the first one will match this pointer.
198 * - The code generated by ICOM_DEFINE defines both the structure representing the interface and
199 * the structure for the jump table. ICOM_DEFINE uses the parent's Xxx_IMETHODS macro to
200 * automatically repeat the prototypes of all the inherited methods and then uses IDirect3D_METHODS
201 * to define the IDirect3D methods.
202 * - Each method is declared as a pointer to function field in the jump table. The implementation
203 * will fill this jump table with appropriate values, probably using a static variable, and
204 * initialize the lpVtbl field to point to this variable.
205 * - The IDirect3D_Xxx macros then just derefence the lpVtbl pointer and use the function pointer
206 * corresponding to the macro name. This emulates the behavior of a virtual table and should be
207 * just as fast.
208 * - This C code should be quite compatible with the Windows headers both for code that uses COM
209 * interfaces and for code implementing a COM interface.
212 * And in C++ (with gcc's g++):
214 * typedef struct IDirect3D: public IUnknown {
215 * private: HRESULT (*fnInitialize)(IDirect3D* me, REFIID a);
216 * public: inline HRESULT Initialize(REFIID a) { return ((IDirect3D*)t.lpVtbl)->fnInitialize(this,a); };
217 * private: HRESULT (*fnEnumDevices)(IDirect3D* me, LPD3DENUMDEVICESCALLBACK a, LPVOID b);
218 * public: inline HRESULT EnumDevices(LPD3DENUMDEVICESCALLBACK a, LPVOID b)
219 * { return ((IDirect3D*)t.lpVtbl)->fnEnumDevices(this,a,b); };
220 * private: HRESULT (*fnCreateLight)(IDirect3D* me, LPDIRECT3DLIGHT* a, IUnknown* b);
221 * public: inline HRESULT CreateLight(LPDIRECT3DLIGHT* a, IUnknown* b)
222 * { return ((IDirect3D*)t.lpVtbl)->fnCreateLight(this,a,b); };
223 * private: HRESULT (*fnCreateMaterial)(IDirect3D* me, LPDIRECT3DMATERIAL* a, IUnknown* b);
224 * public: inline HRESULT CreateMaterial(LPDIRECT3DMATERIAL* a, IUnknown* b)
225 * { return ((IDirect3D*)t.lpVtbl)->fnCreateMaterial(this,a,b); };
226 * private: HRESULT (*fnCreateViewport)(IDirect3D* me, LPDIRECT3DVIEWPORT* a, IUnknown* b);
227 * public: inline HRESULT CreateViewport(LPDIRECT3DVIEWPORT* a, IUnknown* b)
228 * { return ((IDirect3D*)t.lpVtbl)->fnCreateViewport(this,a,b); };
229 * private: HRESULT (*fnFindDevice)(IDirect3D* me, LPD3DFINDDEVICESEARCH a, LPD3DFINDDEVICERESULT b);
230 * public: inline HRESULT FindDevice(LPD3DFINDDEVICESEARCH a, LPD3DFINDDEVICERESULT b)
231 * { return ((IDirect3D*)t.lpVtbl)->fnFindDevice(this,a,b); };
232 * };
234 * Comments:
235 * - In C++ IDirect3D does double duty as both the virtual/jump table and as the interface
236 * definition. The reason for this is to avoid having to duplicate the mehod definitions: once
237 * to have the function pointers in the jump table and once to have the methods in the interface
238 * class. Here one macro can generate both. This means though that the first pointer, t.lpVtbl
239 * defined in IUnknown, must be interpreted as the jump table pointer if we interpret the
240 * structure as the the interface class, and as the function pointer to the QueryInterface
241 * method, t.fnQueryInterface, if we interpret the structure as the jump table. Fortunately this
242 * gymnastic is entirely taken care of in the header of IUnknown.
243 * - Of course in C++ we use inheritance so that we don't have to duplicate the method definitions.
244 * - Since IDirect3D does double duty, each ICOM_METHOD macro defines both a function pointer and
245 * a non-vritual inline method which dereferences it and calls it. This way this method behaves
246 * just like a virtual method but does not create a true C++ virtual table which would break the
247 * structure layout. If you look at the implementation of these methods you'll notice that they
248 * would not work for void functions. We have to return something and fortunately this seems to
249 * be what all the COM methods do (otherwise we would need another set of macros).
250 * - Note how the ICOM_METHOD generates both function prototypes mixing types and formal parameter
251 * names and the method invocation using only the formal parameter name. This is the reason why
252 * we need different macros to handle different numbers of parameters.
253 * - Finally there is no IDirect3D_Xxx macro. These are not needed in C++ unless the CINTERFACE
254 * macro is defined in which case we would not be here.
255 * - This C++ code works well for code that just uses COM interfaces. But it will not work with
256 * C++ code implement a COM interface. That's because such code assumes the interface methods
257 * are declared as virtual C++ methods which is not the case here.
260 * Implementing a COM interface.
262 * This continues the above example. This example assumes that the implementation is in C.
264 * typedef struct _IDirect3D {
265 * void* lpVtbl;
266 * // ...
268 * } _IDirect3D;
270 * static ICOM_VTABLE(IDirect3D) d3dvt;
272 * // implement the IDirect3D methods here
274 * int IDirect3D_fnQueryInterface(IDirect3D* me)
276 * ICOM_THIS(IDirect3D,me);
277 * // ...
280 * // ...
282 * static ICOM_VTABLE(IDirect3D) d3dvt = {
283 * ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
284 * IDirect3D_fnQueryInterface,
285 * IDirect3D_fnAdd,
286 * IDirect3D_fnAdd2,
287 * IDirect3D_fnInitialize,
288 * IDirect3D_fnSetWidth
289 * };
291 * Comments:
292 * - We first define what the interface really contains. This is th e_IDirect3D structure. The
293 * first field must of course be the virtual table pointer. Everything else is free.
294 * - Then we predeclare our static virtual table variable, we will need its address in some
295 * methods to initialize the virtual table pointer of the returned interface objects.
296 * - Then we implement the interface methods. To match what has been declared in the header file
297 * they must take a pointer to a IDirect3D structure and we must cast it to an _IDirect3D so that
298 * we can manipulate the fields. This is performed by the ICOM_THIS macro.
299 * - Finally we initialize the virtual table.
304 #if !defined(__cplusplus) || defined(CINTERFACE)
305 #define ICOM_CINTERFACE 1
306 #endif
308 #ifndef ICOM_CINTERFACE
309 /* C++ interface */
311 #define ICOM_METHOD(ret,xfn) \
312 public: virtual ret CALLBACK (xfn)(void) = 0;
313 #define ICOM_METHOD1(ret,xfn,ta,na) \
314 public: virtual ret CALLBACK (xfn)(ta a) = 0;
315 #define ICOM_METHOD2(ret,xfn,ta,na,tb,nb) \
316 public: virtual ret CALLBACK (xfn)(ta a,tb b) = 0;
317 #define ICOM_METHOD3(ret,xfn,ta,na,tb,nb,tc,nc) \
318 public: virtual ret CALLBACK (xfn)(ta a,tb b,tc c) = 0;
319 #define ICOM_METHOD4(ret,xfn,ta,na,tb,nb,tc,nc,td,nd) \
320 public: virtual ret CALLBACK (xfn)(ta a,tb b,tc c,td d) = 0;
321 #define ICOM_METHOD5(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne) \
322 public: virtual ret CALLBACK (xfn)(ta a,tb b,tc c,td d,te e) = 0;
323 #define ICOM_METHOD6(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf) \
324 public: virtual ret CALLBACK (xfn)(ta a,tb b,tc c,td d,te e,tf f) = 0;
325 #define ICOM_METHOD7(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng) \
326 public: virtual ret CALLBACK (xfn)(ta a,tb b,tc c,td d,te e,tf f,tg g) = 0;
327 #define ICOM_METHOD8(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng,th,nh) \
328 public: virtual ret CALLBACK (xfn)(ta a,tb b,tc c,td d,te e,tf f,tg g,th h) = 0;
329 #define ICOM_METHOD9(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng,th,nh,ti,ni) \
330 public: virtual ret CALLBACK (xfn)(ta a,tb b,tc c,td d,te e,tf f,tg g,th h,ti i) = 0;
331 #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) \
332 public: 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;
333 #define ICOM_METHOD11(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng,th,nh,ti,ni,tj,nj,tk,nk) \
334 public: virtual ret CALLBACK (xfn)(ta a,tb b,tc c,td d,te e,tf f,tg g,th h,ti i,tj j,tk k) = 0;
337 #define ICOM_VMETHOD(xfn) \
338 public: virtual void CALLBACK (xfn)(void) = 0;
339 #define ICOM_VMETHOD1(xfn,ta,na) \
340 public: virtual void CALLBACK (xfn)(ta a) = 0;
341 #define ICOM_VMETHOD2(xfn,ta,na,tb,nb) \
342 public: virtual void CALLBACK (xfn)(ta a,tb b) = 0;
343 #define ICOM_VMETHOD3(xfn,ta,na,tb,nb,tc,nc) \
344 public: virtual void CALLBACK (xfn)(ta a,tb b,tc c) = 0;
345 #define ICOM_VMETHOD4(xfn,ta,na,tb,nb,tc,nc,td,nd) \
346 public: virtual void CALLBACK (xfn)(ta a,tb b,tc c,td d) = 0;
347 #define ICOM_VMETHOD5(xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne) \
348 public: virtual void CALLBACK (xfn)(ta a,tb b,tc c,td d,te e) = 0;
349 #define ICOM_VMETHOD6(xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf) \
350 public: virtual void CALLBACK (xfn)(ta a,tb b,tc c,td d,te e,tf f) = 0;
351 #define ICOM_VMETHOD7(xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng) \
352 public: virtual void CALLBACK (xfn)(ta a,tb b,tc c,td d,te e,tf f,tg g) = 0;
353 #define ICOM_VMETHOD8(xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng,th,nh) \
354 public: virtual void CALLBACK (xfn)(ta a,tb b,tc c,td d,te e,tf f,tg g,th h) = 0;
355 #define ICOM_VMETHOD9(xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng,th,nh,ti,ni) \
356 public: virtual void CALLBACK (xfn)(ta a,tb b,tc c,td d,te e,tf f,tg g,th h,ti i) = 0;
357 #define ICOM_VMETHOD10(xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng,th,nh,ti,ni,tj,nj) \
358 public: virtual void CALLBACK (xfn)(ta a,tb b,tc c,td d,te e,tf f,tg g,th h,ti i, tj j) = 0;
359 #define ICOM_VMETHOD11(xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng,th,nh,ti,ni,tj,nj,tk,nk) \
360 public: virtual void CALLBACK (xfn)(ta a,tb b,tc c,td d,te e,tf f,tg g,th h,ti i, tj j, tk k) = 0;
363 #ifdef ICOM_USE_COM_INTERFACE_ATTRIBUTE
365 #define ICOM_DEFINE(iface,ibase) \
366 typedef struct iface: public ibase { \
367 iface##_METHODS \
368 } __attribute__ ((com_interface));
370 #else
372 #define ICOM_DEFINE(iface,ibase) \
373 typedef struct iface: public ibase { \
374 iface##_METHODS \
377 #endif /* ICOM_USE_COM_INTERFACE_ATTRIBUTE */
379 #define ICOM_FN(xfn) xfn
380 #define ICOM_VTBL(iface) (iface)
382 #else
383 /* C interface */
385 #ifdef __WINE__
386 #define ICOM_FN(xfn) fn##xfn
387 #else
388 #define ICOM_FN(xfn) xfn
389 #endif
391 #define ICOM_METHOD(ret,xfn) \
392 ret CALLBACK (*ICOM_FN(##xfn))(ICOM_INTERFACE* me);
393 #define ICOM_METHOD1(ret,xfn,ta,na) \
394 ret CALLBACK (*ICOM_FN(##xfn))(ICOM_INTERFACE* me,ta a);
395 #define ICOM_METHOD2(ret,xfn,ta,na,tb,nb) \
396 ret CALLBACK (*ICOM_FN(##xfn))(ICOM_INTERFACE* me,ta a,tb b);
397 #define ICOM_METHOD3(ret,xfn,ta,na,tb,nb,tc,nc) \
398 ret CALLBACK (*ICOM_FN(##xfn))(ICOM_INTERFACE* me,ta a,tb b,tc c);
399 #define ICOM_METHOD4(ret,xfn,ta,na,tb,nb,tc,nc,td,nd) \
400 ret CALLBACK (*ICOM_FN(##xfn))(ICOM_INTERFACE* me,ta a,tb b,tc c,td d);
401 #define ICOM_METHOD5(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne) \
402 ret CALLBACK (*ICOM_FN(##xfn))(ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e);
403 #define ICOM_METHOD6(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf) \
404 ret CALLBACK (*ICOM_FN(##xfn))(ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e,tf f);
405 #define ICOM_METHOD7(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng) \
406 ret CALLBACK (*ICOM_FN(##xfn))(ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e,tf f,tg g);
407 #define ICOM_METHOD8(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng,th,nh) \
408 ret CALLBACK (*ICOM_FN(##xfn))(ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e,tf f,tg g,th h);
409 #define ICOM_METHOD9(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng,th,nh,ti,ni) \
410 ret CALLBACK (*ICOM_FN(##xfn))(ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e,tf f,tg g,th h,ti i);
411 #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) \
412 ret CALLBACK (*ICOM_FN(##xfn))(ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e,tf f,tg g,th h,ti i,tj j);
413 #define ICOM_METHOD11(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng,th,nh,ti,ni,tj,nj,tk,nk) \
414 ret CALLBACK (*ICOM_FN(##xfn))(ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e,tf f,tg g,th h,ti i,tj j,tk k);
416 #define ICOM_VMETHOD(xfn) \
417 void CALLBACK (*ICOM_FN(##xfn))(ICOM_INTERFACE* me);
418 #define ICOM_VMETHOD1(xfn,ta,na) \
419 void CALLBACK (*ICOM_FN(##xfn))(ICOM_INTERFACE* me,ta a);
420 #define ICOM_VMETHOD2(xfn,ta,na,tb,nb) \
421 void CALLBACK (*ICOM_FN(##xfn))(ICOM_INTERFACE* me,ta a,tb b);
422 #define ICOM_VMETHOD3(xfn,ta,na,tb,nb,tc,nc) \
423 void CALLBACK (*ICOM_FN(##xfn))(ICOM_INTERFACE* me,ta a,tb b,tc c);
424 #define ICOM_VMETHOD4(xfn,ta,na,tb,nb,tc,nc,td,nd) \
425 void CALLBACK (*ICOM_FN(##xfn))(ICOM_INTERFACE* me,ta a,tb b,tc c,td d);
426 #define ICOM_VMETHOD5(xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne) \
427 void CALLBACK (*ICOM_FN(##xfn))(ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e);
428 #define ICOM_VMETHOD6(xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf) \
429 void CALLBACK (*ICOM_FN(##xfn))(ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e,tf f);
430 #define ICOM_VMETHOD7(xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng) \
431 void CALLBACK (*ICOM_FN(##xfn))(ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e,tf f,tg g);
432 #define ICOM_VMETHOD8(xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng,nh) \
433 void CALLBACK (*ICOM_FN(##xfn))(ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e,tf f,tg g,th h);
434 #define ICOM_VMETHOD9(xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng,th,nh,ni) \
435 void CALLBACK (*ICOM_FN(##xfn))(ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e,tf f,tg g,th h,ti i);
436 #define ICOM_VMETHOD10(xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng,th,nh,ti,ni,nj) \
437 void CALLBACK (*ICOM_FN(##xfn))(ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e,tf f,tg g,th h,ti i,tj j);
438 #define ICOM_VMETHOD11(xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng,th,nh,ti,ni,tj,nj,nk) \
439 void CALLBACK (*ICOM_FN(##xfn))(ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e,tf f,tg g,th h,ti i,tj j,tk k);
442 #define ICOM_VTABLE(iface) iface##Vtbl
443 #define ICOM_VFIELD(iface) ICOM_VTABLE(iface)* lpVtbl
444 #define ICOM_VTBL(iface) (iface)->lpVtbl
446 #ifdef ICOM_MSVTABLE_COMPAT
447 #define ICOM_DEFINE(iface,ibase) \
448 typedef struct ICOM_VTABLE(iface) ICOM_VTABLE(iface); \
449 struct iface { \
450 const ICOM_VFIELD(iface); \
451 }; \
452 struct ICOM_VTABLE(iface) { \
453 long dummyRTTI1; \
454 long dummyRTTI2; \
455 ibase##_IMETHODS \
456 iface##_METHODS \
458 #define ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE 0,0,
460 #else
461 #define ICOM_DEFINE(iface,ibase) \
462 typedef struct ICOM_VTABLE(iface) ICOM_VTABLE(iface); \
463 struct iface { \
464 const ICOM_VFIELD(iface); \
465 }; \
466 struct ICOM_VTABLE(iface) { \
467 ibase##_IMETHODS \
468 iface##_METHODS \
470 #define ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
471 #endif /* ICOM_MSVTABLE_COMPAT */
474 #define ICOM_THIS(impl,iface) impl* const This=(impl*)iface
475 #define ICOM_CTHIS(impl,iface) const impl* const This=(const impl*)iface
477 #endif /*ICOM_CINTERFACE */
479 #define ICOM_CALL(xfn, p) ICOM_VTBL(p)->ICOM_FN(##xfn)(p)
480 #define ICOM_CALL1(xfn, p,a) ICOM_VTBL(p)->ICOM_FN(##xfn)(p,a)
481 #define ICOM_CALL2(xfn, p,a,b) ICOM_VTBL(p)->ICOM_FN(##xfn)(p,a,b)
482 #define ICOM_CALL3(xfn, p,a,b,c) ICOM_VTBL(p)->ICOM_FN(##xfn)(p,a,b,c)
483 #define ICOM_CALL4(xfn, p,a,b,c,d) ICOM_VTBL(p)->ICOM_FN(##xfn)(p,a,b,c,d)
484 #define ICOM_CALL5(xfn, p,a,b,c,d,e) ICOM_VTBL(p)->ICOM_FN(##xfn)(p,a,b,c,d,e)
485 #define ICOM_CALL6(xfn, p,a,b,c,d,e,f) ICOM_VTBL(p)->ICOM_FN(##xfn)(p,a,b,c,d,e,f)
486 #define ICOM_CALL7(xfn, p,a,b,c,d,e,f,g) ICOM_VTBL(p)->ICOM_FN(##xfn)(p,a,b,c,d,e,f,g)
487 #define ICOM_CALL8(xfn, p,a,b,c,d,e,f,g,h) ICOM_VTBL(p)->ICOM_FN(##xfn)(p,a,b,c,d,e,f,g,h)
488 #define ICOM_CALL9(xfn, p,a,b,c,d,e,f,g,h,i) ICOM_VTBL(p)->ICOM_FN(##xfn)(p,a,b,c,d,e,f,g,h,i)
489 #define ICOM_CALL10(xfn, p,a,b,c,d,e,f,g,h,i,j) ICOM_VTBL(p)->ICOM_FN(##xfn)(p,a,b,c,d,e,f,g,h,i,j)
490 #define ICOM_CALL11(xfn, p,a,b,c,d,e,f,g,h,i,j,k) ICOM_VTBL(p)->ICOM_FN(##xfn)(p,a,b,c,d,e,f,g,h,i,j,k)
493 /*****************************************************************************
494 * Predeclare the interfaces
496 DEFINE_OLEGUID(IID_IClassFactory, 0x00000001L, 0, 0);
497 typedef struct IClassFactory IClassFactory, *LPCLASSFACTORY;
499 DEFINE_OLEGUID(IID_IMalloc, 0x00000002L, 0, 0);
500 typedef struct IMalloc IMalloc,*LPMALLOC;
502 DEFINE_OLEGUID(IID_IUnknown, 0x00000000L, 0, 0);
503 typedef struct IUnknown IUnknown, *LPUNKNOWN;
506 /*****************************************************************************
507 * IUnknown interface
509 #define ICOM_INTERFACE IUnknown
510 #define IUnknown_IMETHODS \
511 ICOM_METHOD2(HRESULT,QueryInterface,REFIID,riid, LPVOID*,ppvObj) \
512 ICOM_METHOD (ULONG,AddRef) \
513 ICOM_METHOD (ULONG,Release)
514 #ifdef ICOM_CINTERFACE
515 typedef struct ICOM_VTABLE(IUnknown) ICOM_VTABLE(IUnknown);
516 struct IUnknown {
517 ICOM_VFIELD(IUnknown);
518 #if defined(ICOM_USE_COM_INTERFACE_ATTRIBUTE)
519 } __attribute__ ((com_interface));
520 #else
522 #endif /* ICOM_US_COM_INTERFACE_ATTRIBUTE */
524 struct ICOM_VTABLE(IUnknown) {
525 #ifdef ICOM_MSVTABLE_COMPAT
526 long dummyRTTI1;
527 long dummyRTTI2;
528 #endif /* ICOM_MSVTABLE_COMPAT */
530 #else /* ICOM_CINTERFACE */
531 struct IUnknown {
533 #endif /* ICOM_CINTERFACE */
535 ICOM_METHOD2(HRESULT,QueryInterface,REFIID,riid, LPVOID*,ppvObj)
536 ICOM_METHOD (ULONG,AddRef)
537 ICOM_METHOD (ULONG,Release)
538 #if defined(ICOM_USE_COM_INTERFACE_ATTRIBUTE)
539 } __attribute__ ((com_interface));
540 #else
542 #endif /* ICOM_US_COM_INTERFACE_ATTRIBUTE */
544 #undef ICOM_INTERFACE
546 /*** IUnknown methods ***/
547 #define IUnknown_QueryInterface(p,a,b) ICOM_CALL2(QueryInterface,p,a,b)
548 #define IUnknown_AddRef(p) ICOM_CALL (AddRef,p)
549 #define IUnknown_Release(p) ICOM_CALL (Release,p)
551 /*****************************************************************************
552 * IClassFactory interface
554 #define ICOM_INTERFACE IClassFactory
555 #define IClassFactory_METHODS \
556 ICOM_METHOD3(HRESULT,CreateInstance, LPUNKNOWN,pUnkOuter, REFIID,riid, LPVOID*,ppvObject) \
557 ICOM_METHOD1(HRESULT,LockServer, BOOL,fLock)
558 #define IClassFactory_IMETHODS \
559 IUnknown_IMETHODS \
560 IClassFactory_METHODS
561 ICOM_DEFINE(IClassFactory,IUnknown)
562 #undef ICOM_INTERFACE
564 /*** IUnknown methods ***/
565 #define IClassFactory_QueryInterface(p,a,b) ICOM_CALL2(QueryInterface,p,a,b)
566 #define IClassFactory_AddRef(p) ICOM_CALL (AddRef,p)
567 #define IClassFactory_Release(p) ICOM_CALL (Release,p)
568 /*** IClassFactory methods ***/
569 #define IClassFactory_CreateInstance(p,a,b,c) ICOM_CALL3(CreateInstance,p,a,b,c)
570 #define IClassFactory_LockServer(p,a) ICOM_CALL1(LockServer,p,a)
573 /*****************************************************************************
574 * IMalloc interface
576 #define ICOM_INTERFACE IMalloc
577 #define IMalloc_METHODS \
578 ICOM_METHOD1 (LPVOID,Alloc, DWORD,cb) \
579 ICOM_METHOD2 (LPVOID,Realloc, LPVOID,pv, DWORD,cb) \
580 ICOM_VMETHOD1( Free, LPVOID,pv) \
581 ICOM_METHOD1(DWORD, GetSize, LPVOID,pv) \
582 ICOM_METHOD1(INT, DidAlloc, LPVOID,pv) \
583 ICOM_METHOD (VOID, HeapMinimize)
584 #define IMalloc_IMETHODS \
585 IUnknown_IMETHODS \
586 IMalloc_METHODS
587 ICOM_DEFINE(IMalloc,IUnknown)
588 #undef ICOM_INTERFACE
590 /*** IUnknown methods ***/
591 #define IMalloc_QueryInterface(p,a,b) ICOM_CALL2(QueryInterface,p,a,b)
592 #define IMalloc_AddRef(p) ICOM_CALL (AddRef,p)
593 #define IMalloc_Release(p) ICOM_CALL (Release,p)
594 /*** IMalloc32 methods ***/
595 #define IMalloc_Alloc(p,a) ICOM_CALL1(Alloc,p,a)
596 #define IMalloc_Realloc(p,a,b) ICOM_CALL2(Realloc,p,a,b)
597 #define IMalloc_Free(p,a) ICOM_CALL1(Free,p,a)
598 #define IMalloc_GetSize(p,a) ICOM_CALL1(GetSize,p,a)
599 #define IMalloc_DidAlloc(p,a) ICOM_CALL1(DidAlloc,p,a)
600 #define IMalloc_HeapMinimize(p) ICOM_CALL (HeapMinimize,p)
602 /* values passed to CoGetMalloc */
603 #define MEMCTX_TASK 1 /* private task memory */
604 #define MEMCTX_SHARED 2 /* shared memory */
605 #ifdef _MAC
606 #define MEMCTX_MACSYSTEM 3 /* system heap on mac */
607 #endif
608 /* mainly for internal use... */
609 #define MEMCTX_UNKNOWN -1
610 #define MEMCTX_SAME -2
612 HRESULT WINAPI CoGetMalloc(DWORD dwMemContext,LPMALLOC* lpMalloc);
614 LPVOID WINAPI CoTaskMemAlloc(ULONG size);
616 void WINAPI CoTaskMemFree(LPVOID ptr);
618 /* FIXME: unimplemented */
619 LPVOID WINAPI CoTaskMemRealloc(LPVOID ptr, ULONG size);
622 /*****************************************************************************
623 * Additional API
626 HRESULT WINAPI CoCreateGuid(GUID* pguid);
628 HINSTANCE WINAPI CoLoadLibrary(LPOLESTR lpszLibName, BOOL bAutoFree);
630 void WINAPI CoFreeAllLibraries(void);
632 void WINAPI CoFreeLibrary(HINSTANCE hLibrary);
634 void WINAPI CoFreeUnusedLibraries(void);
636 HRESULT WINAPI CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv);
638 HRESULT WINAPI CoGetClassObject(REFCLSID rclsid, DWORD dwClsContext, LPVOID pvReserved, REFIID iid, LPVOID *ppv);
640 HRESULT WINAPI CoInitialize(LPVOID lpReserved);
641 HRESULT WINAPI CoInitializeEx(LPVOID lpReserved, DWORD dwCoInit);
643 void WINAPI CoUninitialize(void);
645 typedef enum tagCOINIT
647 COINIT_APARTMENTTHREADED = 0x2, /* Apartment model */
648 COINIT_MULTITHREADED = 0x0, /* OLE calls objects on any thread */
649 COINIT_DISABLE_OLE1DDE = 0x4, /* Don't use DDE for Ole1 support */
650 COINIT_SPEED_OVER_MEMORY = 0x8 /* Trade memory for speed */
651 } COINIT;
654 /* FIXME: not implemented */
655 BOOL WINAPI CoIsOle1Class(REFCLSID rclsid);
657 HRESULT WINAPI CoLockObjectExternal(LPUNKNOWN pUnk, BOOL fLock, BOOL fLastUnlockReleases);
659 /* class registration flags; passed to CoRegisterClassObject */
660 typedef enum tagREGCLS
662 REGCLS_SINGLEUSE = 0,
663 REGCLS_MULTIPLEUSE = 1,
664 REGCLS_MULTI_SEPARATE = 2,
665 REGCLS_SUSPENDED = 4
666 } REGCLS;
668 HRESULT WINAPI CoRegisterClassObject(REFCLSID rclsid,LPUNKNOWN pUnk,DWORD dwClsContext,DWORD flags,LPDWORD lpdwRegister);
670 HRESULT WINAPI CoRevokeClassObject(DWORD dwRegister);
672 /*****************************************************************************
673 * COM Server dll - exports
675 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID * ppv);
676 HRESULT WINAPI DllCanUnloadNow(void);
678 #ifdef __cplusplus
679 } /* extern "C" */
680 #endif
682 #endif /* __WINE_WINE_OBJ_BASE_H */