blob: 66a7c1ca5e2a46516d6665950bbb7c9ba72a37d0 [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 *
Robert Shearman1b5ebab2005-03-17 10:26:20 +000046 * 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 inside a critical section.
50 * The identifier following "CS" is the specific critical setion that
51 * must be used.
52 * MUTEX - The value is read or written to with a mutex held.
53 * The identifier following "MUTEX" is the specific mutex that
54 * must be used.
Robert Shearmanc353f852005-01-11 10:45:34 +000055 */
56
Robert Shearman4c8d59d2005-01-17 13:39:40 +000057typedef enum ifstub_state
58{
Robert Shearman95288f92005-02-18 20:03:23 +000059 STUBSTATE_NORMAL_MARSHALED,
60 STUBSTATE_NORMAL_UNMARSHALED,
61 STUBSTATE_TABLE_WEAK_MARSHALED,
62 STUBSTATE_TABLE_WEAK_UNMARSHALED,
63 STUBSTATE_TABLE_STRONG,
64} STUB_STATE;
Robert Shearman4c8d59d2005-01-17 13:39:40 +000065
Mike Hearn5475a2e2004-12-27 19:21:47 +000066/* an interface stub */
67struct ifstub
68{
Robert Shearmanc353f852005-01-11 10:45:34 +000069 struct list entry; /* entry in stub_manager->ifstubs list (CS stub_manager->lock) */
70 IRpcStubBuffer *stubbuffer; /* RO */
71 IID iid; /* RO */
72 IPID ipid; /* RO */
73 IUnknown *iface; /* RO */
Alexandre Julliard611b5ac2005-09-02 11:18:45 +000074 MSHLFLAGS flags; /* so we can enforce process-local marshalling rules (RO) */
Robert Shearmana02cb3e2006-01-10 20:08:02 +010075 IRpcChannelBuffer*chan; /* channel passed to IRpcStubBuffer::Invoke (RO) */
Mike Hearn5475a2e2004-12-27 19:21:47 +000076};
77
78
79/* stub managers hold refs on the object and each interface stub */
80struct stub_manager
81{
Robert Shearmanc353f852005-01-11 10:45:34 +000082 struct list entry; /* entry in apartment stubmgr list (CS apt->cs) */
83 struct list ifstubs; /* list of active ifstubs for the object (CS lock) */
Mike Hearn5475a2e2004-12-27 19:21:47 +000084 CRITICAL_SECTION lock;
Robert Shearmanc353f852005-01-11 10:45:34 +000085 APARTMENT *apt; /* owning apt (RO) */
Mike Hearn5475a2e2004-12-27 19:21:47 +000086
Robert Shearman95288f92005-02-18 20:03:23 +000087 ULONG extrefs; /* number of 'external' references (CS lock) */
Robert Shearmanc353f852005-01-11 10:45:34 +000088 ULONG refs; /* internal reference count (CS apt->cs) */
89 OID oid; /* apartment-scoped unique identifier (RO) */
90 IUnknown *object; /* the object we are managing the stub for (RO) */
91 ULONG next_ipid; /* currently unused (LOCK) */
Alexandre Julliard611b5ac2005-09-02 11:18:45 +000092
93 /* We need to keep a count of the outstanding marshals, so we can enforce the
94 * marshalling rules (ie, you can only unmarshal normal marshals once). Note
95 * that these counts do NOT include unmarshalled interfaces, once a stream is
96 * unmarshalled and a proxy set up, this count is decremented.
97 */
98
99 ULONG norm_refs; /* refcount of normal marshals (CS lock) */
Mike Hearn5475a2e2004-12-27 19:21:47 +0000100};
101
Robert Shearman5ce396f2005-01-14 17:20:27 +0000102/* imported interface proxy */
103struct ifproxy
104{
Robert Shearman4c8d59d2005-01-17 13:39:40 +0000105 struct list entry; /* entry in proxy_manager list (CS parent->cs) */
106 struct proxy_manager *parent; /* owning proxy_manager (RO) */
Robert Shearman5ce396f2005-01-14 17:20:27 +0000107 LPVOID iface; /* interface pointer (RO) */
Robert Shearmandab603d2005-08-27 09:25:16 +0000108 STDOBJREF stdobjref; /* marshal data that represents this object (RO) */
Robert Shearman5ce396f2005-01-14 17:20:27 +0000109 IID iid; /* interface ID (RO) */
Robert Shearman5ce396f2005-01-14 17:20:27 +0000110 LPRPCPROXYBUFFER proxy; /* interface proxy (RO) */
Robert Shearman1b5ebab2005-03-17 10:26:20 +0000111 DWORD refs; /* imported (public) references (MUTEX parent->remoting_mutex) */
Robert Shearman527ef472005-03-07 17:14:11 +0000112 IRpcChannelBuffer *chan; /* channel to object (CS parent->cs) */
Robert Shearman5ce396f2005-01-14 17:20:27 +0000113};
114
115/* imported object / proxy manager */
116struct proxy_manager
117{
Robert Shearman30189742005-01-26 21:07:05 +0000118 const IMultiQIVtbl *lpVtbl;
Robert Shearmandab603d2005-08-27 09:25:16 +0000119 const IMarshalVtbl *lpVtblMarshal;
Robert Shearman5ce396f2005-01-14 17:20:27 +0000120 struct apartment *parent; /* owning apartment (RO) */
121 struct list entry; /* entry in apartment (CS parent->cs) */
Robert Shearman5ce396f2005-01-14 17:20:27 +0000122 OXID oxid; /* object exported ID (RO) */
123 OID oid; /* object ID (RO) */
124 struct list interfaces; /* imported interfaces (CS cs) */
Mike McCormackc7fdb452005-07-05 11:02:54 +0000125 LONG refs; /* proxy reference count (LOCK) */
Robert Shearman5ce396f2005-01-14 17:20:27 +0000126 CRITICAL_SECTION cs; /* thread safety for this object and children */
Robert Shearman6b89a922005-01-24 11:24:08 +0000127 ULONG sorflags; /* STDOBJREF flags (RO) */
Robert Shearmanad34f3d2005-01-25 10:57:24 +0000128 IRemUnknown *remunk; /* proxy to IRemUnknown used for lifecycle management (CS cs) */
Robert Shearman1b5ebab2005-03-17 10:26:20 +0000129 HANDLE remoting_mutex; /* mutex used for synchronizing access to IRemUnknown */
Robert Shearman92a1f522006-03-05 13:37:22 +0000130 MSHCTX dest_context; /* context used for activating optimisations (LOCK) */
131 void *dest_context_data; /* reserved context value (LOCK) */
Robert Shearman5ce396f2005-01-14 17:20:27 +0000132};
133
134/* this needs to become a COM object that implements IRemUnknown */
135struct apartment
136{
Robert Shearmana37a5012006-02-20 11:15:57 +0100137 struct list entry;
Robert Shearman5ce396f2005-01-14 17:20:27 +0000138
Mike McCormackc7fdb452005-07-05 11:02:54 +0000139 LONG refs; /* refcount of the apartment (LOCK) */
Robert Shearmana37a5012006-02-20 11:15:57 +0100140 BOOL multi_threaded; /* multi-threaded or single-threaded apartment? (RO) */
Robert Shearman5ce396f2005-01-14 17:20:27 +0000141 DWORD tid; /* thread id (RO) */
Robert Shearman5ce396f2005-01-14 17:20:27 +0000142 OXID oxid; /* object exporter ID (RO) */
Mike McCormackc7fdb452005-07-05 11:02:54 +0000143 LONG ipidc; /* interface pointer ID counter, starts at 1 (LOCK) */
Robert Shearmancd2fafb2006-01-10 20:09:08 +0100144 HWND win; /* message window (LOCK) */
Robert Shearman5ce396f2005-01-14 17:20:27 +0000145 CRITICAL_SECTION cs; /* thread safety */
146 LPMESSAGEFILTER filter; /* message filter (CS cs) */
147 struct list proxies; /* imported objects (CS cs) */
148 struct list stubmgrs; /* stub managers for exported objects (CS cs) */
Robert Shearmanad34f3d2005-01-25 10:57:24 +0000149 BOOL remunk_exported; /* has the IRemUnknown interface for this apartment been created yet? (CS cs) */
Robert Shearman552cc7d2005-02-15 15:44:25 +0000150 LONG remoting_started; /* has the RPC system been started for this apartment? (LOCK) */
Robert Shearman5ce396f2005-01-14 17:20:27 +0000151
Robert Shearman552cc7d2005-02-15 15:44:25 +0000152 /* FIXME: OID's should be given out by RPCSS */
Alexandre Julliard2a467022005-02-08 12:55:26 +0000153 OID oidc; /* object ID counter, starts at 1, zero is invalid OID (CS cs) */
Robert Shearman5ce396f2005-01-14 17:20:27 +0000154};
155
156/* this is what is stored in TEB->ReservedForOle */
157struct oletls
158{
159 struct apartment *apt;
160 IErrorInfo *errorinfo; /* see errorinfo.c */
161 IUnknown *state; /* see CoSetState */
162 DWORD inits; /* number of times CoInitializeEx called */
163};
164
Robert Shearman552cc7d2005-02-15 15:44:25 +0000165
166/* Global Interface Table Functions */
167
Robert Shearman5ce396f2005-01-14 17:20:27 +0000168extern void* StdGlobalInterfaceTable_Construct(void);
169extern void StdGlobalInterfaceTable_Destroy(void* self);
170extern HRESULT StdGlobalInterfaceTable_GetFactory(LPVOID *ppv);
Robert Shearman552cc7d2005-02-15 15:44:25 +0000171extern void* StdGlobalInterfaceTableInstance;
Robert Shearman5ce396f2005-01-14 17:20:27 +0000172
173/* FIXME: these shouldn't be needed, except for 16-bit functions */
174extern HRESULT WINE_StringFromCLSID(const CLSID *id,LPSTR idstr);
Robert Shearman5ce396f2005-01-14 17:20:27 +0000175
Robert Shearmanf7b65cc2005-11-09 10:29:11 +0000176HRESULT COM_OpenKeyForCLSID(REFCLSID clsid, LPCWSTR keyname, REGSAM access, HKEY *key);
Robert Shearman5ce396f2005-01-14 17:20:27 +0000177HRESULT MARSHAL_GetStandardMarshalCF(LPVOID *ppv);
178
Robert Shearman552cc7d2005-02-15 15:44:25 +0000179/* Stub Manager */
180
Robert Shearmanc353f852005-01-11 10:45:34 +0000181ULONG stub_manager_int_addref(struct stub_manager *This);
182ULONG stub_manager_int_release(struct stub_manager *This);
Alexandre Julliard611b5ac2005-09-02 11:18:45 +0000183struct stub_manager *new_stub_manager(APARTMENT *apt, IUnknown *object);
Robert Shearmanc353f852005-01-11 10:45:34 +0000184ULONG stub_manager_ext_addref(struct stub_manager *m, ULONG refs);
185ULONG stub_manager_ext_release(struct stub_manager *m, ULONG refs);
Alexandre Julliard611b5ac2005-09-02 11:18:45 +0000186struct ifstub *stub_manager_new_ifstub(struct stub_manager *m, IRpcStubBuffer *sb, IUnknown *iptr, REFIID iid, MSHLFLAGS flags);
187struct ifstub *stub_manager_find_ifstub(struct stub_manager *m, REFIID iid, MSHLFLAGS flags);
Robert Shearman6036a772005-01-14 16:48:34 +0000188struct stub_manager *get_stub_manager(APARTMENT *apt, OID oid);
189struct stub_manager *get_stub_manager_from_object(APARTMENT *apt, void *object);
Alexandre Julliard611b5ac2005-09-02 11:18:45 +0000190BOOL stub_manager_notify_unmarshal(struct stub_manager *m, const IPID *ipid);
191BOOL stub_manager_is_table_marshaled(struct stub_manager *m, const IPID *ipid);
192void stub_manager_release_marshal_data(struct stub_manager *m, ULONG refs, const IPID *ipid);
Robert Shearmanad34f3d2005-01-25 10:57:24 +0000193HRESULT ipid_to_stub_manager(const IPID *ipid, APARTMENT **stub_apt, struct stub_manager **stubmgr_ret);
Robert Shearmana02cb3e2006-01-10 20:08:02 +0100194HRESULT ipid_get_dispatch_params(const IPID *ipid, APARTMENT **stub_apt, IRpcStubBuffer **stub, IRpcChannelBuffer **chan);
Robert Shearmanad34f3d2005-01-25 10:57:24 +0000195HRESULT start_apartment_remote_unknown(void);
Mike Hearn5475a2e2004-12-27 19:21:47 +0000196
Robert Shearman8971f062005-03-11 10:19:10 +0000197HRESULT marshal_object(APARTMENT *apt, STDOBJREF *stdobjref, REFIID riid, IUnknown *obj, MSHLFLAGS mshlflags);
198
Robert Shearman552cc7d2005-02-15 15:44:25 +0000199/* RPC Backend */
Mike Hearn5475a2e2004-12-27 19:21:47 +0000200
Robert Shearman1b5ebab2005-03-17 10:26:20 +0000201struct dispatch_params;
202
Robert Shearman552cc7d2005-02-15 15:44:25 +0000203void RPC_StartRemoting(struct apartment *apt);
Robert Shearman7406cc22006-03-05 13:37:34 +0000204HRESULT RPC_CreateClientChannel(const OXID *oxid, const IPID *ipid,
205 DWORD dest_context, void *dest_context_data,
206 IRpcChannelBuffer **chan);
Robert Shearmana02cb3e2006-01-10 20:08:02 +0100207HRESULT RPC_CreateServerChannel(IRpcChannelBuffer **chan);
Robert Shearman43df8b62005-09-14 10:07:01 +0000208void RPC_ExecuteCall(struct dispatch_params *params);
Robert Shearmandb6db7c2005-02-15 15:02:49 +0000209HRESULT RPC_RegisterInterface(REFIID riid);
Robert Shearman552cc7d2005-02-15 15:44:25 +0000210void RPC_UnregisterInterface(REFIID riid);
211void RPC_StartLocalServer(REFCLSID clsid, IStream *stream);
212HRESULT RPC_GetLocalClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv);
Marcus Meissner0749fc22002-02-05 18:11:17 +0000213
Francois Gouget3116bd92000-11-25 03:08:23 +0000214/* This function initialize the Running Object Table */
Eric Pouech4056d7e2004-12-13 21:19:01 +0000215HRESULT WINAPI RunningObjectTableImpl_Initialize(void);
Francois Gouget3116bd92000-11-25 03:08:23 +0000216
217/* This function uninitialize the Running Object Table */
Eric Pouech4056d7e2004-12-13 21:19:01 +0000218HRESULT WINAPI RunningObjectTableImpl_UnInitialize(void);
Francois Gouget3116bd92000-11-25 03:08:23 +0000219
220/* This function decomposes a String path to a String Table containing all the elements ("\" or "subDirectory" or "Directory" or "FileName") of the path */
Mike McCormack912ffd62005-05-12 09:57:21 +0000221int FileMonikerImpl_DecomposePath(LPCOLESTR str, LPOLESTR** stringTable);
Francois Gouget3116bd92000-11-25 03:08:23 +0000222
Robert Shearman552cc7d2005-02-15 15:44:25 +0000223
224/* Apartment Functions */
225
Robert Shearman8971f062005-03-11 10:19:10 +0000226APARTMENT *apartment_findfromoxid(OXID oxid, BOOL ref);
227APARTMENT *apartment_findfromtid(DWORD tid);
228DWORD apartment_addref(struct apartment *apt);
229DWORD apartment_release(struct apartment *apt);
230HRESULT apartment_disconnectproxies(struct apartment *apt);
231void apartment_disconnectobject(struct apartment *apt, void *object);
232static inline HRESULT apartment_getoxid(struct apartment *apt, OXID *oxid)
233{
234 *oxid = apt->oxid;
235 return S_OK;
236}
Robert Shearmancd2fafb2006-01-10 20:09:08 +0100237HRESULT apartment_createwindowifneeded(struct apartment *apt);
Robert Shearmanfcba7832006-01-10 20:08:41 +0100238HWND apartment_getwindow(struct apartment *apt);
Robert Shearmanb75db2d2006-01-09 18:41:19 +0100239void apartment_joinmta(void);
Mike Hearna6a416c2005-01-05 17:14:33 +0000240
Robert Shearman1b5ebab2005-03-17 10:26:20 +0000241
242/* DCOM messages used by the apartment window (not compatible with native) */
243#define DM_EXECUTERPC (WM_USER + 0) /* WPARAM = 0, LPARAM = (struct dispatch_params *) */
Robert Shearman2ff17112005-02-14 11:50:51 +0000244
Ove Kaavenef57c4d2003-06-04 20:11:34 +0000245/*
246 * Per-thread values are stored in the TEB on offset 0xF80,
247 * see http://www.microsoft.com/msj/1099/bugslayer/bugslayer1099.htm
248 */
Mike Hearna6a416c2005-01-05 17:14:33 +0000249
250/* will create if necessary */
251static inline struct oletls *COM_CurrentInfo(void)
Ove Kaavenef57c4d2003-06-04 20:11:34 +0000252{
Robert Shearman452491b2005-01-12 19:48:39 +0000253 if (!NtCurrentTeb()->ReservedForOle)
Mike Hearna6a416c2005-01-05 17:14:33 +0000254 NtCurrentTeb()->ReservedForOle = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct oletls));
Robert Shearman452491b2005-01-12 19:48:39 +0000255
Mike Hearna6a416c2005-01-05 17:14:33 +0000256 return NtCurrentTeb()->ReservedForOle;
Ove Kaavenef57c4d2003-06-04 20:11:34 +0000257}
258
Mike Hearna6a416c2005-01-05 17:14:33 +0000259static inline APARTMENT* COM_CurrentApt(void)
260{
261 return COM_CurrentInfo()->apt;
262}
Ove Kaavenef57c4d2003-06-04 20:11:34 +0000263
Alexandre Julliard936198c2004-08-13 00:44:22 +0000264#define ICOM_THIS_MULTI(impl,field,iface) impl* const This=(impl*)((char*)(iface) - offsetof(impl,field))
265
Robert Shearman1b5ebab2005-03-17 10:26:20 +0000266/* helpers for debugging */
Alexandre Julliard20a1a202005-09-09 10:19:44 +0000267# define DEBUG_SET_CRITSEC_NAME(cs, name) (cs)->DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": " name)
268# define DEBUG_CLEAR_CRITSEC_NAME(cs) (cs)->DebugInfo->Spare[0] = 0
Robert Shearman1b5ebab2005-03-17 10:26:20 +0000269
Marcus Meissnerf3d99b22005-05-16 14:12:53 +0000270extern HINSTANCE OLE32_hInstance; /* FIXME: make static */
271
Robert Shearmanf4198802005-06-20 10:33:17 +0000272#define CHARS_IN_GUID 39 /* including NULL */
273
Robert Shearmanb9d77542005-11-28 11:16:58 +0100274/* Exported non-interface Data Advise Holder functions */
275HRESULT DataAdviseHolder_OnConnect(IDataAdviseHolder *iface, IDataObject *pDelegate);
276void DataAdviseHolder_OnDisconnect(IDataAdviseHolder *iface);
277
Francois Gouget3116bd92000-11-25 03:08:23 +0000278#endif /* __WINE_OLE_COMPOBJ_H */