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
7 * Copyright 2003 Ove Kåven, TransGaming Technologies
8 * Copyright 2004 Mike Hearn, CodeWeavers Inc
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.
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.
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
25 #ifndef __WINE_OLE_COMPOBJ_H
26 #define __WINE_OLE_COMPOBJ_H
28 /* All private prototype functions used by OLE will be added to this header file */
32 #include "wine/list.h"
42 typedef struct apartment APARTMENT;
44 /* Thread-safety Annotation Legend:
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
54 /* an interface stub */
57 struct list entry; /* entry in stub_manager->ifstubs list (CS stub_manager->lock) */
58 IRpcStubBuffer *stubbuffer; /* RO */
61 IUnknown *iface; /* RO */
62 BOOL table; /* CS stub_manager->lock */
66 /* stub managers hold refs on the object and each interface stub */
69 struct list entry; /* entry in apartment stubmgr list (CS apt->cs) */
70 struct list ifstubs; /* list of active ifstubs for the object (CS lock) */
71 CRITICAL_SECTION lock;
72 APARTMENT *apt; /* owning apt (RO) */
74 ULONG extrefs; /* number of 'external' references (LOCK) */
75 ULONG refs; /* internal reference count (CS apt->cs) */
76 OID oid; /* apartment-scoped unique identifier (RO) */
77 IUnknown *object; /* the object we are managing the stub for (RO) */
78 ULONG next_ipid; /* currently unused (LOCK) */
81 /* imported interface proxy */
85 LPVOID iface; /* interface pointer (RO) */
86 IID iid; /* interface ID (RO) */
87 IPID ipid; /* imported interface ID (RO) */
88 LPRPCPROXYBUFFER proxy; /* interface proxy (RO) */
89 DWORD refs; /* imported (public) references (CS ?) */
92 /* imported object / proxy manager */
95 const IInternalUnknownVtbl *lpVtbl;
96 struct apartment *parent; /* owning apartment (RO) */
97 struct list entry; /* entry in apartment (CS parent->cs) */
98 LPRPCCHANNELBUFFER chan; /* channel to object (CS cs) */
99 OXID oxid; /* object exported ID (RO) */
100 OID oid; /* object ID (RO) */
101 struct list interfaces; /* imported interfaces (CS cs) */
102 DWORD refs; /* proxy reference count (LOCK) */
103 CRITICAL_SECTION cs; /* thread safety for this object and children */
106 /* this needs to become a COM object that implements IRemUnknown */
111 DWORD refs; /* refcount of the apartment (LOCK) */
112 DWORD model; /* threading model (RO) */
113 DWORD tid; /* thread id (RO) */
114 HANDLE thread; /* thread handle (RO) */
115 OXID oxid; /* object exporter ID (RO) */
116 OID oidc; /* object ID counter, starts at 1, zero is invalid OID (CS cs) */
117 HWND win; /* message window (RO) */
118 CRITICAL_SECTION cs; /* thread safety */
119 LPMESSAGEFILTER filter; /* message filter (CS cs) */
120 struct list proxies; /* imported objects (CS cs) */
121 struct list stubmgrs; /* stub managers for exported objects (CS cs) */
123 DWORD listenertid; /* id of apartment_listener_thread. FIXME: remove me */
126 /* this is what is stored in TEB->ReservedForOle */
129 struct apartment *apt;
130 IErrorInfo *errorinfo; /* see errorinfo.c */
131 IUnknown *state; /* see CoSetState */
132 DWORD inits; /* number of times CoInitializeEx called */
135 extern void* StdGlobalInterfaceTable_Construct(void);
136 extern void StdGlobalInterfaceTable_Destroy(void* self);
137 extern HRESULT StdGlobalInterfaceTable_GetFactory(LPVOID *ppv);
139 /* FIXME: these shouldn't be needed, except for 16-bit functions */
140 extern HRESULT WINE_StringFromCLSID(const CLSID *id,LPSTR idstr);
141 HRESULT WINAPI __CLSIDFromStringA(LPCSTR idstr, CLSID *id);
143 extern HRESULT create_marshalled_proxy(REFCLSID rclsid, REFIID iid, LPVOID *ppv);
145 extern void* StdGlobalInterfaceTableInstance;
147 /* Standard Marshalling definitions */
148 typedef struct _wine_marshal_id {
149 OXID oxid; /* id of apartment */
150 OID oid; /* id of stub manager */
151 IPID ipid; /* id of interface pointer */
155 MARSHAL_Compare_Mids(wine_marshal_id *mid1,wine_marshal_id *mid2) {
157 (mid1->oxid == mid2->oxid) &&
158 (mid1->oid == mid2->oid) &&
159 IsEqualGUID(&(mid1->ipid),&(mid2->ipid))
163 HRESULT MARSHAL_Disconnect_Proxies(APARTMENT *apt);
164 HRESULT MARSHAL_GetStandardMarshalCF(LPVOID *ppv);
166 ULONG stub_manager_int_addref(struct stub_manager *This);
167 ULONG stub_manager_int_release(struct stub_manager *This);
168 struct stub_manager *new_stub_manager(APARTMENT *apt, IUnknown *object);
169 ULONG stub_manager_ext_addref(struct stub_manager *m, ULONG refs);
170 ULONG stub_manager_ext_release(struct stub_manager *m, ULONG refs);
171 IRpcStubBuffer *stub_manager_ipid_to_stubbuffer(struct stub_manager *m, const IPID *iid);
172 struct ifstub *stub_manager_new_ifstub(struct stub_manager *m, IRpcStubBuffer *sb, IUnknown *iptr, REFIID iid, BOOL tablemarshal);
173 struct stub_manager *get_stub_manager(APARTMENT *apt, OID oid);
174 struct stub_manager *get_stub_manager_from_object(APARTMENT *apt, void *object);
176 IRpcStubBuffer *mid_to_stubbuffer(wine_marshal_id *mid);
178 void start_apartment_listener_thread(void);
180 extern HRESULT PIPE_GetNewPipeBuf(wine_marshal_id *mid, IRpcChannelBuffer **pipebuf);
181 void RPC_StartLocalServer(REFCLSID clsid, IStream *stream);
183 /* This function initialize the Running Object Table */
184 HRESULT WINAPI RunningObjectTableImpl_Initialize(void);
186 /* This function uninitialize the Running Object Table */
187 HRESULT WINAPI RunningObjectTableImpl_UnInitialize(void);
189 /* This function decomposes a String path to a String Table containing all the elements ("\" or "subDirectory" or "Directory" or "FileName") of the path */
190 int WINAPI FileMonikerImpl_DecomposePath(LPCOLESTR str, LPOLESTR** stringTable);
193 APARTMENT *COM_CreateApartment(DWORD model);
194 APARTMENT *COM_ApartmentFromOXID(OXID oxid, BOOL ref);
195 DWORD COM_ApartmentAddRef(struct apartment *apt);
196 DWORD COM_ApartmentRelease(struct apartment *apt);
199 * Per-thread values are stored in the TEB on offset 0xF80,
200 * see http://www.microsoft.com/msj/1099/bugslayer/bugslayer1099.htm
203 /* will create if necessary */
204 static inline struct oletls *COM_CurrentInfo(void)
206 if (!NtCurrentTeb()->ReservedForOle)
207 NtCurrentTeb()->ReservedForOle = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct oletls));
209 return NtCurrentTeb()->ReservedForOle;
212 static inline APARTMENT* COM_CurrentApt(void)
214 return COM_CurrentInfo()->apt;
217 #define ICOM_THIS_MULTI(impl,field,iface) impl* const This=(impl*)((char*)(iface) - offsetof(impl,field))
219 #endif /* __WINE_OLE_COMPOBJ_H */