Define the COM macros even in C++.
[wine] / include / wine / 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.
18  *
19  * If you aren't interested in WineLib C++ compatability at all, leave both
20  * options off.
21  */
22 /* #define ICOM_MSVTABLE_COMPAT 1 */
23 /* #define ICOM_USE_COM_INTERFACE_ATTRIBUTE 1 */
24
25 /*****************************************************************************
26  * Defines the basic types
27  */
28 #include "wtypes.h"
29
30
31 #define LISet32(li, v)   ((li).HighPart = (v) < 0 ? -1 : 0, (li).LowPart = (v))
32 #define ULISet32(li, v)  ((li).HighPart = 0, (li).LowPart = (v))
33
34 /*****************************************************************************
35  * Macros to declare the GUIDs
36  */
37 #ifdef INITGUID
38 #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
39         const GUID name = \
40         { l, w1, w2, { b1, b2,  b3,  b4,  b5,  b6,  b7,  b8 } }
41 #else
42 #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
43     extern const GUID name
44 #endif
45
46 #define DEFINE_OLEGUID(name, l, w1, w2) \
47         DEFINE_GUID(name, l, w1, w2, 0xC0,0,0,0,0,0,0,0x46)
48
49 #define DEFINE_SHLGUID(name, l, w1, w2) DEFINE_OLEGUID(name,l,w1,w2)
50
51
52 /*****************************************************************************
53  * GUID API
54  */
55 HRESULT WINAPI StringFromCLSID16(REFCLSID id, LPOLESTR16*);
56 HRESULT WINAPI StringFromCLSID(REFCLSID id, LPOLESTR*);
57
58 HRESULT WINAPI CLSIDFromString16(LPCOLESTR16, CLSID *);
59 HRESULT WINAPI CLSIDFromString(LPCOLESTR, CLSID *);
60
61 HRESULT WINAPI CLSIDFromProgID16(LPCOLESTR16 progid, LPCLSID riid);
62 HRESULT WINAPI CLSIDFromProgID(LPCOLESTR progid, LPCLSID riid);
63
64 INT WINAPI StringFromGUID2(REFGUID id, LPOLESTR str, INT cmax);
65
66 BOOL16 WINAPI IsEqualGUID16(GUID* g1,GUID* g2);
67 BOOL WINAPI IsEqualGUID32(REFGUID rguid1,REFGUID rguid2);
68 /*#define IsEqualGUID WINELIB_NAME(IsEqualGUID)*/
69 #if defined(__cplusplus) && !defined(CINTERFACE)
70 #define IsEqualGUID(rguid1, rguid2) (!memcmp(&(rguid1), &(rguid2), sizeof(GUID)))
71 #else /* defined(__cplusplus) && !defined(CINTERFACE) */
72 #define IsEqualGUID(rguid1, rguid2) (!memcmp(rguid1, rguid2, sizeof(GUID)))
73 #endif /* defined(__cplusplus) && !defined(CINTERFACE) */
74 #define IsEqualIID(riid1, riid2) IsEqualGUID(riid1, riid2)
75 #define IsEqualCLSID(rclsid1, rclsid2) IsEqualGUID(rclsid1, rclsid2)
76
77 #if defined(__cplusplus) && !defined(CINTERFACE)
78 inline BOOL operator==(const GUID& guidOne, const GUID& guidOther)
79 {
80     return !memcmp(&guidOne,&guidOther,sizeof(GUID));
81 }
82 inline BOOL operator!=(const GUID& guidOne, const GUID& guidOther)
83 {
84     return !(guidOne == guidOther);
85 }
86 #endif 
87
88
89 /*****************************************************************************
90  * Macros to define a COM interface
91  */
92 /*
93  * The goal of the following set of definitions is to provide a way to use the same 
94  * header file definitions to provide both a C interface and a C++ object oriented 
95  * interface to COM interfaces. The type of interface is selected automatically 
96  * depending on the language but it is always possible to get the C interface in C++ 
97  * by defining CINTERFACE.
98  *
99  * It is based on the following assumptions:
100  *  - all COM interfaces derive from IUnknown, this should not be a problem.
101  *  - the header file only defines the interface, the actual fields are defined 
102  *    separately in the C file implementing the interface.
103  *
104  * The natural approach to this problem would be to make sure we get a C++ class and 
105  * virtual methods in C++ and a structure with a table of pointer to functions in C.
106  * Unfortunately the layout of the virtual table is compiler specific, the layout of 
107  * g++ virtual tables is not the same as that of an egcs virtual table which is not the 
108  * same as that generated by Visual C+. There are workarounds to make the virtual tables 
109  * compatible via padding but unfortunately the one which is imposed to the WINE emulator
110  * by the Windows binaries, i.e. the Visual C++ one, is the most compact of all.
111  *
112  * So the solution I finally adopted does not use virtual tables. Instead I use inline 
113  * non virtual methods that dereference the method pointer themselves and perform the call.
114  *
115  * Let's take Direct3D as an example:
116  *
117  *    #define ICOM_INTERFACE IDirect3D
118  *    #define IDirect3D_METHODS \
119  *        ICOM_METHOD1(HRESULT,Initialize,    REFIID,) \
120  *        ICOM_METHOD2(HRESULT,EnumDevices,   LPD3DENUMDEVICESCALLBACK,, LPVOID,) \
121  *        ICOM_METHOD2(HRESULT,CreateLight,   LPDIRECT3DLIGHT*,, IUnknown*,) \
122  *        ICOM_METHOD2(HRESULT,CreateMaterial,LPDIRECT3DMATERIAL*,, IUnknown*,) \
123  *        ICOM_METHOD2(HRESULT,CreateViewport,LPDIRECT3DVIEWPORT*,, IUnknown*,) \
124  *        ICOM_METHOD2(HRESULT,FindDevice,    LPD3DFINDDEVICESEARCH,, LPD3DFINDDEVICERESULT,)
125  *    #define IDirect3D_IMETHODS \
126  *        IUnknown_IMETHODS \
127  *        IDirect3D_METHODS
128  *    ICOM_DEFINE(IDirect3D,IUnknown)
129  *    #undef ICOM_INTERFACE
130  *
131  *    #ifdef ICOM_CINTERFACE
132  *    // *** IUnknown methods *** //
133  *    #define IDirect3D_QueryInterface(p,a,b) ICOM_CALL2(QueryInterface,p,a,b)
134  *    #define IDirect3D_AddRef(p)             ICOM_CALL (AddRef,p)
135  *    #define IDirect3D_Release(p)            ICOM_CALL (Release,p)
136  *    // *** IDirect3D methods *** //
137  *    #define IDirect3D_Initialize(p,a)       ICOM_CALL1(Initialize,p,a)
138  *    #define IDirect3D_EnumDevices(p,a,b)    ICOM_CALL2(EnumDevice,p,a,b)
139  *    #define IDirect3D_CreateLight(p,a,b)    ICOM_CALL2(CreateLight,p,a,b)
140  *    #define IDirect3D_CreateMaterial(p,a,b) ICOM_CALL2(CreateMaterial,p,a,b)
141  *    #define IDirect3D_CreateViewport(p,a,b) ICOM_CALL2(CreateViewport,p,a,b)
142  *    #define IDirect3D_FindDevice(p,a,b)     ICOM_CALL2(FindDevice,p,a,b)
143  *    #endif
144  *
145  * Comments:
146  *  - The ICOM_INTERFACE macro is used in the ICOM_METHOD macros to define the type of the 'this' 
147  *    pointer. Defining this macro here saves us the trouble of having to repeat the interface 
148  *    name everywhere. Note however that because of the way macros work, a macro like ICOM_METHOD1 
149  *    cannot use 'ICOM_INTERFACE##_VTABLE' because this would give 'ICOM_INTERFACE_VTABLE' and not 
150  *    'IDirect3D_VTABLE'.
151  *  - ICOM_METHODS defines the methods specific to this interface. It is then aggregated with the 
152  *    inherited methods to form ICOM_IMETHODS.
153  *  - ICOM_IMETHODS defines the list of methods that are inheritable from this interface. It must 
154  *    be written manually (rather than using a macro to generate the equivalent code) to avoid 
155  *    macro recursion (which compilers don't like).
156  *  - The ICOM_DEFINE finally declares all the structures necessary for the interface. We have to 
157  *    explicitly use the interface name for macro expansion reasons again.
158  *    Inherited methods are inherited in C by using the IDirect3D_METHODS macro and the parent's 
159  *    Xxx_IMETHODS macro. In C++ we need only use the IDirect3D_METHODS since method inheritance 
160  *    is taken care of by the language.
161  *  - In C++ the ICOM_METHOD macros generate a function prototype and a call to a function pointer 
162  *    method. This means using once 't1 p1, t2 p2, ...' and once 'p1, p2' without the types. The 
163  *    only way I found to handle this is to have one ICOM_METHOD macro per number of parameters and 
164  *    to have it take only the type information (with const if necessary) as parameters.
165  *    The 'undef ICOM_INTERFACE' is here to remind you that using ICOM_INTERFACE in the following 
166  *    macros will not work. This time it's because the ICOM_CALL macro expansion is done only once 
167  *    the 'IDirect3D_Xxx' macro is expanded. And by that time ICOM_INTERFACE will be long gone 
168  *    anyway.
169  *  - You may have noticed the double commas after each parameter type. This allows you to put the 
170  *    name of that parameter which I think is good for documentation. It is not required and since 
171  *    I did not know what to put there for this example (I could only find doc about IDirect3D2), 
172  *    I left them blank.
173  *  - Finally the set of 'IDirect3D_Xxx' macros is a standard set of macros defined to ease access 
174  *    to the interface methods in C. Unfortunately I don't see any way to avoid having to duplicate 
175  *    the inherited method definitions there. This time I could have used a trick to use only one 
176  *    macro whatever the number of parameters but I prefered to have it work the same way as above.
177  *  - You probably have noticed that we don't define the fields we need to actually implement this 
178  *    interface: reference count, pointer to other resources and miscellaneous fields. That's 
179  *    because these interfaces are just that: interfaces. They may be implemented more than once, in 
180  *    different contexts and sometimes not even in Wine. Thus it would not make sense to impose 
181  *    that the interface contains some specific fields.
182  *
183  *
184  * In C this gives:
185  *    typedef struct IDirect3DVtbl IDirect3DVtbl;
186  *    struct IDirect3D {
187  *        IDirect3DVtbl* lpvtbl;
188  *    };
189  *    struct IDirect3DVtbl {
190  *        HRESULT (*fnQueryInterface)(IDirect3D* me, REFIID riid, LPVOID* ppvObj);
191  *        ULONG (*fnQueryInterface)(IDirect3D* me);
192  *        ULONG (*fnQueryInterface)(IDirect3D* me);
193  *        HRESULT (*fnInitialize)(IDirect3D* me, REFIID a);
194  *        HRESULT (*fnEnumDevices)(IDirect3D* me, LPD3DENUMDEVICESCALLBACK a, LPVOID b);
195  *        HRESULT (*fnCreateLight)(IDirect3D* me, LPDIRECT3DLIGHT* a, IUnknown* b);
196  *        HRESULT (*fnCreateMaterial)(IDirect3D* me, LPDIRECT3DMATERIAL* a, IUnknown* b);
197  *        HRESULT (*fnCreateViewport)(IDirect3D* me, LPDIRECT3DVIEWPORT* a, IUnknown* b);
198  *        HRESULT (*fnFindDevice)(IDirect3D* me, LPD3DFINDDEVICESEARCH a, LPD3DFINDDEVICERESULT b);
199  *    }; 
200  *
201  *    #ifdef ICOM_CINTERFACE
202  *    // *** IUnknown methods *** //
203  *    #define IDirect3D_QueryInterface(p,a,b) (p)->lpvtbl->fnQueryInterface(p,a,b)
204  *    #define IDirect3D_AddRef(p)             (p)->lpvtbl->fnAddRef(p)
205  *    #define IDirect3D_Release(p)            (p)->lpvtbl->fnRelease(p)
206  *    // *** IDirect3D methods *** //
207  *    #define IDirect3D_Initialize(p,a)       (p)->lpvtbl->fnInitialize(p,a)
208  *    #define IDirect3D_EnumDevices(p,a,b)    (p)->lpvtbl->fnEnumDevice(p,a,b)
209  *    #define IDirect3D_CreateLight(p,a,b)    (p)->lpvtbl->fnCreateLight(p,a,b)
210  *    #define IDirect3D_CreateMaterial(p,a,b) (p)->lpvtbl->fnCreateMaterial(p,a,b)
211  *    #define IDirect3D_CreateViewport(p,a,b) (p)->lpvtbl->fnCreateViewport(p,a,b)
212  *    #define IDirect3D_FindDevice(p,a,b)     (p)->lpvtbl->fnFindDevice(p,a,b)
213  *    #endif
214  *
215  * Comments:
216  *  - IDirect3D only contains a pointer to the IDirect3D virtual/jump table. This is the only thing 
217  *    the user needs to know to use the interface. Of course the structure we will define to 
218  *    implement this interface will have more fields but the first one will match this pointer.
219  *  - The code generated by ICOM_DEFINE defines both the structure representing the interface and 
220  *    the structure for the jump table. ICOM_DEFINE uses the parent's Xxx_IMETHODS macro to 
221  *    automatically repeat the prototypes of all the inherited methods and then uses IDirect3D_METHODS 
222  *    to define the IDirect3D methods.
223  *  - Each method is declared as a pointer to function field in the jump table. The implementation 
224  *    will fill this jump table with appropriate values, probably using a static variable, and 
225  *    initialize the lpvtbl field to point to this variable.
226  *  - The IDirect3D_Xxx macros then just derefence the lpvtbl pointer and use the function pointer 
227  *    corresponding to the macro name. This emulates the behavior of a virtual table and should be 
228  *    just as fast.
229  *  - This C code should be quite compatible with the Windows headers both for code that uses COM 
230  *    interfaces and for code implementing a COM interface.
231  *
232  *
233  * And in C++ (with gcc's g++):
234  *
235  *    typedef struct IDirect3D: public IUnknown {
236  *        private: HRESULT (*fnInitialize)(IDirect3D* me, REFIID a);
237  *        public: inline HRESULT Initialize(REFIID a) { return ((IDirect3D*)t.lpvtbl)->fnInitialize(this,a); };
238  *        private: HRESULT (*fnEnumDevices)(IDirect3D* me, LPD3DENUMDEVICESCALLBACK a, LPVOID b);
239  *        public: inline HRESULT EnumDevices(LPD3DENUMDEVICESCALLBACK a, LPVOID b)
240  *            { return ((IDirect3D*)t.lpvtbl)->fnEnumDevices(this,a,b); };
241  *        private: HRESULT (*fnCreateLight)(IDirect3D* me, LPDIRECT3DLIGHT* a, IUnknown* b);
242  *        public: inline HRESULT CreateLight(LPDIRECT3DLIGHT* a, IUnknown* b)
243  *            { return ((IDirect3D*)t.lpvtbl)->fnCreateLight(this,a,b); };
244  *        private: HRESULT (*fnCreateMaterial)(IDirect3D* me, LPDIRECT3DMATERIAL* a, IUnknown* b);
245  *        public: inline HRESULT CreateMaterial(LPDIRECT3DMATERIAL* a, IUnknown* b)
246  *            { return ((IDirect3D*)t.lpvtbl)->fnCreateMaterial(this,a,b); };
247  *        private: HRESULT (*fnCreateViewport)(IDirect3D* me, LPDIRECT3DVIEWPORT* a, IUnknown* b);
248  *        public: inline HRESULT CreateViewport(LPDIRECT3DVIEWPORT* a, IUnknown* b)
249  *            { return ((IDirect3D*)t.lpvtbl)->fnCreateViewport(this,a,b); };
250  *        private:  HRESULT (*fnFindDevice)(IDirect3D* me, LPD3DFINDDEVICESEARCH a, LPD3DFINDDEVICERESULT b);
251  *        public: inline HRESULT FindDevice(LPD3DFINDDEVICESEARCH a, LPD3DFINDDEVICERESULT b)
252  *            { return ((IDirect3D*)t.lpvtbl)->fnFindDevice(this,a,b); };
253  *    }; 
254  *
255  * Comments:
256  *  - In C++ IDirect3D does double duty as both the virtual/jump table and as the interface 
257  *    definition. The reason for this is to avoid having to duplicate the mehod definitions: once 
258  *    to have the function pointers in the jump table and once to have the methods in the interface 
259  *    class. Here one macro can generate both. This means though that the first pointer, t.lpvtbl 
260  *    defined in IUnknown,  must be interpreted as the jump table pointer if we interpret the 
261  *    structure as the the interface class, and as the function pointer to the QueryInterface 
262  *    method, t.fnQueryInterface, if we interpret the structure as the jump table. Fortunately this 
263  *    gymnastic is entirely taken care of in the header of IUnknown.
264  *  - Of course in C++ we use inheritance so that we don't have to duplicate the method definitions. 
265  *  - Since IDirect3D does double duty, each ICOM_METHOD macro defines both a function pointer and 
266  *    a non-vritual inline method which dereferences it and calls it. This way this method behaves 
267  *    just like a virtual method but does not create a true C++ virtual table which would break the 
268  *    structure layout. If you look at the implementation of these methods you'll notice that they 
269  *    would not work for void functions. We have to return something and fortunately this seems to 
270  *    be what all the COM methods do (otherwise we would need another set of macros).
271  *  - Note how the ICOM_METHOD generates both function prototypes mixing types and formal parameter 
272  *    names and the method invocation using only the formal parameter name. This is the reason why 
273  *    we need different macros to handle different numbers of parameters.
274  *  - Finally there is no IDirect3D_Xxx macro. These are not needed in C++ unless the CINTERFACE 
275  *    macro is defined in which case we would not be here.
276  *  - This C++ code works well for code that just uses COM interfaces. But it will not work with 
277  *    C++ code implement a COM interface. That's because such code assumes the interface methods 
278  *    are declared as virtual C++ methods which is not the case here.
279  *
280  *
281  * Implementing a COM interface.
282  *
283  * This continues the above example. This example assumes that the implementation is in C.
284  *
285  *    typedef struct _IDirect3D {
286  *        void* lpvtbl;
287  *        // ...
288  *
289  *    } _IDirect3D;
290  *
291  *    static ICOM_VTABLE(IDirect3D) d3dvt;
292  *
293  *    // implement the IDirect3D methods here
294  *
295  *    int IDirect3D_fnQueryInterface(IDirect3D* me)
296  *    {
297  *        ICOM_THIS(IDirect3D,me);
298  *        // ...
299  *    }
300  *
301  *    // ...
302  *
303  *    static ICOM_VTABLE(IDirect3D) d3dvt = {
304  *            IDirect3D_fnQueryInterface,
305  *        IDirect3D_fnAdd,
306  *        IDirect3D_fnAdd2,
307  *        IDirect3D_fnInitialize,
308  *        IDirect3D_fnSetWidth
309  *    };
310  *
311  * Comments:
312  *  - We first define what the interface really contains. This is th e_IDirect3D structure. The 
313  *    first field must of course be the virtual table pointer. Everything else is free.
314  *  - Then we predeclare our static virtual table variable, we will need its address in some 
315  *    methods to initialize the virtual table pointer of the returned interface objects.
316  *  - Then we implement the interface methods. To match what has been declared in the header file 
317  *    they must take a pointer to a IDirect3D structure and we must cast it to an _IDirect3D so that 
318  *    we can manipulate the fields. This is performed by the ICOM_THIS macro.
319  *  - Finally we initialize the virtual table.
320  */
321
322
323 #define ICOM_VTABLE(iface)       iface##Vtbl
324
325
326 #if !defined(__cplusplus) || defined(CINTERFACE)
327 #define ICOM_CINTERFACE 1
328 #endif
329
330 #ifndef ICOM_CINTERFACE
331 /* C++ interface */
332
333 #define ICOM_METHOD(ret,xfn) \
334      public: virtual ret (CALLBACK xfn)(void) = 0;
335
336 #define ICOM_METHOD1(ret,xfn,ta,na) \
337      public: virtual ret (CALLBACK xfn)(ta a) = 0;
338
339 #define ICOM_METHOD2(ret,xfn,ta,na,tb,nb) \
340      public: virtual ret (CALLBACK xfn)(ta a,tb b) = 0;
341
342 #define ICOM_METHOD3(ret,xfn,ta,na,tb,nb,tc,nc) \
343      public: virtual ret (CALLBACK xfn)(ta a,tb b,tc c) = 0;
344
345 #define ICOM_METHOD4(ret,xfn,ta,na,tb,nb,tc,nc,td,nd) \
346      public: virtual ret (CALLBACK xfn)(ta a,tb b,tc c,td d) = 0;
347
348 #define ICOM_METHOD5(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne) \
349      public: virtual ret (CALLBACK xfn)(ta a,tb b,tc c,td d,te e) = 0;
350
351 #define ICOM_METHOD6(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf) \
352      public: virtual ret (CALLBACK xfn)(ta a,tb b,tc c,td d,te e,tf f) = 0;
353
354 #define ICOM_METHOD7(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng) \
355      public: virtual ret (CALLBACK xfn)(ta a,tb b,tc c,td d,te e,tf f,tg g) = 0;
356
357 #define ICOM_METHOD8(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng,th,nh) \
358      public: virtual ret (CALLBACK xfn)(ta a,tb b,tc c,td d,te e,tf f,tg g,th h) = 0;
359
360 #define ICOM_METHOD9(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng,th,nh,ti,ni) \
361      public: virtual ret (CALLBACK xfn)(ta a,tb b,tc c,td d,te e,tf f,tg g,th h,ti i) = 0;
362
363 #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) \
364      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;
365
366
367 #define ICOM_CMETHOD(ret,xfn) \
368      public: virtual ret (CALLBACK xfn)(void) const = 0;
369
370 #define ICOM_CMETHOD1(ret,xfn,ta,na) \
371      public: virtual ret (CALLBACK xfn)(ta a) const = 0;
372
373 #define ICOM_CMETHOD2(ret,xfn,ta,na,tb,nb) \
374      public: virtual ret (CALLBACK xfn)(ta a,tb b) const = 0;
375
376 #define ICOM_CMETHOD3(ret,xfn,ta,na,tb,nb,tc,nc) \
377      public: virtual ret (CALLBACK xfn)(ta a,tb b,tc c) const = 0;
378
379 #define ICOM_CMETHOD4(ret,xfn,ta,na,tb,nb,tc,nc,td,nd) \
380      public: virtual ret (CALLBACK xfn)(ta a,tb b,tc c,td d) const = 0;
381
382 #define ICOM_CMETHOD5(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne) \
383      public: virtual ret (CALLBACK xfn)(ta a,tb b,tc c,td d,te e) const = 0;
384
385 #define ICOM_CMETHOD6(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf) \
386      public: virtual ret (CALLBACK xfn)(ta a,tb b,tc c,td d,te e,tf f) const = 0;
387
388 #define ICOM_CMETHOD7(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng) \
389      public: virtual ret (CALLBACK xfn)(ta a,tb b,tc c,td d,te e,tf f,tg g) const = 0;
390
391 #define ICOM_CMETHOD8(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng,th,nh) \
392      public: virtual ret (CALLBACK xfn)(ta a,tb b,tc c,td d,te e,tf f,tg g,th h) const = 0;
393
394
395 #define ICOM_VMETHOD(xfn) \
396      public: virtual void (CALLBACK xfn)(void) = 0;
397
398 #define ICOM_VMETHOD1(xfn,ta,na) \
399      public: virtual void (CALLBACK xfn)(ta a) = 0;
400
401 #define ICOM_VMETHOD2(xfn,ta,na,tb,nb) \
402      public: virtual void (CALLBACK xfn)(ta a,tb b) = 0;
403
404 #define ICOM_VMETHOD3(xfn,ta,na,tb,nb,tc,nc) \
405      public: virtual void (CALLBACK xfn)(ta a,tb b,tc c) = 0;
406
407 #define ICOM_VMETHOD4(xfn,ta,na,tb,nb,tc,nc,td,nd) \
408      public: virtual void (CALLBACK xfn)(ta a,tb b,tc c,td d) = 0;
409
410 #define ICOM_VMETHOD5(xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne) \
411      public: virtual void (CALLBACK xfn)(ta a,tb b,tc c,td d,te e) = 0;
412
413 #define ICOM_VMETHOD6(xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf) \
414      public: virtual void (CALLBACK xfn)(ta a,tb b,tc c,td d,te e,tf f) = 0;
415
416 #define ICOM_VMETHOD7(xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng) \
417      public: virtual void (CALLBACK xfn)(ta a,tb b,tc c,td d,te e,tf f,tg g) = 0;
418
419 #define ICOM_VMETHOD8(xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng,th,nh) \
420      public: virtual void (CALLBACK xfn)(ta a,tb b,tc c,td d,te e,tf f,tg g,th h) = 0;
421
422
423 #define ICOM_CVMETHOD(xfn) \
424      public: virtual void (CALLBACK xfn)(void) const = 0;
425
426 #define ICOM_CVMETHOD1(xfn,ta,na) \
427      public: virtual void (CALLBACK xfn)(ta a) const = 0;
428
429 #define ICOM_CVMETHOD2(xfn,ta,na,tb,nb) \
430      public: virtual void (CALLBACK xfn)(ta a,tb b) const = 0;
431
432 #define ICOM_CVMETHOD3(xfn,ta,na,tb,nb,tc,nc) \
433      public: virtual void (CALLBACK xfn)(ta a,tb b,tc c) const = 0;
434
435 #define ICOM_CVMETHOD4(xfn,ta,na,tb,nb,tc,nc,td,nd) \
436      public: virtual void (CALLBACK xfn)(ta a,tb b,tc c,td d) const = 0;
437
438 #define ICOM_CVMETHOD5(xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne) \
439      public: virtual void (CALLBACK xfn)(ta a,tb b,tc c,td d,te e) const = 0;
440
441 #define ICOM_CVMETHOD6(xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf) \
442      public: virtual void (CALLBACK xfn)(ta a,tb b,tc c,td d,te e,tf f) const = 0;
443
444 #define ICOM_CVMETHOD7(xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng) \
445      public: virtual void (CALLBACK xfn)(ta a,tb b,tc c,td d,te e,tf f,tg g) const = 0;
446
447 #define ICOM_CVMETHOD8(xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng,th,nh) \
448      public: virtual void (CALLBACK xfn)(ta a,tb b,tc c,td d,te e,tf f,tg g,th h) const = 0;
449
450 #ifdef ICOM_USE_COM_INTERFACE_ATTRIBUTE
451
452 #define ICOM_DEFINE(iface,ibase) \
453     typedef struct iface: public ibase { \
454         iface##_METHODS \
455             } __attribute__ ((com_interface));
456
457 #else
458
459 #define ICOM_DEFINE(iface,ibase) \
460     typedef struct iface: public ibase { \
461         iface##_METHODS \
462     };
463
464 #endif /* ICOM_USE_COM_INTERFACE_ATTRIBUTE */
465
466 #define ICOM_CALL(xfn, p)                  (p)->fn##xfn()
467 #define ICOM_CALL1(xfn, p,a)               (p)->fn##xfn(a)
468 #define ICOM_CALL2(xfn, p,a,b)             (p)->fn##xfn(a,b)
469 #define ICOM_CALL3(xfn, p,a,b,c)           (p)->fn##xfn(a,b,c)
470 #define ICOM_CALL4(xfn, p,a,b,c,d)         (p)->fn##xfn(a,b,c,d)
471 #define ICOM_CALL5(xfn, p,a,b,c,d,e)       (p)->fn##xfn(a,b,c,d,e)
472 #define ICOM_CALL6(xfn, p,a,b,c,d,e,f)     (p)->fn##xfn(a,b,c,d,e,f)
473 #define ICOM_CALL7(xfn, p,a,b,c,d,e,f,g)   (p)->fn##xfn(a,b,c,d,e,f,g)
474 #define ICOM_CALL8(xfn, p,a,b,c,d,e,f,g,h) (p)->fn##xfn(a,b,c,d,e,f,g,h)
475
476
477 #else
478 /* C interface */
479
480
481 #define ICOM_METHOD(ret,xfn) \
482     ret (CALLBACK *fn##xfn)(ICOM_INTERFACE* me);
483
484 #define ICOM_METHOD1(ret,xfn,ta,na) \
485     ret (CALLBACK *fn##xfn)(ICOM_INTERFACE* me,ta a);
486
487 #define ICOM_METHOD2(ret,xfn,ta,na,tb,nb) \
488     ret (CALLBACK *fn##xfn)(ICOM_INTERFACE* me,ta a,tb b);
489
490 #define ICOM_METHOD3(ret,xfn,ta,na,tb,nb,tc,nc) \
491     ret (CALLBACK *fn##xfn)(ICOM_INTERFACE* me,ta a,tb b,tc c);
492
493 #define ICOM_METHOD4(ret,xfn,ta,na,tb,nb,tc,nc,td,nd) \
494     ret (CALLBACK *fn##xfn)(ICOM_INTERFACE* me,ta a,tb b,tc c,td d);
495
496 #define ICOM_METHOD5(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne) \
497     ret (CALLBACK *fn##xfn)(ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e);
498
499 #define ICOM_METHOD6(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf) \
500     ret (CALLBACK *fn##xfn)(ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e,tf f);
501
502 #define ICOM_METHOD7(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng) \
503     ret (CALLBACK *fn##xfn)(ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e,tf f,tg g);
504
505 #define ICOM_METHOD8(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng,th,nh) \
506     ret (CALLBACK *fn##xfn)(ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e,tf f,tg g,th h);
507
508 #define ICOM_METHOD9(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng,th,nh,ti,ni) \
509     ret (CALLBACK *fn##xfn)(ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e,tf f,tg g,th h,ti i);
510
511 #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) \
512     ret (CALLBACK *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);
513
514
515 #define ICOM_CMETHOD(ret,xfn) \
516         ret (CALLBACK *fn##xfn)(const ICOM_INTERFACE* me);
517
518 #define ICOM_CMETHOD1(ret,xfn,ta,na) \
519     ret (CALLBACK *fn##xfn)(const ICOM_INTERFACE* me,ta a);
520
521 #define ICOM_CMETHOD2(ret,xfn,ta,na,tb,nb) \
522     ret (CALLBACK *fn##xfn)(const ICOM_INTERFACE* me,ta a,tb b);
523
524 #define ICOM_CMETHOD3(ret,xfn,ta,na,tb,nb,tc,nc) \
525     ret (CALLBACK *fn##xfn)(const ICOM_INTERFACE* me,ta a,tb b,tc c);
526
527 #define ICOM_CMETHOD4(ret,xfn,ta,na,tb,nb,tc,nc,td,nd) \
528     ret (CALLBACK *fn##xfn)(const ICOM_INTERFACE* me,ta a,tb b,tc c,td d);
529
530 #define ICOM_CMETHOD5(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne) \
531     ret (CALLBACK *fn##xfn)(const ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e);
532
533 #define ICOM_CMETHOD6(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf) \
534     ret (CALLBACK *fn##xfn)(const ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e,tf f);
535
536 #define ICOM_CMETHOD7(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng) \
537     ret (CALLBACK *fn##xfn)(const ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e,tf f,tg g);
538
539 #define ICOM_CMETHOD8(ret,xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng,th,nh) \
540     ret (CALLBACK *fn##xfn)(const ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e,tf f,tg g,th h);
541
542
543 #define ICOM_VMETHOD(xfn) \
544     void (CALLBACK *fn##xfn)(ICOM_INTERFACE* me);
545
546 #define ICOM_VMETHOD1(xfn,ta,na) \
547     void (CALLBACK *fn##xfn)(ICOM_INTERFACE* me,ta a);
548
549 #define ICOM_VMETHOD2(xfn,ta,na,tb,nb) \
550     void (CALLBACK *fn##xfn)(ICOM_INTERFACE* me,ta a,tb b);
551
552 #define ICOM_VMETHOD3(xfn,ta,na,tb,nb,tc,nc) \
553     void (CALLBACK *fn##xfn)(ICOM_INTERFACE* me,ta a,tb b,tc c);
554
555 #define ICOM_VMETHOD4(xfn,ta,na,tb,nb,tc,nc,td,nd) \
556     void (CALLBACK *fn##xfn)(ICOM_INTERFACE* me,ta a,tb b,tc c,td d);
557
558 #define ICOM_VMETHOD5(xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne) \
559     void (CALLBACK *fn##xfn)(ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e);
560
561 #define ICOM_VMETHOD6(xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf) \
562     void (CALLBACK *fn##xfn)(ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e,tf f);
563
564 #define ICOM_VMETHOD7(xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng) \
565     void (CALLBACK *fn##xfn)(ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e,tf f,tg g);
566
567 #define ICOM_VMETHOD8(xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng,nh) \
568     void (CALLBACK *fn##xfn)(ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e,tf f,tg g,th h);
569
570
571 #define ICOM_CVMETHOD(xfn) \
572         void (CALLBACK *fn##xfn)(const ICOM_INTERFACE* me);
573
574 #define ICOM_CVMETHOD1(xfn,ta,na) \
575     void (CALLBACK *fn##xfn)(const ICOM_INTERFACE* me,ta a);
576
577 #define ICOM_CVMETHOD2(xfn,ta,na,tb,nb) \
578     void (CALLBACK *fn##xfn)(const ICOM_INTERFACE* me,ta a,tb b);
579
580 #define ICOM_CVMETHOD3(xfn,ta,na,tb,nb,tc,nc) \
581     void (CALLBACK *fn##xfn)(const ICOM_INTERFACE* me,ta a,tb b,tc c);
582
583 #define ICOM_CVMETHOD4(xfn,ta,na,tb,nb,tc,nc,td,nd) \
584     void (CALLBACK *fn##xfn)(const ICOM_INTERFACE* me,ta a,tb b,tc c,td d);
585
586 #define ICOM_CVMETHOD5(xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne) \
587     void (CALLBACK *fn##xfn)(const ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e);
588
589 #define ICOM_CVMETHOD6(xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf) \
590     void (CALLBACK *fn##xfn)(const ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e,tf f);
591
592 #define ICOM_CVMETHOD7(xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng) \
593     void (CALLBACK *fn##xfn)(const ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e,tf f,tg g);
594
595 #define ICOM_CVMETHOD8(xfn,ta,na,tb,nb,tc,nc,td,nd,te,ne,tf,nf,tg,ng,th,nh) \
596     void (CALLBACK *fn##xfn)(const ICOM_INTERFACE* me,ta a,tb b,tc c,td d,te e,tf f,tg g,th h);
597
598
599 #ifdef ICOM_MSVTABLE_COMPAT
600 #define ICOM_DEFINE(iface,ibase) \
601     typedef struct ICOM_VTABLE(iface) ICOM_VTABLE(iface); \
602     struct iface { \
603         const ICOM_VTABLE(iface)* lpvtbl; \
604     }; \
605     struct ICOM_VTABLE(iface) { \
606         long dummyRTTI1; \
607         long dummyRTTI2; \
608         ibase##_IMETHODS \
609         iface##_METHODS \
610     };
611 #define ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE 0,0,
612
613 #else
614 #define ICOM_DEFINE(iface,ibase) \
615     typedef struct ICOM_VTABLE(iface) ICOM_VTABLE(iface); \
616     struct iface { \
617         const ICOM_VTABLE(iface)* lpvtbl; \
618     }; \
619     struct ICOM_VTABLE(iface) { \
620         ibase##_IMETHODS \
621         iface##_METHODS \
622     };
623 #define ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
624 #endif /* ICOM_MSVTABLE_COMPAT */
625
626
627 #define ICOM_CALL(xfn, p)  (p)->lpvtbl->fn##xfn(p)
628 #define ICOM_CALL1(xfn, p,a) (p)->lpvtbl->fn##xfn(p,a)
629 #define ICOM_CALL2(xfn, p,a,b) (p)->lpvtbl->fn##xfn(p,a,b)
630 #define ICOM_CALL3(xfn, p,a,b,c) (p)->lpvtbl->fn##xfn(p,a,b,c)
631 #define ICOM_CALL4(xfn, p,a,b,c,d) (p)->lpvtbl->fn##xfn(p,a,b,c,d)
632 #define ICOM_CALL5(xfn, p,a,b,c,d,e) (p)->lpvtbl->fn##xfn(p,a,b,c,d,e)
633 #define ICOM_CALL6(xfn, p,a,b,c,d,e,f) (p)->lpvtbl->fn##xfn(p,a,b,c,d,e,f)
634 #define ICOM_CALL7(xfn, p,a,b,c,d,e,f,g) (p)->lpvtbl->fn##xfn(p,a,b,c,d,e,f,g)
635 #define ICOM_CALL8(xfn, p,a,b,c,d,e,f,g,h) (p)->lpvtbl->fn##xfn(p,a,b,c,d,e,f,g,h)
636 #define ICOM_CALL9(xfn, p,a,b,c,d,e,f,g,h,i) (p)->lpvtbl->fn##xfn(p,a,b,c,d,e,f,g,h,i)
637 #define ICOM_CALL10(xfn, p,a,b,c,d,e,f,g,h,i,j) (p)->lpvtbl->fn##xfn(p,a,b,c,d,e,f,g,h,i,j)
638
639
640 #define ICOM_THIS(impl,iface)          impl* const This=(impl*)iface
641 #define ICOM_CTHIS(impl,iface)         const impl* const This=(const impl*)iface
642
643 #endif
644
645
646 /*****************************************************************************
647  * Predeclare the interfaces
648  */
649 DEFINE_OLEGUID(IID_IClassFactory,       0x00000001L, 0, 0);
650 typedef struct IClassFactory IClassFactory, *LPCLASSFACTORY;
651
652 DEFINE_OLEGUID(IID_IMalloc,             0x00000002L, 0, 0);
653 typedef struct IMalloc16 IMalloc16,*LPMALLOC16;
654 typedef struct IMalloc IMalloc,*LPMALLOC;
655
656 DEFINE_OLEGUID(IID_IUnknown,            0x00000000L, 0, 0);
657 typedef struct IUnknown IUnknown, *LPUNKNOWN;
658
659
660 /*****************************************************************************
661  * IUnknown interface
662  */
663 #define ICOM_INTERFACE IUnknown
664 #define IUnknown_IMETHODS \
665     ICOM_METHOD2(HRESULT,QueryInterface,REFIID,riid, LPVOID*,ppvObj) \
666     ICOM_METHOD (ULONG,AddRef) \
667     ICOM_METHOD (ULONG,Release)
668 #ifdef ICOM_CINTERFACE
669 typedef struct ICOM_VTABLE(IUnknown) ICOM_VTABLE(IUnknown);
670 struct IUnknown {
671     ICOM_VTABLE(IUnknown)* lpvtbl;
672 #if defined(ICOM_USE_COM_INTERFACE_ATTRIBUTE) && !defined(ICOM_CINTERFACE)
673 } __attribute__ ((com_interface)); 
674 #else
675 };
676 #endif /* ICOM_US_COM_INTERFACE_ATTRIBUTE, !ICOM_CINTERFACE */
677
678 struct ICOM_VTABLE(IUnknown) {
679 #ifdef ICOM_MSVTABLE_COMPAT
680     long dummyRTTI1;
681     long dummyRTTI2;
682 #endif /* ICOM_MSVTABLE_COMPAT */
683
684 #else /* ICOM_CINTERFACE */
685 struct IUnknown {
686
687 #endif /* ICOM_CINTERFACE */
688
689     ICOM_METHOD2(HRESULT,QueryInterface,REFIID,riid, LPVOID*,ppvObj)
690     ICOM_METHOD (ULONG,AddRef)
691     ICOM_METHOD (ULONG,Release)
692 };
693 #undef ICOM_INTERFACE
694
695 /*** IUnknown methods ***/
696 #define IUnknown_QueryInterface(p,a,b) ICOM_CALL2(QueryInterface,p,a,b)
697 #define IUnknown_AddRef(p)             ICOM_CALL (AddRef,p)
698 #define IUnknown_Release(p)            ICOM_CALL (Release,p)
699
700 /*****************************************************************************
701  * IClassFactory interface
702  */
703 #define ICOM_INTERFACE IClassFactory
704 #define IClassFactory_METHODS \
705     ICOM_METHOD3(HRESULT,CreateInstance, LPUNKNOWN,pUnkOuter, REFIID,riid, LPVOID*,ppvObject) \
706     ICOM_METHOD1(HRESULT,LockServer,     BOOL,fLock)
707 #define IClassFactory_IMETHODS \
708     IUnknown_IMETHODS \
709     IClassFactory_METHODS
710 ICOM_DEFINE(IClassFactory,IUnknown)
711 #undef ICOM_INTERFACE
712
713 /*** IUnknown methods ***/
714 #define IClassFactory_QueryInterface(p,a,b) ICOM_CALL2(QueryInterface,p,a,b)
715 #define IClassFactory_AddRef(p)             ICOM_CALL (AddRef,p)
716 #define IClassFactory_Release(p)            ICOM_CALL (Release,p)
717 /*** IClassFactory methods ***/
718 #define IClassFactory_CreateInstance(p,a,b,c) ICOM_CALL3(CreateInstance,p,a,b,c)
719 #define IClassFactory_LockServer(p,a)         ICOM_CALL1(LockServer,p,a)
720
721
722 /*****************************************************************************
723  * IMalloc interface
724  */
725 #define ICOM_INTERFACE IMalloc16
726 #define IMalloc16_METHODS \
727     ICOM_METHOD1 (LPVOID,Alloc,       DWORD,cb) \
728     ICOM_METHOD2 (LPVOID,Realloc,     LPVOID,pv, DWORD,cb) \
729     ICOM_VMETHOD1(       Free,        LPVOID,pv) \
730     ICOM_CMETHOD1(DWORD, GetSize,     LPVOID,pv) \
731     ICOM_CMETHOD1(INT16, DidAlloc,    LPVOID,pv) \
732     ICOM_METHOD  (LPVOID,HeapMinimize)
733 #define IMalloc16_IMETHODS \
734     IUnknown_IMETHODS \
735     IMalloc16_METHODS
736 ICOM_DEFINE(IMalloc16,IUnknown)
737 #undef ICOM_INTERFACE
738
739 /*** IUnknown methods ***/
740 #define IMalloc16_QueryInterface(p,a,b) ICOM_CALL2(QueryInterface,p,a,b)
741 #define IMalloc16_AddRef(p)             ICOM_CALL (AddRef,p)
742 #define IMalloc16_Release(p)            ICOM_CALL (Release,p)
743 /*** IMalloc16 methods ***/
744 #define IMalloc16_Alloc(p,a)      ICOM_CALL1(Alloc,p,a)
745 #define IMalloc16_Realloc(p,a,b)  ICOM_CALL2(Realloc,p,a,b)
746 #define IMalloc16_Free(p,a)       ICOM_CALL1(Free,p,a)
747 #define IMalloc16_GetSize(p,a)    ICOM_CALL1(GetSize,p,a)
748 #define IMalloc16_DidAlloc(p,a)   ICOM_CALL1(DidAlloc,p,a)
749 #define IMalloc16_HeapMinimize(p) ICOM_CALL (HeapMinimize,p)
750
751
752 #define ICOM_INTERFACE IMalloc
753 #define IMalloc_METHODS \
754     ICOM_METHOD1 (LPVOID,Alloc,       DWORD,cb) \
755     ICOM_METHOD2 (LPVOID,Realloc,     LPVOID,pv, DWORD,cb) \
756     ICOM_VMETHOD1(       Free,        LPVOID,pv) \
757     ICOM_CMETHOD1(DWORD, GetSize,     LPVOID,pv) \
758     ICOM_CMETHOD1(INT, DidAlloc,    LPVOID,pv) \
759     ICOM_METHOD  (LPVOID,HeapMinimize)
760 #define IMalloc_IMETHODS \
761     IUnknown_IMETHODS \
762     IMalloc_METHODS
763 ICOM_DEFINE(IMalloc,IUnknown)
764 #undef ICOM_INTERFACE
765
766 /*** IUnknown methods ***/
767 #define IMalloc_QueryInterface(p,a,b) ICOM_CALL2(QueryInterface,p,a,b)
768 #define IMalloc_AddRef(p)             ICOM_CALL (AddRef,p)
769 #define IMalloc_Release(p)            ICOM_CALL (Release,p)
770 /*** IMalloc32 methods ***/
771 #define IMalloc_Alloc(p,a)      ICOM_CALL1(Alloc,p,a)
772 #define IMalloc_Realloc(p,a,b)  ICOM_CALL2(Realloc,p,a,b)
773 #define IMalloc_Free(p,a)       ICOM_CALL1(Free,p,a)
774 #define IMalloc_GetSize(p,a)    ICOM_CALL1(GetSize,p,a)
775 #define IMalloc_DidAlloc(p,a)   ICOM_CALL1(DidAlloc,p,a)
776 #define IMalloc_HeapMinimize(p) ICOM_CALL (HeapMinimize,p)
777
778
779 HRESULT WINAPI CoCreateStandardMalloc16(DWORD dwMemContext, LPMALLOC16* lpMalloc);
780
781 HRESULT WINAPI CoGetMalloc16(DWORD dwMemContext,LPMALLOC16* lpMalloc);
782 HRESULT WINAPI CoGetMalloc(DWORD dwMemContext,LPMALLOC* lpMalloc);
783
784 LPVOID WINAPI CoTaskMemAlloc(ULONG size);
785
786 void WINAPI CoTaskMemFree(LPVOID ptr);
787
788 /* FIXME: unimplemented */
789 LPVOID WINAPI CoTaskMemRealloc(LPVOID ptr, ULONG size);
790
791
792 /*****************************************************************************
793  * Additional API
794  */
795
796 HRESULT WINAPI CoCreateGuid(GUID* pguid);
797
798 void WINAPI CoFreeAllLibraries(void);
799
800 void WINAPI CoFreeLibrary(HINSTANCE hLibrary);
801
802 void WINAPI CoFreeUnusedLibraries(void);
803
804 HRESULT WINAPI CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv);
805
806 HRESULT WINAPI CoGetClassObject(REFCLSID rclsid, DWORD dwClsContext, LPVOID pvReserved, REFIID iid, LPVOID *ppv);
807
808 HRESULT WINAPI CoInitialize16(LPVOID lpReserved);
809 HRESULT WINAPI CoInitialize(LPVOID lpReserved);
810 HRESULT WINAPI CoInitializeEx(LPVOID lpReserved, DWORD dwCoInit);
811
812 void WINAPI CoUninitialize16(void);
813 void WINAPI CoUninitialize(void);
814
815 typedef enum tagCOINIT
816 {
817     COINIT_APARTMENTTHREADED  = 0x2, /* Apartment model */
818     COINIT_MULTITHREADED      = 0x0, /* OLE calls objects on any thread */
819     COINIT_DISABLE_OLE1DDE    = 0x4, /* Don't use DDE for Ole1 support */
820     COINIT_SPEED_OVER_MEMORY  = 0x8  /* Trade memory for speed */
821 } COINIT;
822
823
824 /* FIXME: not implemented */
825 BOOL WINAPI CoIsOle1Class(REFCLSID rclsid);
826
827 HINSTANCE WINAPI CoLoadLibrary(LPOLESTR16 lpszLibName, BOOL bAutoFree);
828
829 HRESULT WINAPI CoLockObjectExternal16(LPUNKNOWN pUnk, BOOL16 fLock, BOOL16 fLastUnlockReleases);
830 HRESULT WINAPI CoLockObjectExternal(LPUNKNOWN pUnk, BOOL fLock, BOOL fLastUnlockReleases);
831
832 /* class registration flags; passed to CoRegisterClassObject */
833 typedef enum tagREGCLS
834 {
835     REGCLS_SINGLEUSE = 0,
836     REGCLS_MULTIPLEUSE = 1,
837     REGCLS_MULTI_SEPARATE = 2,
838     REGCLS_SUSPENDED = 4
839 } REGCLS;
840
841 HRESULT WINAPI CoRegisterClassObject16(REFCLSID rclsid, LPUNKNOWN pUnk, DWORD dwClsContext, DWORD flags, LPDWORD lpdwRegister);
842 HRESULT WINAPI CoRegisterClassObject(REFCLSID rclsid,LPUNKNOWN pUnk,DWORD dwClsContext,DWORD flags,LPDWORD lpdwRegister);
843
844 HRESULT WINAPI CoRevokeClassObject(DWORD dwRegister);
845
846 void WINAPI CoUninitialize16(void);
847 void WINAPI CoUninitialize(void);
848
849 /*****************************************************************************
850  *      COM Server dll - exports
851  */
852 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID * ppv);
853 HRESULT WINAPI DllCanUnloadNow(void);
854
855 /*****************************************************************************
856  * Internal WINE API
857  */
858 #ifdef __WINE__
859 HRESULT WINE_StringFromCLSID(const CLSID *id, LPSTR);
860 #endif
861
862 #endif /* __WINE_WINE_OBJ_BASE_H */