2002-03-09 23:29:33 +00:00
/*
* Copyright 1995 Martin von Loewis
* Copyright 1998 Justin Bradford
* Copyright 1999 Francis Beaudet
* Copyright 1999 Sylvain St - Germain
* Copyright 2002 Marcus Meissner
2003-06-04 20:11:34 +00:00
* Copyright 2003 Ove K <EFBFBD> ven , TransGaming Technologies
2005-02-08 12:55:26 +00:00
* Copyright 2004 Mike Hearn , Rob Shearman , CodeWeavers Inc
2002-03-09 23:29:33 +00:00
*
* This library is free software ; you can redistribute it and / or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation ; either
* version 2.1 of the License , or ( at your option ) any later version .
*
* This library is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
* Lesser General Public License for more details .
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library ; if not , write to the Free Software
2006-05-18 12:49:52 +00:00
* Foundation , Inc . , 51 Franklin St , Fifth Floor , Boston , MA 02110 - 1301 , USA
2002-03-09 23:29:33 +00:00
*/
2000-11-25 03:08:23 +00:00
# ifndef __WINE_OLE_COMPOBJ_H
# define __WINE_OLE_COMPOBJ_H
/* All private prototype functions used by OLE will be added to this header file */
2003-09-05 23:08:26 +00:00
# include <stdarg.h>
2004-12-27 19:21:47 +00:00
# include "wine/list.h"
2003-09-05 23:08:26 +00:00
# include "windef.h"
# include "winbase.h"
2000-11-25 03:08:23 +00:00
# include "wtypes.h"
2003-06-04 20:11:34 +00:00
# include "dcom.h"
2003-09-05 23:08:26 +00:00
# include "winreg.h"
2003-08-28 19:57:35 +00:00
# include "winternl.h"
2003-06-04 20:11:34 +00:00
2005-01-05 17:14:33 +00:00
struct apartment ;
2005-01-14 17:20:27 +00:00
typedef struct apartment APARTMENT ;
2005-01-05 17:14:33 +00:00
2006-06-09 19:09:49 +00:00
DEFINE_OLEGUID ( CLSID_DfMarshal , 0x0000030b , 0 , 0 ) ;
DEFINE_OLEGUID ( CLSID_PSFactoryBuffer , 0x00000320 , 0 , 0 ) ;
DEFINE_OLEGUID ( CLSID_InProcFreeMarshaler , 0x0000033a , 0 , 0 ) ;
2006-05-08 14:55:25 +00:00
2005-01-14 17:20:27 +00:00
/* Thread-safety Annotation Legend:
*
2005-03-17 10:26:20 +00:00
* RO - The value is read only . It never changes after creation , so no
* locking is required .
* LOCK - The value is written to only using Interlocked * functions .
* CS - The value is read or written to inside a critical section .
* The identifier following " CS " is the specific critical setion that
* must be used .
* MUTEX - The value is read or written to with a mutex held .
* The identifier following " MUTEX " is the specific mutex that
* must be used .
2005-01-14 17:20:27 +00:00
*/
2005-01-17 13:39:40 +00:00
typedef enum ifstub_state
{
2005-02-18 20:03:23 +00:00
STUBSTATE_NORMAL_MARSHALED ,
STUBSTATE_NORMAL_UNMARSHALED ,
STUBSTATE_TABLE_WEAK_MARSHALED ,
STUBSTATE_TABLE_WEAK_UNMARSHALED ,
STUBSTATE_TABLE_STRONG ,
} STUB_STATE ;
2005-01-17 13:39:40 +00:00
2005-01-14 17:20:27 +00:00
/* an interface stub */
struct ifstub
{
struct list entry ; /* entry in stub_manager->ifstubs list (CS stub_manager->lock) */
IRpcStubBuffer * stubbuffer ; /* RO */
IID iid ; /* RO */
IPID ipid ; /* RO */
IUnknown * iface ; /* RO */
2005-09-02 11:18:45 +00:00
MSHLFLAGS flags ; /* so we can enforce process-local marshalling rules (RO) */
2006-01-10 19:08:02 +00:00
IRpcChannelBuffer * chan ; /* channel passed to IRpcStubBuffer::Invoke (RO) */
2005-01-14 17:20:27 +00:00
} ;
2004-02-10 01:36:20 +00:00
2005-01-14 17:20:27 +00:00
/* stub managers hold refs on the object and each interface stub */
struct stub_manager
{
struct list entry ; /* entry in apartment stubmgr list (CS apt->cs) */
struct list ifstubs ; /* list of active ifstubs for the object (CS lock) */
CRITICAL_SECTION lock ;
APARTMENT * apt ; /* owning apt (RO) */
2005-02-18 20:03:23 +00:00
ULONG extrefs ; /* number of 'external' references (CS lock) */
2005-01-14 17:20:27 +00:00
ULONG refs ; /* internal reference count (CS apt->cs) */
OID oid ; /* apartment-scoped unique identifier (RO) */
IUnknown * object ; /* the object we are managing the stub for (RO) */
ULONG next_ipid ; /* currently unused (LOCK) */
2005-09-02 11:18:45 +00:00
/* We need to keep a count of the outstanding marshals, so we can enforce the
* marshalling rules ( ie , you can only unmarshal normal marshals once ) . Note
* that these counts do NOT include unmarshalled interfaces , once a stream is
* unmarshalled and a proxy set up , this count is decremented .
*/
ULONG norm_refs ; /* refcount of normal marshals (CS lock) */
2005-01-14 17:20:27 +00:00
} ;
2003-06-04 20:11:34 +00:00
2005-01-04 11:58:23 +00:00
/* imported interface proxy */
struct ifproxy
{
2005-01-17 13:39:40 +00:00
struct list entry ; /* entry in proxy_manager list (CS parent->cs) */
struct proxy_manager * parent ; /* owning proxy_manager (RO) */
2005-01-14 17:20:27 +00:00
LPVOID iface ; /* interface pointer (RO) */
2005-08-27 09:25:16 +00:00
STDOBJREF stdobjref ; /* marshal data that represents this object (RO) */
2005-01-14 17:20:27 +00:00
IID iid ; /* interface ID (RO) */
LPRPCPROXYBUFFER proxy ; /* interface proxy (RO) */
2005-03-17 10:26:20 +00:00
DWORD refs ; /* imported (public) references (MUTEX parent->remoting_mutex) */
2005-03-07 17:14:11 +00:00
IRpcChannelBuffer * chan ; /* channel to object (CS parent->cs) */
2005-01-04 11:58:23 +00:00
} ;
2003-06-04 20:11:34 +00:00
2005-01-04 11:58:23 +00:00
/* imported object / proxy manager */
struct proxy_manager
{
2005-01-26 21:07:05 +00:00
const IMultiQIVtbl * lpVtbl ;
2005-08-27 09:25:16 +00:00
const IMarshalVtbl * lpVtblMarshal ;
2005-01-14 17:20:27 +00:00
struct apartment * parent ; /* owning apartment (RO) */
struct list entry ; /* entry in apartment (CS parent->cs) */
OXID oxid ; /* object exported ID (RO) */
OID oid ; /* object ID (RO) */
struct list interfaces ; /* imported interfaces (CS cs) */
2005-07-05 11:02:54 +00:00
LONG refs ; /* proxy reference count (LOCK) */
2005-01-14 17:20:27 +00:00
CRITICAL_SECTION cs ; /* thread safety for this object and children */
2005-01-24 11:24:08 +00:00
ULONG sorflags ; /* STDOBJREF flags (RO) */
2005-01-25 10:57:24 +00:00
IRemUnknown * remunk ; /* proxy to IRemUnknown used for lifecycle management (CS cs) */
2005-03-17 10:26:20 +00:00
HANDLE remoting_mutex ; /* mutex used for synchronizing access to IRemUnknown */
2006-03-05 13:37:22 +00:00
MSHCTX dest_context ; /* context used for activating optimisations (LOCK) */
void * dest_context_data ; /* reserved context value (LOCK) */
2005-01-04 11:58:23 +00:00
} ;
2003-06-04 20:11:34 +00:00
2005-01-05 17:14:33 +00:00
/* this needs to become a COM object that implements IRemUnknown */
struct apartment
{
2006-02-20 10:15:57 +00:00
struct list entry ;
2005-01-05 17:14:33 +00:00
2005-07-05 11:02:54 +00:00
LONG refs ; /* refcount of the apartment (LOCK) */
2006-02-20 10:15:57 +00:00
BOOL multi_threaded ; /* multi-threaded or single-threaded apartment? (RO) */
2005-01-14 17:20:27 +00:00
DWORD tid ; /* thread id (RO) */
OXID oxid ; /* object exporter ID (RO) */
2005-07-05 11:02:54 +00:00
LONG ipidc ; /* interface pointer ID counter, starts at 1 (LOCK) */
2003-06-04 20:11:34 +00:00
CRITICAL_SECTION cs ; /* thread safety */
2005-01-14 17:20:27 +00:00
struct list proxies ; /* imported objects (CS cs) */
struct list stubmgrs ; /* stub managers for exported objects (CS cs) */
2005-01-25 10:57:24 +00:00
BOOL remunk_exported ; /* has the IRemUnknown interface for this apartment been created yet? (CS cs) */
2005-02-15 15:44:25 +00:00
LONG remoting_started ; /* has the RPC system been started for this apartment? (LOCK) */
2006-07-20 18:30:21 +00:00
struct list psclsids ; /* list of registered PS CLSIDs (CS cs) */
2005-01-14 17:20:27 +00:00
2005-02-15 15:44:25 +00:00
/* FIXME: OID's should be given out by RPCSS */
2005-02-08 12:55:26 +00:00
OID oidc ; /* object ID counter, starts at 1, zero is invalid OID (CS cs) */
2006-08-26 11:02:31 +00:00
/* STA-only fields */
HWND win ; /* message window (LOCK) */
LPMESSAGEFILTER filter ; /* message filter (CS cs) */
BOOL main ; /* is this a main-threaded-apartment? (RO) */
2005-01-05 17:14:33 +00:00
} ;
2003-06-04 20:11:34 +00:00
2005-01-14 17:20:27 +00:00
/* this is what is stored in TEB->ReservedForOle */
struct oletls
{
struct apartment * apt ;
IErrorInfo * errorinfo ; /* see errorinfo.c */
IUnknown * state ; /* see CoSetState */
DWORD inits ; /* number of times CoInitializeEx called */
} ;
2000-11-25 03:08:23 +00:00
2005-02-15 15:44:25 +00:00
/* Global Interface Table Functions */
2004-12-13 21:19:01 +00:00
extern void * StdGlobalInterfaceTable_Construct ( void ) ;
2003-06-17 03:57:18 +00:00
extern HRESULT StdGlobalInterfaceTable_GetFactory ( LPVOID * ppv ) ;
2005-02-15 15:44:25 +00:00
extern void * StdGlobalInterfaceTableInstance ;
2003-03-11 01:45:38 +00:00
2005-01-14 17:20:27 +00:00
/* FIXME: these shouldn't be needed, except for 16-bit functions */
2002-02-05 18:11:17 +00:00
extern HRESULT WINE_StringFromCLSID ( const CLSID * id , LPSTR idstr ) ;
2005-01-14 17:20:27 +00:00
2005-11-09 10:29:11 +00:00
HRESULT COM_OpenKeyForCLSID ( REFCLSID clsid , LPCWSTR keyname , REGSAM access , HKEY * key ) ;
2006-08-26 10:55:16 +00:00
HRESULT COM_OpenKeyForAppIdFromCLSID ( REFCLSID clsid , REGSAM access , HKEY * subkey ) ;
2002-02-05 18:11:17 +00:00
HRESULT MARSHAL_GetStandardMarshalCF ( LPVOID * ppv ) ;
2006-05-24 22:02:35 +00:00
HRESULT FTMarshalCF_Create ( REFIID riid , LPVOID * ppv ) ;
2002-02-05 18:11:17 +00:00
2005-02-15 15:44:25 +00:00
/* Stub Manager */
2005-01-11 10:45:34 +00:00
ULONG stub_manager_int_addref ( struct stub_manager * This ) ;
ULONG stub_manager_int_release ( struct stub_manager * This ) ;
2005-09-02 11:18:45 +00:00
struct stub_manager * new_stub_manager ( APARTMENT * apt , IUnknown * object ) ;
2005-01-11 10:45:34 +00:00
ULONG stub_manager_ext_addref ( struct stub_manager * m , ULONG refs ) ;
2006-08-03 19:24:57 +00:00
ULONG stub_manager_ext_release ( struct stub_manager * m , ULONG refs , BOOL last_unlock_releases ) ;
2005-09-02 11:18:45 +00:00
struct ifstub * stub_manager_new_ifstub ( struct stub_manager * m , IRpcStubBuffer * sb , IUnknown * iptr , REFIID iid , MSHLFLAGS flags ) ;
struct ifstub * stub_manager_find_ifstub ( struct stub_manager * m , REFIID iid , MSHLFLAGS flags ) ;
2005-01-14 16:48:34 +00:00
struct stub_manager * get_stub_manager ( APARTMENT * apt , OID oid ) ;
struct stub_manager * get_stub_manager_from_object ( APARTMENT * apt , void * object ) ;
2005-09-02 11:18:45 +00:00
BOOL stub_manager_notify_unmarshal ( struct stub_manager * m , const IPID * ipid ) ;
BOOL stub_manager_is_table_marshaled ( struct stub_manager * m , const IPID * ipid ) ;
void stub_manager_release_marshal_data ( struct stub_manager * m , ULONG refs , const IPID * ipid ) ;
2005-01-25 10:57:24 +00:00
HRESULT ipid_to_stub_manager ( const IPID * ipid , APARTMENT * * stub_apt , struct stub_manager * * stubmgr_ret ) ;
2006-01-10 19:08:02 +00:00
HRESULT ipid_get_dispatch_params ( const IPID * ipid , APARTMENT * * stub_apt , IRpcStubBuffer * * stub , IRpcChannelBuffer * * chan ) ;
2005-01-25 10:57:24 +00:00
HRESULT start_apartment_remote_unknown ( void ) ;
2004-12-27 19:21:47 +00:00
2005-03-11 10:19:10 +00:00
HRESULT marshal_object ( APARTMENT * apt , STDOBJREF * stdobjref , REFIID riid , IUnknown * obj , MSHLFLAGS mshlflags ) ;
2005-02-15 15:44:25 +00:00
/* RPC Backend */
2002-02-05 18:11:17 +00:00
2005-03-17 10:26:20 +00:00
struct dispatch_params ;
2005-02-15 15:44:25 +00:00
void RPC_StartRemoting ( struct apartment * apt ) ;
2006-03-05 13:37:34 +00:00
HRESULT RPC_CreateClientChannel ( const OXID * oxid , const IPID * ipid ,
DWORD dest_context , void * dest_context_data ,
IRpcChannelBuffer * * chan ) ;
2006-01-10 19:08:02 +00:00
HRESULT RPC_CreateServerChannel ( IRpcChannelBuffer * * chan ) ;
2005-09-14 10:07:01 +00:00
void RPC_ExecuteCall ( struct dispatch_params * params ) ;
2005-02-15 15:02:49 +00:00
HRESULT RPC_RegisterInterface ( REFIID riid ) ;
2005-02-15 15:44:25 +00:00
void RPC_UnregisterInterface ( REFIID riid ) ;
void RPC_StartLocalServer ( REFCLSID clsid , IStream * stream ) ;
HRESULT RPC_GetLocalClassObject ( REFCLSID rclsid , REFIID iid , LPVOID * ppv ) ;
2002-02-05 18:11:17 +00:00
2000-11-25 03:08:23 +00:00
/* This function initialize the Running Object Table */
2004-12-13 21:19:01 +00:00
HRESULT WINAPI RunningObjectTableImpl_Initialize ( void ) ;
2000-11-25 03:08:23 +00:00
/* This function uninitialize the Running Object Table */
2004-12-13 21:19:01 +00:00
HRESULT WINAPI RunningObjectTableImpl_UnInitialize ( void ) ;
2000-11-25 03:08:23 +00:00
/* This function decomposes a String path to a String Table containing all the elements ("\" or "subDirectory" or "Directory" or "FileName") of the path */
2005-05-12 09:57:21 +00:00
int FileMonikerImpl_DecomposePath ( LPCOLESTR str , LPOLESTR * * stringTable ) ;
2000-11-25 03:08:23 +00:00
2005-02-15 15:44:25 +00:00
/* Apartment Functions */
2005-03-11 10:19:10 +00:00
APARTMENT * apartment_findfromoxid ( OXID oxid , BOOL ref ) ;
APARTMENT * apartment_findfromtid ( DWORD tid ) ;
DWORD apartment_addref ( struct apartment * apt ) ;
DWORD apartment_release ( struct apartment * apt ) ;
HRESULT apartment_disconnectproxies ( struct apartment * apt ) ;
void apartment_disconnectobject ( struct apartment * apt , void * object ) ;
static inline HRESULT apartment_getoxid ( struct apartment * apt , OXID * oxid )
{
* oxid = apt - > oxid ;
return S_OK ;
}
2006-01-10 19:09:08 +00:00
HRESULT apartment_createwindowifneeded ( struct apartment * apt ) ;
2006-01-10 19:08:41 +00:00
HWND apartment_getwindow ( struct apartment * apt ) ;
2006-01-09 17:41:19 +00:00
void apartment_joinmta ( void ) ;
2005-01-05 17:14:33 +00:00
2005-03-17 10:26:20 +00:00
/* DCOM messages used by the apartment window (not compatible with native) */
# define DM_EXECUTERPC (WM_USER + 0) /* WPARAM = 0, LPARAM = (struct dispatch_params *) */
2006-08-26 10:42:40 +00:00
# define DM_HOSTOBJECT (WM_USER + 1) /* WPARAM = 0, LPARAM = (struct host_object_params *) */
2005-02-14 11:50:51 +00:00
2003-06-04 20:11:34 +00:00
/*
* Per - thread values are stored in the TEB on offset 0xF80 ,
* see http : //www.microsoft.com/msj/1099/bugslayer/bugslayer1099.htm
*/
2005-01-05 17:14:33 +00:00
/* will create if necessary */
static inline struct oletls * COM_CurrentInfo ( void )
2003-06-04 20:11:34 +00:00
{
2005-01-12 19:48:39 +00:00
if ( ! NtCurrentTeb ( ) - > ReservedForOle )
2005-01-05 17:14:33 +00:00
NtCurrentTeb ( ) - > ReservedForOle = HeapAlloc ( GetProcessHeap ( ) , HEAP_ZERO_MEMORY , sizeof ( struct oletls ) ) ;
2005-01-12 19:48:39 +00:00
2005-01-05 17:14:33 +00:00
return NtCurrentTeb ( ) - > ReservedForOle ;
2003-06-04 20:11:34 +00:00
}
2005-01-05 17:14:33 +00:00
2003-06-04 20:11:34 +00:00
static inline APARTMENT * COM_CurrentApt ( void )
2005-01-05 17:14:33 +00:00
{
return COM_CurrentInfo ( ) - > apt ;
2003-06-04 20:11:34 +00:00
}
2004-08-13 00:44:22 +00:00
# define ICOM_THIS_MULTI(impl,field,iface) impl* const This=(impl*)((char*)(iface) - offsetof(impl,field))
2005-03-17 10:26:20 +00:00
/* helpers for debugging */
2005-09-09 10:19:44 +00:00
# define DEBUG_SET_CRITSEC_NAME(cs, name) (cs)->DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": " name)
# define DEBUG_CLEAR_CRITSEC_NAME(cs) (cs)->DebugInfo->Spare[0] = 0
2005-03-17 10:26:20 +00:00
2005-05-16 14:12:53 +00:00
extern HINSTANCE OLE32_hInstance ; /* FIXME: make static */
2005-06-20 10:33:17 +00:00
# define CHARS_IN_GUID 39 /* including NULL */
2005-11-28 10:16:58 +00:00
/* Exported non-interface Data Advise Holder functions */
HRESULT DataAdviseHolder_OnConnect ( IDataAdviseHolder * iface , IDataObject * pDelegate ) ;
void DataAdviseHolder_OnDisconnect ( IDataAdviseHolder * iface ) ;
2000-11-25 03:08:23 +00:00
# endif /* __WINE_OLE_COMPOBJ_H */