:pserver:cvsanon@mok.lvcm.com:/CVS/ReactOS reactos
[reactos.git] / include / ole32 / obj_base.h
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  */
5
6 #ifndef __WINE_WINE_OBJ_BASE_H
7 #define __WINE_WINE_OBJ_BASE_H
8
9 /*****************************************************************************
10  * define ICOM_MSVTABLE_COMPAT
11  * to implement the microsoft com vtable compatibility workaround for g++.
12  *
13  * NOTE: Turning this option on will produce a winelib that is incompatible
14  * with the binary emulator.
15  *
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++.
19  *
20  * If you aren't interested in Winelib C++ compatibility at all, leave both
21  * options off.
22  *
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 :)
27  */
28 /* #define ICOM_MSVTABLE_COMPAT 1 */
29 /* #define ICOM_USE_COM_INTERFACE_ATTRIBUTE 1 */
30
31 /*****************************************************************************
32  * Defines the basic types
33  */
34 #include "wtypes.h"
35 #include "guiddef.h"
36
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40
41
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
49
50 /*****************************************************************************
51  * GUID API
52  */
53 HRESULT WINAPI StringFromCLSID16(REFCLSID id, LPOLESTR16*);
54 HRESULT WINAPI StringFromCLSID(REFCLSID id, LPOLESTR*);
55
56 HRESULT WINAPI CLSIDFromString16(LPCOLESTR16, CLSID *);
57 HRESULT WINAPI CLSIDFromString(LPCOLESTR, CLSID *);
58
59 HRESULT WINAPI CLSIDFromProgID16(LPCOLESTR16 progid, LPCLSID riid);
60 HRESULT WINAPI CLSIDFromProgID(LPCOLESTR progid, LPCLSID riid);
61
62 HRESULT WINAPI ProgIDFromCLSID(REFCLSID clsid, LPOLESTR *lplpszProgID);
63
64
65 INT WINAPI StringFromGUID2(REFGUID id, LPOLESTR str, INT cmax);
66
67
68 /*****************************************************************************
69  * Macros to define a COM interface
70  */
71 /*
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.
77  *
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.
82  *
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.
90  *
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.
93  *
94  * Let's take Direct3D as an example:
95  *
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
109  *
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
123  *
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.
161  *
162  *
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  *    }; 
179  *
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
193  *
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.
210  *
211  *
212  * And in C++ (with gcc's g++):
213  *
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  *    }; 
233  *
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.
258  *
259  *
260  * Implementing a COM interface.
261  *
262  * This continues the above example. This example assumes that the implementation is in C.
263  *
264  *    typedef struct _IDirect3D {
265  *        void* lpVtbl;
266  *        // ...
267  *
268  *    } _IDirect3D;
269  *
270  *    static ICOM_VTABLE(IDirect3D) d3dvt;
271  *
272  *    // implement the IDirect3D methods here
273  *
274  *    int IDirect3D_QueryInterface(IDirect3D* me)
275  *    {
276  *        ICOM_THIS(IDirect3D,me);
277  *        // ...
278  *    }
279  *
280  *    // ...
281  *
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  *    };
290  *
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.
300  */
301
302
303
304 #if !defined(__cplusplus) || defined(CINTERFACE)
305 #define ICOM_CINTERFACE 1
306 #endif
307
308 #ifndef ICOM_CINTERFACE
309 /* C++ interface */
310
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;
335
336
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;
361
362
363 #ifdef ICOM_USE_COM_INTERFACE_ATTRIBUTE
364
365 #define ICOM_DEFINE(iface,ibase) \
366     typedef struct iface: public ibase { \
367         iface##_METHODS \
368             } __attribute__ ((com_interface));
369
370 #else
371
372 #define ICOM_DEFINE(iface,ibase) \
373     typedef struct iface: public ibase { \
374         iface##_METHODS \
375     };
376
377 #endif /* ICOM_USE_COM_INTERFACE_ATTRIBUTE */
378
379 #define ICOM_VTBL(iface)         (iface)
380
381 #else
382 /* C interface */
383
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);
408
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);
433
434
435 #define ICOM_VTABLE(iface)       iface##Vtbl
436 #define ICOM_VFIELD(iface)       ICOM_VTABLE(iface)* lpVtbl
437 #define ICOM_VTBL(iface)         (iface)->lpVtbl
438
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 \
450     };
451 #define ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE 0,0,
452
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 \
462     };
463 #define ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
464 #endif /* ICOM_MSVTABLE_COMPAT */
465
466
467 #define ICOM_THIS(impl,iface)          impl* const This=(impl*)iface
468 #define ICOM_CTHIS(impl,iface)         const impl* const This=(const impl*)iface
469
470 #endif /*ICOM_CINTERFACE  */
471
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)
484
485
486 /*****************************************************************************
487  * Predeclare the interfaces
488  */
489 DEFINE_OLEGUID(IID_IClassFactory,       0x00000001L, 0, 0);
490 typedef struct IClassFactory IClassFactory, *LPCLASSFACTORY;
491
492 DEFINE_OLEGUID(IID_IMalloc,             0x00000002L, 0, 0);
493 typedef struct IMalloc IMalloc,*LPMALLOC;
494
495 DEFINE_OLEGUID(IID_IUnknown,            0x00000000L, 0, 0);
496 typedef struct IUnknown IUnknown, *LPUNKNOWN;
497
498
499 /*****************************************************************************
500  * IUnknown interface
501  */
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
514 };
515 #endif /* ICOM_US_COM_INTERFACE_ATTRIBUTE */
516
517 struct ICOM_VTABLE(IUnknown) {
518 #ifdef ICOM_MSVTABLE_COMPAT
519     long dummyRTTI1;
520     long dummyRTTI2;
521 #endif /* ICOM_MSVTABLE_COMPAT */
522
523 #else /* ICOM_CINTERFACE */
524 struct IUnknown {
525
526 #endif /* ICOM_CINTERFACE */
527
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
534 };
535 #endif /* ICOM_US_COM_INTERFACE_ATTRIBUTE */
536
537 #undef ICOM_INTERFACE
538
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)
543
544 /*****************************************************************************
545  * IClassFactory interface
546  */
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
556
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)
564
565
566 /*****************************************************************************
567  * IMalloc interface
568  */
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
582
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 /*** IMalloc 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)
594
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
604
605 HRESULT WINAPI CoGetMalloc(DWORD dwMemContext,LPMALLOC* lpMalloc);
606
607 LPVOID WINAPI CoTaskMemAlloc(ULONG size);
608
609 void WINAPI CoTaskMemFree(LPVOID ptr);
610
611 /* FIXME: unimplemented */
612 LPVOID WINAPI CoTaskMemRealloc(LPVOID ptr, ULONG size);
613
614
615 /*****************************************************************************
616  * Additional API
617  */
618
619 typedef enum tagCOINIT
620 {
621     COINIT_APARTMENTTHREADED  = 0x2, /* Apartment model */
622     COINIT_MULTITHREADED      = 0x0, /* OLE calls objects on any thread */
623     COINIT_DISABLE_OLE1DDE    = 0x4, /* Don't use DDE for Ole1 support */
624     COINIT_SPEED_OVER_MEMORY  = 0x8  /* Trade memory for speed */
625 } COINIT;
626
627 HRESULT WINAPI CoCreateGuid(GUID* pguid);
628
629 HINSTANCE WINAPI CoLoadLibrary(LPOLESTR lpszLibName, BOOL bAutoFree);
630
631 VOID WINAPI CoFreeAllLibraries(VOID);
632
633 VOID WINAPI CoFreeLibrary(HINSTANCE hLibrary);
634
635 VOID WINAPI CoFreeUnusedLibraries(VOID);
636
637 HRESULT WINAPI CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv);
638
639 HRESULT WINAPI CoGetClassObject(REFCLSID rclsid, DWORD dwClsContext, COSERVERINFO *pServerInfo, REFIID iid, LPVOID *ppv);
640
641 HRESULT WINAPI CoInitialize(LPVOID lpReserved);
642 HRESULT WINAPI CoInitializeEx(LPVOID lpReserved, DWORD dwCoInit);
643
644 VOID WINAPI CoUninitialize(VOID);
645
646 /* FIXME: not implemented */
647 BOOL WINAPI CoIsOle1Class(REFCLSID rclsid);
648
649 HRESULT WINAPI CoLockObjectExternal(LPUNKNOWN pUnk, BOOL fLock, BOOL fLastUnlockReleases);
650
651 /* class registration flags; passed to CoRegisterClassObject */
652 typedef enum tagREGCLS
653 {
654     REGCLS_SINGLEUSE = 0,
655     REGCLS_MULTIPLEUSE = 1,
656     REGCLS_MULTI_SEPARATE = 2,
657     REGCLS_SUSPENDED = 4
658 } REGCLS;
659
660 HRESULT WINAPI CoRegisterClassObject(REFCLSID rclsid,LPUNKNOWN pUnk,DWORD dwClsContext,DWORD flags,LPDWORD lpdwRegister);
661
662 HRESULT WINAPI CoRevokeClassObject(DWORD dwRegister);
663
664 BOOL WINAPI IsValidInterface(
665         LPUNKNOWN punk);
666
667 HRESULT WINAPI GetClassFile(LPOLESTR filePathName,CLSID *pclsid);
668
669
670 /*****************************************************************************
671  *      COM Server dll - exports
672  */
673 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID * ppv);
674 HRESULT WINAPI DllCanUnloadNow(VOID);
675
676 #ifdef __cplusplus
677 } /* extern "C" */
678 #endif
679
680 #endif /* __WINE_WINE_OBJ_BASE_H */