Arg 3 of CoGetClassObject is COSERVERINFO*, added some more debug.
[wine.git] / include / wine / obj_base.h
blob9683853d338c10df3e1ec917b2deae5334c06d63
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 (*QueryInterface)(IDirect3D* me, REFIID riid, LPVOID* ppvObj);
170 * ULONG (*QueryInterface)(IDirect3D* me);
171 * ULONG (*QueryInterface)(IDirect3D* me);
172 * HRESULT (*Initialize)(IDirect3D* me, REFIID a);
173 * HRESULT (*EnumDevices)(IDirect3D* me, LPD3DENUMDEVICESCALLBACK a, LPVOID b);
174 * HRESULT (*CreateLight)(IDirect3D* me, LPDIRECT3DLIGHT* a, IUnknown* b);
175 * HRESULT (*CreateMaterial)(IDirect3D* me, LPDIRECT3DMATERIAL* a, IUnknown* b);
176 * HRESULT (*CreateViewport)(IDirect3D* me, LPDIRECT3DVIEWPORT* a, IUnknown* b);
177 * HRESULT (*FindDevice)(IDirect3D* me, LPD3DFINDDEVICESEARCH a, LPD3DFINDDEVICERESULT b);
178 * };
180 * #ifdef ICOM_CINTERFACE
181 * // *** IUnknown methods *** //
182 * #define IDirect3D_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b)
183 * #define IDirect3D_AddRef(p) (p)->lpVtbl->AddRef(p)
184 * #define IDirect3D_Release(p) (p)->lpVtbl->Release(p)
185 * // *** IDirect3D methods *** //
186 * #define IDirect3D_Initialize(p,a) (p)->lpVtbl->Initialize(p,a)
187 * #define IDirect3D_EnumDevices(p,a,b) (p)->lpVtbl->EnumDevice(p,a,b)
188 * #define IDirect3D_CreateLight(p,a,b) (p)->lpVtbl->CreateLight(p,a,b)
189 * #define IDirect3D_CreateMaterial(p,a,b) (p)->lpVtbl->CreateMaterial(p,a,b)
190 * #define IDirect3D_CreateViewport(p,a,b) (p)->lpVtbl->CreateViewport(p,a,b)
191 * #define IDirect3D_FindDevice(p,a,b) (p)->lpVtbl->FindDevice(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 (*Initialize)(IDirect3D* me, REFIID a);
216 * public: inline HRESULT Initialize(REFIID a) { return ((IDirect3D*)t.lpVtbl)->Initialize(this,a); };
217 * private: HRESULT (*EnumDevices)(IDirect3D* me, LPD3DENUMDEVICESCALLBACK a, LPVOID b);
218 * public: inline HRESULT EnumDevices(LPD3DENUMDEVICESCALLBACK a, LPVOID b)
219 * { return ((IDirect3D*)t.lpVtbl)->EnumDevices(this,a,b); };
220 * private: HRESULT (*freateLight)(IDirect3D* me, LPDIRECT3DLIGHT* a, IUnknown* b);
221 * public: inline HRESULT CreateLight(LPDIRECT3DLIGHT* a, IUnknown* b)
222 * { return ((IDirect3D*)t.lpVtbl)->CreateLight(this,a,b); };
223 * private: HRESULT (*CreateMaterial)(IDirect3D* me, LPDIRECT3DMATERIAL* a, IUnknown* b);
224 * public: inline HRESULT CreateMaterial(LPDIRECT3DMATERIAL* a, IUnknown* b)
225 * { return ((IDirect3D*)t.lpVtbl)->CreateMaterial(this,a,b); };
226 * private: HRESULT (*CreateViewport)(IDirect3D* me, LPDIRECT3DVIEWPORT* a, IUnknown* b);
227 * public: inline HRESULT CreateViewport(LPDIRECT3DVIEWPORT* a, IUnknown* b)
228 * { return ((IDirect3D*)t.lpVtbl)->CreateViewport(this,a,b); };
229 * private: HRESULT (*FindDevice)(IDirect3D* me, LPD3DFINDDEVICESEARCH a, LPD3DFINDDEVICERESULT b);
230 * public: inline HRESULT FindDevice(LPD3DFINDDEVICESEARCH a, LPD3DFINDDEVICERESULT b)
231 * { return ((IDirect3D*)t.lpVtbl)->FindDevice(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.QueryInterface, 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_QueryInterface(IDirect3D* me)
276 * ICOM_THIS(IDirect3D,me);
277 * // ...
280 * // ...
282 * static ICOM_VTABLE(IDirect3D) d3dvt = {
283 * ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
284 * IDirect3D_QueryInterface,
285 * IDirect3D_Add,
286 * IDirect3D_Add2,
287 * IDirect3D_Initialize,
288 * IDirect3D_SetWidth
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_VTBL(iface) (iface)
381 #else
382 /* C interface */
384 #define ICOM_METHOD(ret,xfn) \
385 ret CALLBACK (*xfn)(ICOM_INTERFACE* me);
386 #define ICOM_METHOD1(ret,xfn,ta,na) \
387 ret CALLBACK (*xfn)(ICOM_INTERFACE* me,ta a);
388 #define ICOM_METHOD2(ret,xfn,ta,na,tb,nb) \
389 ret CALLBACK (*xfn)(ICOM_INTERFACE* me,ta a,tb b);
390 #define ICOM_METHOD3(ret,xfn,ta,na,tb,nb,tc,nc) \
391 ret CALLBACK (*xfn)(ICOM_INTERFACE* me,ta a,tb b,tc c);
392 #define ICOM_METHOD4(ret,xfn,ta,na,tb,nb,tc,nc,td,nd) \
393 ret CALLBACK (*xfn)(ICOM_INTERFACE* me,ta a,tb b,tc c,td d);
394 #define ICOM_METHOD5(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne) \
395 ret CALLBACK (*xfn)(ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e);
396 #define ICOM_METHOD6(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf) \
397 ret CALLBACK (*xfn)(ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e,tf f);
398 #define ICOM_METHOD7(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng) \
399 ret CALLBACK (*xfn)(ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e,tf f,tg g);
400 #define ICOM_METHOD8(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng,th,nh) \
401 ret CALLBACK (*xfn)(ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e,tf f,tg g,th h);
402 #define ICOM_METHOD9(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng,th,nh,ti,ni) \
403 ret CALLBACK (*xfn)(ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e,tf f,tg g,th h,ti i);
404 #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) \
405 ret CALLBACK (*xfn)(ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e,tf f,tg g,th h,ti i,tj j);
406 #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) \
407 ret CALLBACK (*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);
409 #define ICOM_VMETHOD(xfn) \
410 void CALLBACK (*xfn)(ICOM_INTERFACE* me);
411 #define ICOM_VMETHOD1(xfn,ta,na) \
412 void CALLBACK (*xfn)(ICOM_INTERFACE* me,ta a);
413 #define ICOM_VMETHOD2(xfn,ta,na,tb,nb) \
414 void CALLBACK (*xfn)(ICOM_INTERFACE* me,ta a,tb b);
415 #define ICOM_VMETHOD3(xfn,ta,na,tb,nb,tc,nc) \
416 void CALLBACK (*xfn)(ICOM_INTERFACE* me,ta a,tb b,tc c);
417 #define ICOM_VMETHOD4(xfn,ta,na,tb,nb,tc,nc,td,nd) \
418 void CALLBACK (*xfn)(ICOM_INTERFACE* me,ta a,tb b,tc c,td d);
419 #define ICOM_VMETHOD5(xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne) \
420 void CALLBACK (*xfn)(ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e);
421 #define ICOM_VMETHOD6(xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf) \
422 void CALLBACK (*xfn)(ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e,tf f);
423 #define ICOM_VMETHOD7(xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng) \
424 void CALLBACK (*xfn)(ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e,tf f,tg g);
425 #define ICOM_VMETHOD8(xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng,nh) \
426 void CALLBACK (*xfn)(ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e,tf f,tg g,th h);
427 #define ICOM_VMETHOD9(xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng,th,nh,ni) \
428 void CALLBACK (*xfn)(ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e,tf f,tg g,th h,ti i);
429 #define ICOM_VMETHOD10(xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng,th,nh,ti,ni,nj) \
430 void CALLBACK (*xfn)(ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e,tf f,tg g,th h,ti i,tj j);
431 #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) \
432 void CALLBACK (*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);
435 #define ICOM_VTABLE(iface) iface##Vtbl
436 #define ICOM_VFIELD(iface) ICOM_VTABLE(iface)* lpVtbl
437 #define ICOM_VTBL(iface) (iface)->lpVtbl
439 #ifdef ICOM_MSVTABLE_COMPAT
440 #define ICOM_DEFINE(iface,ibase) \
441 typedef struct ICOM_VTABLE(iface) ICOM_VTABLE(iface); \
442 struct iface { \
443 const ICOM_VFIELD(iface); \
444 }; \
445 struct ICOM_VTABLE(iface) { \
446 long dummyRTTI1; \
447 long dummyRTTI2; \
448 ibase##_IMETHODS \
449 iface##_METHODS \
451 #define ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE 0,0,
453 #else
454 #define ICOM_DEFINE(iface,ibase) \
455 typedef struct ICOM_VTABLE(iface) ICOM_VTABLE(iface); \
456 struct iface { \
457 const ICOM_VFIELD(iface); \
458 }; \
459 struct ICOM_VTABLE(iface) { \
460 ibase##_IMETHODS \
461 iface##_METHODS \
463 #define ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
464 #endif /* ICOM_MSVTABLE_COMPAT */
467 #define ICOM_THIS(impl,iface) impl* const This=(impl*)iface
468 #define ICOM_CTHIS(impl,iface) const impl* const This=(const impl*)iface
470 #endif /*ICOM_CINTERFACE */
472 #define ICOM_CALL(xfn, p) ICOM_VTBL(p)->xfn(p)
473 #define ICOM_CALL1(xfn, p,a) ICOM_VTBL(p)->xfn(p,a)
474 #define ICOM_CALL2(xfn, p,a,b) ICOM_VTBL(p)->xfn(p,a,b)
475 #define ICOM_CALL3(xfn, p,a,b,c) ICOM_VTBL(p)->xfn(p,a,b,c)
476 #define ICOM_CALL4(xfn, p,a,b,c,d) ICOM_VTBL(p)->xfn(p,a,b,c,d)
477 #define ICOM_CALL5(xfn, p,a,b,c,d,e) ICOM_VTBL(p)->xfn(p,a,b,c,d,e)
478 #define ICOM_CALL6(xfn, p,a,b,c,d,e,f) ICOM_VTBL(p)->xfn(p,a,b,c,d,e,f)
479 #define ICOM_CALL7(xfn, p,a,b,c,d,e,f,g) ICOM_VTBL(p)->xfn(p,a,b,c,d,e,f,g)
480 #define ICOM_CALL8(xfn, p,a,b,c,d,e,f,g,h) ICOM_VTBL(p)->xfn(p,a,b,c,d,e,f,g,h)
481 #define ICOM_CALL9(xfn, p,a,b,c,d,e,f,g,h,i) ICOM_VTBL(p)->xfn(p,a,b,c,d,e,f,g,h,i)
482 #define ICOM_CALL10(xfn, p,a,b,c,d,e,f,g,h,i,j) ICOM_VTBL(p)->xfn(p,a,b,c,d,e,f,g,h,i,j)
483 #define ICOM_CALL11(xfn, p,a,b,c,d,e,f,g,h,i,j,k) ICOM_VTBL(p)->xfn(p,a,b,c,d,e,f,g,h,i,j,k)
486 /*****************************************************************************
487 * Predeclare the interfaces
489 DEFINE_OLEGUID(IID_IClassFactory, 0x00000001L, 0, 0);
490 typedef struct IClassFactory IClassFactory, *LPCLASSFACTORY;
492 DEFINE_OLEGUID(IID_IMalloc, 0x00000002L, 0, 0);
493 typedef struct IMalloc IMalloc,*LPMALLOC;
495 DEFINE_OLEGUID(IID_IUnknown, 0x00000000L, 0, 0);
496 typedef struct IUnknown IUnknown, *LPUNKNOWN;
499 /*****************************************************************************
500 * IUnknown interface
502 #define ICOM_INTERFACE IUnknown
503 #define IUnknown_IMETHODS \
504 ICOM_METHOD2(HRESULT,QueryInterface,REFIID,riid, LPVOID*,ppvObj) \
505 ICOM_METHOD (ULONG,AddRef) \
506 ICOM_METHOD (ULONG,Release)
507 #ifdef ICOM_CINTERFACE
508 typedef struct ICOM_VTABLE(IUnknown) ICOM_VTABLE(IUnknown);
509 struct IUnknown {
510 ICOM_VFIELD(IUnknown);
511 #if defined(ICOM_USE_COM_INTERFACE_ATTRIBUTE)
512 } __attribute__ ((com_interface));
513 #else
515 #endif /* ICOM_US_COM_INTERFACE_ATTRIBUTE */
517 struct ICOM_VTABLE(IUnknown) {
518 #ifdef ICOM_MSVTABLE_COMPAT
519 long dummyRTTI1;
520 long dummyRTTI2;
521 #endif /* ICOM_MSVTABLE_COMPAT */
523 #else /* ICOM_CINTERFACE */
524 struct IUnknown {
526 #endif /* ICOM_CINTERFACE */
528 ICOM_METHOD2(HRESULT,QueryInterface,REFIID,riid, LPVOID*,ppvObj)
529 ICOM_METHOD (ULONG,AddRef)
530 ICOM_METHOD (ULONG,Release)
531 #if defined(ICOM_USE_COM_INTERFACE_ATTRIBUTE)
532 } __attribute__ ((com_interface));
533 #else
535 #endif /* ICOM_US_COM_INTERFACE_ATTRIBUTE */
537 #undef ICOM_INTERFACE
539 /*** IUnknown methods ***/
540 #define IUnknown_QueryInterface(p,a,b) ICOM_CALL2(QueryInterface,p,a,b)
541 #define IUnknown_AddRef(p) ICOM_CALL (AddRef,p)
542 #define IUnknown_Release(p) ICOM_CALL (Release,p)
544 /*****************************************************************************
545 * IClassFactory interface
547 #define ICOM_INTERFACE IClassFactory
548 #define IClassFactory_METHODS \
549 ICOM_METHOD3(HRESULT,CreateInstance, LPUNKNOWN,pUnkOuter, REFIID,riid, LPVOID*,ppvObject) \
550 ICOM_METHOD1(HRESULT,LockServer, BOOL,fLock)
551 #define IClassFactory_IMETHODS \
552 IUnknown_IMETHODS \
553 IClassFactory_METHODS
554 ICOM_DEFINE(IClassFactory,IUnknown)
555 #undef ICOM_INTERFACE
557 /*** IUnknown methods ***/
558 #define IClassFactory_QueryInterface(p,a,b) ICOM_CALL2(QueryInterface,p,a,b)
559 #define IClassFactory_AddRef(p) ICOM_CALL (AddRef,p)
560 #define IClassFactory_Release(p) ICOM_CALL (Release,p)
561 /*** IClassFactory methods ***/
562 #define IClassFactory_CreateInstance(p,a,b,c) ICOM_CALL3(CreateInstance,p,a,b,c)
563 #define IClassFactory_LockServer(p,a) ICOM_CALL1(LockServer,p,a)
566 /*****************************************************************************
567 * IMalloc interface
569 #define ICOM_INTERFACE IMalloc
570 #define IMalloc_METHODS \
571 ICOM_METHOD1 (LPVOID,Alloc, DWORD,cb) \
572 ICOM_METHOD2 (LPVOID,Realloc, LPVOID,pv, DWORD,cb) \
573 ICOM_VMETHOD1( Free, LPVOID,pv) \
574 ICOM_METHOD1(DWORD, GetSize, LPVOID,pv) \
575 ICOM_METHOD1(INT, DidAlloc, LPVOID,pv) \
576 ICOM_METHOD (VOID, HeapMinimize)
577 #define IMalloc_IMETHODS \
578 IUnknown_IMETHODS \
579 IMalloc_METHODS
580 ICOM_DEFINE(IMalloc,IUnknown)
581 #undef ICOM_INTERFACE
583 /*** IUnknown methods ***/
584 #define IMalloc_QueryInterface(p,a,b) ICOM_CALL2(QueryInterface,p,a,b)
585 #define IMalloc_AddRef(p) ICOM_CALL (AddRef,p)
586 #define IMalloc_Release(p) ICOM_CALL (Release,p)
587 /*** IMalloc32 methods ***/
588 #define IMalloc_Alloc(p,a) ICOM_CALL1(Alloc,p,a)
589 #define IMalloc_Realloc(p,a,b) ICOM_CALL2(Realloc,p,a,b)
590 #define IMalloc_Free(p,a) ICOM_CALL1(Free,p,a)
591 #define IMalloc_GetSize(p,a) ICOM_CALL1(GetSize,p,a)
592 #define IMalloc_DidAlloc(p,a) ICOM_CALL1(DidAlloc,p,a)
593 #define IMalloc_HeapMinimize(p) ICOM_CALL (HeapMinimize,p)
595 /* values passed to CoGetMalloc */
596 #define MEMCTX_TASK 1 /* private task memory */
597 #define MEMCTX_SHARED 2 /* shared memory */
598 #ifdef _MAC
599 #define MEMCTX_MACSYSTEM 3 /* system heap on mac */
600 #endif
601 /* mainly for internal use... */
602 #define MEMCTX_UNKNOWN -1
603 #define MEMCTX_SAME -2
605 HRESULT WINAPI CoGetMalloc(DWORD dwMemContext,LPMALLOC* lpMalloc);
607 LPVOID WINAPI CoTaskMemAlloc(ULONG size);
609 void WINAPI CoTaskMemFree(LPVOID ptr);
611 /* FIXME: unimplemented */
612 LPVOID WINAPI CoTaskMemRealloc(LPVOID ptr, ULONG size);
615 /*****************************************************************************
616 * Additional API
619 HRESULT WINAPI CoCreateGuid(GUID* pguid);
621 HINSTANCE WINAPI CoLoadLibrary(LPOLESTR lpszLibName, BOOL bAutoFree);
623 void WINAPI CoFreeAllLibraries(void);
625 void WINAPI CoFreeLibrary(HINSTANCE hLibrary);
627 void WINAPI CoFreeUnusedLibraries(void);
629 HRESULT WINAPI CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv);
631 HRESULT WINAPI CoGetClassObject(REFCLSID rclsid, DWORD dwClsContext, COSERVERINFO *pServerInfo, REFIID iid, LPVOID *ppv);
633 HRESULT WINAPI CoInitialize(LPVOID lpReserved);
634 HRESULT WINAPI CoInitializeEx(LPVOID lpReserved, DWORD dwCoInit);
636 void WINAPI CoUninitialize(void);
638 typedef enum tagCOINIT
640 COINIT_APARTMENTTHREADED = 0x2, /* Apartment model */
641 COINIT_MULTITHREADED = 0x0, /* OLE calls objects on any thread */
642 COINIT_DISABLE_OLE1DDE = 0x4, /* Don't use DDE for Ole1 support */
643 COINIT_SPEED_OVER_MEMORY = 0x8 /* Trade memory for speed */
644 } COINIT;
647 /* FIXME: not implemented */
648 BOOL WINAPI CoIsOle1Class(REFCLSID rclsid);
650 HRESULT WINAPI CoLockObjectExternal(LPUNKNOWN pUnk, BOOL fLock, BOOL fLastUnlockReleases);
652 /* class registration flags; passed to CoRegisterClassObject */
653 typedef enum tagREGCLS
655 REGCLS_SINGLEUSE = 0,
656 REGCLS_MULTIPLEUSE = 1,
657 REGCLS_MULTI_SEPARATE = 2,
658 REGCLS_SUSPENDED = 4
659 } REGCLS;
661 HRESULT WINAPI CoRegisterClassObject(REFCLSID rclsid,LPUNKNOWN pUnk,DWORD dwClsContext,DWORD flags,LPDWORD lpdwRegister);
663 HRESULT WINAPI CoRevokeClassObject(DWORD dwRegister);
665 /*****************************************************************************
666 * COM Server dll - exports
668 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID * ppv);
669 HRESULT WINAPI DllCanUnloadNow(void);
671 #ifdef __cplusplus
672 } /* extern "C" */
673 #endif
675 #endif /* __WINE_WINE_OBJ_BASE_H */