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 typedef enum ifstub_state
56 IFSTUB_STATE_NORMAL_MARSHALED
,
57 IFSTUB_STATE_NORMAL_UNMARSHALED
,
58 IFSTUB_STATE_TABLE_MARSHALED
61 /* an interface stub */
64 struct list entry
; /* entry in stub_manager->ifstubs list (CS stub_manager->lock) */
65 IRpcStubBuffer
*stubbuffer
; /* RO */
68 IUnknown
*iface
; /* RO */
69 IFSTUB_STATE state
; /* CS stub_manager->lock */
73 /* stub managers hold refs on the object and each interface stub */
76 struct list entry
; /* entry in apartment stubmgr list (CS apt->cs) */
77 struct list ifstubs
; /* list of active ifstubs for the object (CS lock) */
78 CRITICAL_SECTION lock
;
79 APARTMENT
*apt
; /* owning apt (RO) */
81 ULONG extrefs
; /* number of 'external' references (LOCK) */
82 ULONG refs
; /* internal reference count (CS apt->cs) */
83 OID oid
; /* apartment-scoped unique identifier (RO) */
84 IUnknown
*object
; /* the object we are managing the stub for (RO) */
85 ULONG next_ipid
; /* currently unused (LOCK) */
88 /* imported interface proxy */
91 struct list entry
; /* entry in proxy_manager list (CS parent->cs) */
92 struct proxy_manager
*parent
; /* owning proxy_manager (RO) */
93 LPVOID iface
; /* interface pointer (RO) */
94 IID iid
; /* interface ID (RO) */
95 IPID ipid
; /* imported interface ID (RO) */
96 LPRPCPROXYBUFFER proxy
; /* interface proxy (RO) */
97 DWORD refs
; /* imported (public) references (CS parent->cs) */
100 /* imported object / proxy manager */
103 const IInternalUnknownVtbl
*lpVtbl
;
104 struct apartment
*parent
; /* owning apartment (RO) */
105 struct list entry
; /* entry in apartment (CS parent->cs) */
106 LPRPCCHANNELBUFFER chan
; /* channel to object (CS cs) */
107 OXID oxid
; /* object exported ID (RO) */
108 OID oid
; /* object ID (RO) */
109 struct list interfaces
; /* imported interfaces (CS cs) */
110 DWORD refs
; /* proxy reference count (LOCK) */
111 CRITICAL_SECTION cs
; /* thread safety for this object and children */
112 ULONG sorflags
; /* STDOBJREF flags (RO) */
113 IRemUnknown
*remunk
; /* proxy to IRemUnknown used for lifecycle management (CS cs) */
116 /* this needs to become a COM object that implements IRemUnknown */
121 DWORD refs
; /* refcount of the apartment (LOCK) */
122 DWORD model
; /* threading model (RO) */
123 DWORD tid
; /* thread id (RO) */
124 HANDLE thread
; /* thread handle (RO) */
125 OXID oxid
; /* object exporter ID (RO) */
126 DWORD ipidc
; /* interface pointer ID counter, starts at 1 (LOCK) */
127 HWND win
; /* message window (RO) */
128 CRITICAL_SECTION cs
; /* thread safety */
129 LPMESSAGEFILTER filter
; /* message filter (CS cs) */
130 struct list proxies
; /* imported objects (CS cs) */
131 struct list stubmgrs
; /* stub managers for exported objects (CS cs) */
132 BOOL remunk_exported
; /* has the IRemUnknown interface for this apartment been created yet? (CS cs) */
134 OID oidc
; /* object ID counter, starts at 1, zero is invalid OID (CS cs). FIXME: remove me */
135 DWORD listenertid
; /* id of apartment_listener_thread. FIXME: remove me */
138 /* this is what is stored in TEB->ReservedForOle */
141 struct apartment
*apt
;
142 IErrorInfo
*errorinfo
; /* see errorinfo.c */
143 IUnknown
*state
; /* see CoSetState */
144 DWORD inits
; /* number of times CoInitializeEx called */
147 extern void* StdGlobalInterfaceTable_Construct(void);
148 extern void StdGlobalInterfaceTable_Destroy(void* self
);
149 extern HRESULT
StdGlobalInterfaceTable_GetFactory(LPVOID
*ppv
);
151 /* FIXME: these shouldn't be needed, except for 16-bit functions */
152 extern HRESULT
WINE_StringFromCLSID(const CLSID
*id
,LPSTR idstr
);
153 HRESULT WINAPI
__CLSIDFromStringA(LPCSTR idstr
, CLSID
*id
);
155 extern HRESULT
create_marshalled_proxy(REFCLSID rclsid
, REFIID iid
, LPVOID
*ppv
);
157 extern void* StdGlobalInterfaceTableInstance
;
159 /* Standard Marshalling definitions */
160 typedef struct _wine_marshal_id
{
161 OXID oxid
; /* id of apartment */
162 OID oid
; /* id of stub manager */
163 IPID ipid
; /* id of interface pointer */
167 MARSHAL_Compare_Mids(wine_marshal_id
*mid1
,wine_marshal_id
*mid2
) {
169 (mid1
->oxid
== mid2
->oxid
) &&
170 (mid1
->oid
== mid2
->oid
) &&
171 IsEqualGUID(&(mid1
->ipid
),&(mid2
->ipid
))
175 HRESULT
MARSHAL_Disconnect_Proxies(APARTMENT
*apt
);
176 HRESULT
MARSHAL_GetStandardMarshalCF(LPVOID
*ppv
);
178 ULONG
stub_manager_int_addref(struct stub_manager
*This
);
179 ULONG
stub_manager_int_release(struct stub_manager
*This
);
180 struct stub_manager
*new_stub_manager(APARTMENT
*apt
, IUnknown
*object
);
181 ULONG
stub_manager_ext_addref(struct stub_manager
*m
, ULONG refs
);
182 ULONG
stub_manager_ext_release(struct stub_manager
*m
, ULONG refs
);
183 struct ifstub
*stub_manager_new_ifstub(struct stub_manager
*m
, IRpcStubBuffer
*sb
, IUnknown
*iptr
, REFIID iid
, BOOL tablemarshal
);
184 struct stub_manager
*get_stub_manager(APARTMENT
*apt
, OID oid
);
185 struct stub_manager
*get_stub_manager_from_object(APARTMENT
*apt
, void *object
);
186 BOOL
stub_manager_notify_unmarshal(struct stub_manager
*m
, const IPID
*ipid
);
187 BOOL
stub_manager_is_table_marshaled(struct stub_manager
*m
, const IPID
*ipid
);
188 HRESULT
register_ifstub(APARTMENT
*apt
, STDOBJREF
*stdobjref
, REFIID riid
, IUnknown
*obj
, MSHLFLAGS mshlflags
);
189 HRESULT
ipid_to_stub_manager(const IPID
*ipid
, APARTMENT
**stub_apt
, struct stub_manager
**stubmgr_ret
);
190 IRpcStubBuffer
*ipid_to_stubbuffer(const IPID
*ipid
);
191 HRESULT
start_apartment_remote_unknown(void);
193 IRpcStubBuffer
*mid_to_stubbuffer(wine_marshal_id
*mid
);
195 void start_apartment_listener_thread(void);
197 extern HRESULT
PIPE_GetNewPipeBuf(wine_marshal_id
*mid
, IRpcChannelBuffer
**pipebuf
);
198 void RPC_StartLocalServer(REFCLSID clsid
, IStream
*stream
);
200 /* This function initialize the Running Object Table */
201 HRESULT WINAPI
RunningObjectTableImpl_Initialize(void);
203 /* This function uninitialize the Running Object Table */
204 HRESULT WINAPI
RunningObjectTableImpl_UnInitialize(void);
206 /* This function decomposes a String path to a String Table containing all the elements ("\" or "subDirectory" or "Directory" or "FileName") of the path */
207 int WINAPI
FileMonikerImpl_DecomposePath(LPCOLESTR str
, LPOLESTR
** stringTable
);
210 APARTMENT
*COM_CreateApartment(DWORD model
);
211 APARTMENT
*COM_ApartmentFromOXID(OXID oxid
, BOOL ref
);
212 APARTMENT
*COM_ApartmentFromTID(DWORD tid
);
213 DWORD
COM_ApartmentAddRef(struct apartment
*apt
);
214 DWORD
COM_ApartmentRelease(struct apartment
*apt
);
217 * Per-thread values are stored in the TEB on offset 0xF80,
218 * see http://www.microsoft.com/msj/1099/bugslayer/bugslayer1099.htm
221 /* will create if necessary */
222 static inline struct oletls
*COM_CurrentInfo(void)
224 if (!NtCurrentTeb()->ReservedForOle
)
225 NtCurrentTeb()->ReservedForOle
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(struct oletls
));
227 return NtCurrentTeb()->ReservedForOle
;
230 static inline APARTMENT
* COM_CurrentApt(void)
232 return COM_CurrentInfo()->apt
;
235 #define ICOM_THIS_MULTI(impl,field,iface) impl* const This=(impl*)((char*)(iface) - offsetof(impl,field))
237 #endif /* __WINE_OLE_COMPOBJ_H */