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