blob: 307fc9b85e9efc0d143fbb675cd80d0cd997ecc9 [file] [log] [blame]
Alexandre Julliard0799c1a2002-03-09 23:29:33 +00001/*
2 * Copyright 1995 Martin von Loewis
3 * Copyright 1998 Justin Bradford
4 * Copyright 1999 Francis Beaudet
5 * Copyright 1999 Sylvain St-Germain
6 * Copyright 2002 Marcus Meissner
Ove Kaavenef57c4d2003-06-04 20:11:34 +00007 * Copyright 2003 Ove Kåven, TransGaming Technologies
Alexandre Julliard2a467022005-02-08 12:55:26 +00008 * Copyright 2004 Mike Hearn, Rob Shearman, CodeWeavers Inc
Alexandre Julliard0799c1a2002-03-09 23:29:33 +00009 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24
Francois Gouget3116bd92000-11-25 03:08:23 +000025#ifndef __WINE_OLE_COMPOBJ_H
26#define __WINE_OLE_COMPOBJ_H
27
28/* All private prototype functions used by OLE will be added to this header file */
29
Alexandre Julliarde37c6e12003-09-05 23:08:26 +000030#include <stdarg.h>
31
Mike Hearn5475a2e2004-12-27 19:21:47 +000032#include "wine/list.h"
33
Alexandre Julliarde37c6e12003-09-05 23:08:26 +000034#include "windef.h"
35#include "winbase.h"
Francois Gouget3116bd92000-11-25 03:08:23 +000036#include "wtypes.h"
Ove Kaavenef57c4d2003-06-04 20:11:34 +000037#include "dcom.h"
Alexandre Julliarde37c6e12003-09-05 23:08:26 +000038#include "winreg.h"
Alexandre Julliard7df1b9e2003-08-28 19:57:35 +000039#include "winternl.h"
Ove Kaavenef57c4d2003-06-04 20:11:34 +000040
Mike Hearna6a416c2005-01-05 17:14:33 +000041struct apartment;
Mike Hearna6a416c2005-01-05 17:14:33 +000042typedef struct apartment APARTMENT;
Francois Gouget3116bd92000-11-25 03:08:23 +000043
Robert Shearmanc353f852005-01-11 10:45:34 +000044/* Thread-safety Annotation Legend:
45 *
46 * RO - The value is read only. It never changes after creation, so no
47 * locking is required.
48 * LOCK - The value is written to only using Interlocked* functions.
49 * CS - The value is read or written to with a critical section held.
50 * The identifier following "CS" is the specific critical section that
51 * must be used.
52 */
53
Robert Shearman4c8d59d2005-01-17 13:39:40 +000054typedef enum ifstub_state
55{
Robert Shearman95288f92005-02-18 20:03:23 +000056 STUBSTATE_NORMAL_MARSHALED,
57 STUBSTATE_NORMAL_UNMARSHALED,
58 STUBSTATE_TABLE_WEAK_MARSHALED,
59 STUBSTATE_TABLE_WEAK_UNMARSHALED,
60 STUBSTATE_TABLE_STRONG,
61} STUB_STATE;
Robert Shearman4c8d59d2005-01-17 13:39:40 +000062
Mike Hearn5475a2e2004-12-27 19:21:47 +000063/* an interface stub */
64struct ifstub
65{
Robert Shearmanc353f852005-01-11 10:45:34 +000066 struct list entry; /* entry in stub_manager->ifstubs list (CS stub_manager->lock) */
67 IRpcStubBuffer *stubbuffer; /* RO */
68 IID iid; /* RO */
69 IPID ipid; /* RO */
70 IUnknown *iface; /* RO */
Mike Hearn5475a2e2004-12-27 19:21:47 +000071};
72
73
74/* stub managers hold refs on the object and each interface stub */
75struct stub_manager
76{
Robert Shearmanc353f852005-01-11 10:45:34 +000077 struct list entry; /* entry in apartment stubmgr list (CS apt->cs) */
78 struct list ifstubs; /* list of active ifstubs for the object (CS lock) */
Mike Hearn5475a2e2004-12-27 19:21:47 +000079 CRITICAL_SECTION lock;
Robert Shearmanc353f852005-01-11 10:45:34 +000080 APARTMENT *apt; /* owning apt (RO) */
Mike Hearn5475a2e2004-12-27 19:21:47 +000081
Robert Shearman95288f92005-02-18 20:03:23 +000082 ULONG extrefs; /* number of 'external' references (CS lock) */
Robert Shearmanc353f852005-01-11 10:45:34 +000083 ULONG refs; /* internal reference count (CS apt->cs) */
84 OID oid; /* apartment-scoped unique identifier (RO) */
85 IUnknown *object; /* the object we are managing the stub for (RO) */
86 ULONG next_ipid; /* currently unused (LOCK) */
Robert Shearman95288f92005-02-18 20:03:23 +000087 STUB_STATE state; /* state machine (CS lock) */
Mike Hearn5475a2e2004-12-27 19:21:47 +000088};
89
Robert Shearman5ce396f2005-01-14 17:20:27 +000090/* imported interface proxy */
91struct ifproxy
92{
Robert Shearman4c8d59d2005-01-17 13:39:40 +000093 struct list entry; /* entry in proxy_manager list (CS parent->cs) */
94 struct proxy_manager *parent; /* owning proxy_manager (RO) */
Robert Shearman5ce396f2005-01-14 17:20:27 +000095 LPVOID iface; /* interface pointer (RO) */
96 IID iid; /* interface ID (RO) */
97 IPID ipid; /* imported interface ID (RO) */
98 LPRPCPROXYBUFFER proxy; /* interface proxy (RO) */
Robert Shearman4c8d59d2005-01-17 13:39:40 +000099 DWORD refs; /* imported (public) references (CS parent->cs) */
Robert Shearman527ef472005-03-07 17:14:11 +0000100 IRpcChannelBuffer *chan; /* channel to object (CS parent->cs) */
Robert Shearman5ce396f2005-01-14 17:20:27 +0000101};
102
103/* imported object / proxy manager */
104struct proxy_manager
105{
Robert Shearman30189742005-01-26 21:07:05 +0000106 const IMultiQIVtbl *lpVtbl;
Robert Shearman5ce396f2005-01-14 17:20:27 +0000107 struct apartment *parent; /* owning apartment (RO) */
108 struct list entry; /* entry in apartment (CS parent->cs) */
Robert Shearman5ce396f2005-01-14 17:20:27 +0000109 OXID oxid; /* object exported ID (RO) */
110 OID oid; /* object ID (RO) */
111 struct list interfaces; /* imported interfaces (CS cs) */
112 DWORD refs; /* proxy reference count (LOCK) */
113 CRITICAL_SECTION cs; /* thread safety for this object and children */
Robert Shearman6b89a922005-01-24 11:24:08 +0000114 ULONG sorflags; /* STDOBJREF flags (RO) */
Robert Shearmanad34f3d2005-01-25 10:57:24 +0000115 IRemUnknown *remunk; /* proxy to IRemUnknown used for lifecycle management (CS cs) */
Robert Shearman5ce396f2005-01-14 17:20:27 +0000116};
117
118/* this needs to become a COM object that implements IRemUnknown */
119struct apartment
120{
121 struct list entry;
122
123 DWORD refs; /* refcount of the apartment (LOCK) */
124 DWORD model; /* threading model (RO) */
125 DWORD tid; /* thread id (RO) */
126 HANDLE thread; /* thread handle (RO) */
127 OXID oxid; /* object exporter ID (RO) */
Robert Shearmancbbf08a2005-01-26 20:53:06 +0000128 DWORD ipidc; /* interface pointer ID counter, starts at 1 (LOCK) */
Robert Shearman5ce396f2005-01-14 17:20:27 +0000129 HWND win; /* message window (RO) */
130 CRITICAL_SECTION cs; /* thread safety */
131 LPMESSAGEFILTER filter; /* message filter (CS cs) */
132 struct list proxies; /* imported objects (CS cs) */
133 struct list stubmgrs; /* stub managers for exported objects (CS cs) */
Robert Shearmanad34f3d2005-01-25 10:57:24 +0000134 BOOL remunk_exported; /* has the IRemUnknown interface for this apartment been created yet? (CS cs) */
Robert Shearman552cc7d2005-02-15 15:44:25 +0000135 LONG remoting_started; /* has the RPC system been started for this apartment? (LOCK) */
Robert Shearman5ce396f2005-01-14 17:20:27 +0000136
Robert Shearman552cc7d2005-02-15 15:44:25 +0000137 /* FIXME: OID's should be given out by RPCSS */
Alexandre Julliard2a467022005-02-08 12:55:26 +0000138 OID oidc; /* object ID counter, starts at 1, zero is invalid OID (CS cs) */
Robert Shearman5ce396f2005-01-14 17:20:27 +0000139};
140
141/* this is what is stored in TEB->ReservedForOle */
142struct oletls
143{
144 struct apartment *apt;
145 IErrorInfo *errorinfo; /* see errorinfo.c */
146 IUnknown *state; /* see CoSetState */
147 DWORD inits; /* number of times CoInitializeEx called */
148};
149
Robert Shearman552cc7d2005-02-15 15:44:25 +0000150
151/* Global Interface Table Functions */
152
Robert Shearman5ce396f2005-01-14 17:20:27 +0000153extern void* StdGlobalInterfaceTable_Construct(void);
154extern void StdGlobalInterfaceTable_Destroy(void* self);
155extern HRESULT StdGlobalInterfaceTable_GetFactory(LPVOID *ppv);
Robert Shearman552cc7d2005-02-15 15:44:25 +0000156extern void* StdGlobalInterfaceTableInstance;
Robert Shearman5ce396f2005-01-14 17:20:27 +0000157
158/* FIXME: these shouldn't be needed, except for 16-bit functions */
159extern HRESULT WINE_StringFromCLSID(const CLSID *id,LPSTR idstr);
160HRESULT WINAPI __CLSIDFromStringA(LPCSTR idstr, CLSID *id);
161
Robert Shearman5ce396f2005-01-14 17:20:27 +0000162HRESULT MARSHAL_GetStandardMarshalCF(LPVOID *ppv);
163
Robert Shearman552cc7d2005-02-15 15:44:25 +0000164/* Stub Manager */
165
Robert Shearmanc353f852005-01-11 10:45:34 +0000166ULONG stub_manager_int_addref(struct stub_manager *This);
167ULONG stub_manager_int_release(struct stub_manager *This);
Robert Shearman95288f92005-02-18 20:03:23 +0000168struct stub_manager *new_stub_manager(APARTMENT *apt, IUnknown *object, MSHLFLAGS mshlflags);
Robert Shearmanc353f852005-01-11 10:45:34 +0000169ULONG stub_manager_ext_addref(struct stub_manager *m, ULONG refs);
170ULONG stub_manager_ext_release(struct stub_manager *m, ULONG refs);
Robert Shearman95288f92005-02-18 20:03:23 +0000171struct ifstub *stub_manager_new_ifstub(struct stub_manager *m, IRpcStubBuffer *sb, IUnknown *iptr, REFIID iid);
Robert Shearman6036a772005-01-14 16:48:34 +0000172struct stub_manager *get_stub_manager(APARTMENT *apt, OID oid);
173struct stub_manager *get_stub_manager_from_object(APARTMENT *apt, void *object);
Robert Shearman95288f92005-02-18 20:03:23 +0000174BOOL stub_manager_notify_unmarshal(struct stub_manager *m);
175BOOL stub_manager_is_table_marshaled(struct stub_manager *m);
176void stub_manager_release_marshal_data(struct stub_manager *m, ULONG refs);
Robert Shearmanad34f3d2005-01-25 10:57:24 +0000177HRESULT ipid_to_stub_manager(const IPID *ipid, APARTMENT **stub_apt, struct stub_manager **stubmgr_ret);
Robert Shearman2ff17112005-02-14 11:50:51 +0000178IRpcStubBuffer *ipid_to_apt_and_stubbuffer(const IPID *ipid, APARTMENT **stub_apt);
Robert Shearmanad34f3d2005-01-25 10:57:24 +0000179HRESULT start_apartment_remote_unknown(void);
Mike Hearn5475a2e2004-12-27 19:21:47 +0000180
Robert Shearman8971f062005-03-11 10:19:10 +0000181HRESULT marshal_object(APARTMENT *apt, STDOBJREF *stdobjref, REFIID riid, IUnknown *obj, MSHLFLAGS mshlflags);
182
Robert Shearman552cc7d2005-02-15 15:44:25 +0000183/* RPC Backend */
Mike Hearn5475a2e2004-12-27 19:21:47 +0000184
Robert Shearman552cc7d2005-02-15 15:44:25 +0000185void RPC_StartRemoting(struct apartment *apt);
186HRESULT RPC_CreateClientChannel(const OXID *oxid, const IPID *ipid, IRpcChannelBuffer **pipebuf);
Robert Shearman2ff17112005-02-14 11:50:51 +0000187HRESULT RPC_ExecuteCall(RPCOLEMESSAGE *msg, IRpcStubBuffer *stub);
Robert Shearmandb6db7c2005-02-15 15:02:49 +0000188HRESULT RPC_RegisterInterface(REFIID riid);
Robert Shearman552cc7d2005-02-15 15:44:25 +0000189void RPC_UnregisterInterface(REFIID riid);
190void RPC_StartLocalServer(REFCLSID clsid, IStream *stream);
191HRESULT RPC_GetLocalClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv);
Marcus Meissner0749fc22002-02-05 18:11:17 +0000192
Francois Gouget3116bd92000-11-25 03:08:23 +0000193/* This function initialize the Running Object Table */
Eric Pouech4056d7e2004-12-13 21:19:01 +0000194HRESULT WINAPI RunningObjectTableImpl_Initialize(void);
Francois Gouget3116bd92000-11-25 03:08:23 +0000195
196/* This function uninitialize the Running Object Table */
Eric Pouech4056d7e2004-12-13 21:19:01 +0000197HRESULT WINAPI RunningObjectTableImpl_UnInitialize(void);
Francois Gouget3116bd92000-11-25 03:08:23 +0000198
199/* This function decomposes a String path to a String Table containing all the elements ("\" or "subDirectory" or "Directory" or "FileName") of the path */
Patrik Stridvallbc38d6b2001-07-20 18:00:00 +0000200int WINAPI FileMonikerImpl_DecomposePath(LPCOLESTR str, LPOLESTR** stringTable);
Francois Gouget3116bd92000-11-25 03:08:23 +0000201
Robert Shearman552cc7d2005-02-15 15:44:25 +0000202
203/* Apartment Functions */
204
Robert Shearman8971f062005-03-11 10:19:10 +0000205APARTMENT *apartment_findfromoxid(OXID oxid, BOOL ref);
206APARTMENT *apartment_findfromtid(DWORD tid);
207DWORD apartment_addref(struct apartment *apt);
208DWORD apartment_release(struct apartment *apt);
209HRESULT apartment_disconnectproxies(struct apartment *apt);
210void apartment_disconnectobject(struct apartment *apt, void *object);
211static inline HRESULT apartment_getoxid(struct apartment *apt, OXID *oxid)
212{
213 *oxid = apt->oxid;
214 return S_OK;
215}
Mike Hearna6a416c2005-01-05 17:14:33 +0000216
Robert Shearman2ff17112005-02-14 11:50:51 +0000217/* messages used by the apartment window (not compatible with native) */
218#define DM_EXECUTERPC (WM_USER + 0) /* WPARAM = (RPCOLEMESSAGE *), LPARAM = (IRpcStubBuffer *) */
219
Ove Kaavenef57c4d2003-06-04 20:11:34 +0000220/*
221 * Per-thread values are stored in the TEB on offset 0xF80,
222 * see http://www.microsoft.com/msj/1099/bugslayer/bugslayer1099.htm
223 */
Mike Hearna6a416c2005-01-05 17:14:33 +0000224
225/* will create if necessary */
226static inline struct oletls *COM_CurrentInfo(void)
Ove Kaavenef57c4d2003-06-04 20:11:34 +0000227{
Robert Shearman452491b2005-01-12 19:48:39 +0000228 if (!NtCurrentTeb()->ReservedForOle)
Mike Hearna6a416c2005-01-05 17:14:33 +0000229 NtCurrentTeb()->ReservedForOle = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct oletls));
Robert Shearman452491b2005-01-12 19:48:39 +0000230
Mike Hearna6a416c2005-01-05 17:14:33 +0000231 return NtCurrentTeb()->ReservedForOle;
Ove Kaavenef57c4d2003-06-04 20:11:34 +0000232}
233
Mike Hearna6a416c2005-01-05 17:14:33 +0000234static inline APARTMENT* COM_CurrentApt(void)
235{
236 return COM_CurrentInfo()->apt;
237}
Ove Kaavenef57c4d2003-06-04 20:11:34 +0000238
Alexandre Julliard936198c2004-08-13 00:44:22 +0000239#define ICOM_THIS_MULTI(impl,field,iface) impl* const This=(impl*)((char*)(iface) - offsetof(impl,field))
240
Francois Gouget3116bd92000-11-25 03:08:23 +0000241#endif /* __WINE_OLE_COMPOBJ_H */