2002-03-10 00:29:33 +01: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 22:11:34 +02:00
* Copyright 2003 Ove K <EFBFBD> ven , TransGaming Technologies
2005-02-08 13:55:26 +01:00
* Copyright 2004 Mike Hearn , Rob Shearman , CodeWeavers Inc
2002-03-10 00:29:33 +01: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 14:49:52 +02:00
* Foundation , Inc . , 51 Franklin St , Fifth Floor , Boston , MA 02110 - 1301 , USA
2002-03-10 00:29:33 +01:00
*/
2000-11-25 04:08:23 +01: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-06 01:08:26 +02:00
# include <stdarg.h>
2004-12-27 20:21:47 +01:00
# include "wine/list.h"
2003-09-06 01:08:26 +02:00
# include "windef.h"
# include "winbase.h"
2000-11-25 04:08:23 +01:00
# include "wtypes.h"
2003-06-04 22:11:34 +02:00
# include "dcom.h"
2003-09-06 01:08:26 +02:00
# include "winreg.h"
2003-08-28 21:57:35 +02:00
# include "winternl.h"
2003-06-04 22:11:34 +02:00
2005-01-05 18:14:33 +01:00
struct apartment ;
2005-01-14 18:20:27 +01:00
typedef struct apartment APARTMENT ;
2005-01-05 18:14:33 +01:00
2006-06-09 21:09:49 +02: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 16:55:25 +02:00
2005-01-14 18:20:27 +01:00
/* Thread-safety Annotation Legend:
*
2005-03-17 11:26:20 +01: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 18:20:27 +01:00
*/
2005-01-17 14:39:40 +01:00
typedef enum ifstub_state
{
2005-02-18 21:03:23 +01:00
STUBSTATE_NORMAL_MARSHALED ,
STUBSTATE_NORMAL_UNMARSHALED ,
STUBSTATE_TABLE_WEAK_MARSHALED ,
STUBSTATE_TABLE_WEAK_UNMARSHALED ,
STUBSTATE_TABLE_STRONG ,
} STUB_STATE ;
2005-01-17 14:39:40 +01:00
2005-01-14 18:20:27 +01: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 13:18:45 +02:00
MSHLFLAGS flags ; /* so we can enforce process-local marshalling rules (RO) */
2006-01-10 20:08:02 +01:00
IRpcChannelBuffer * chan ; /* channel passed to IRpcStubBuffer::Invoke (RO) */
2005-01-14 18:20:27 +01:00
} ;
2004-02-10 02:36:20 +01:00
2005-01-14 18:20:27 +01: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 21:03:23 +01:00
ULONG extrefs ; /* number of 'external' references (CS lock) */
2005-01-14 18:20:27 +01: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 13:18:45 +02: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 18:20:27 +01:00
} ;
2003-06-04 22:11:34 +02:00
2005-01-04 12:58:23 +01:00
/* imported interface proxy */
struct ifproxy
{
2005-01-17 14:39:40 +01:00
struct list entry ; /* entry in proxy_manager list (CS parent->cs) */
struct proxy_manager * parent ; /* owning proxy_manager (RO) */
2005-01-14 18:20:27 +01:00
LPVOID iface ; /* interface pointer (RO) */
2005-08-27 11:25:16 +02:00
STDOBJREF stdobjref ; /* marshal data that represents this object (RO) */
2005-01-14 18:20:27 +01:00
IID iid ; /* interface ID (RO) */
LPRPCPROXYBUFFER proxy ; /* interface proxy (RO) */
2005-03-17 11:26:20 +01:00
DWORD refs ; /* imported (public) references (MUTEX parent->remoting_mutex) */
2005-03-07 18:14:11 +01:00
IRpcChannelBuffer * chan ; /* channel to object (CS parent->cs) */
2005-01-04 12:58:23 +01:00
} ;
2003-06-04 22:11:34 +02:00
2005-01-04 12:58:23 +01:00
/* imported object / proxy manager */
struct proxy_manager
{
2005-01-26 22:07:05 +01:00
const IMultiQIVtbl * lpVtbl ;
2005-08-27 11:25:16 +02:00
const IMarshalVtbl * lpVtblMarshal ;
2005-01-14 18:20:27 +01: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 13:02:54 +02:00
LONG refs ; /* proxy reference count (LOCK) */
2005-01-14 18:20:27 +01:00
CRITICAL_SECTION cs ; /* thread safety for this object and children */
2005-01-24 12:24:08 +01:00
ULONG sorflags ; /* STDOBJREF flags (RO) */
2005-01-25 11:57:24 +01:00
IRemUnknown * remunk ; /* proxy to IRemUnknown used for lifecycle management (CS cs) */
2005-03-17 11:26:20 +01:00
HANDLE remoting_mutex ; /* mutex used for synchronizing access to IRemUnknown */
2006-03-05 14:37:22 +01:00
MSHCTX dest_context ; /* context used for activating optimisations (LOCK) */
void * dest_context_data ; /* reserved context value (LOCK) */
2005-01-04 12:58:23 +01:00
} ;
2003-06-04 22:11:34 +02:00
2005-01-05 18:14:33 +01:00
/* this needs to become a COM object that implements IRemUnknown */
struct apartment
{
2006-02-20 11:15:57 +01:00
struct list entry ;
2005-01-05 18:14:33 +01:00
2005-07-05 13:02:54 +02:00
LONG refs ; /* refcount of the apartment (LOCK) */
2006-02-20 11:15:57 +01:00
BOOL multi_threaded ; /* multi-threaded or single-threaded apartment? (RO) */
2005-01-14 18:20:27 +01:00
DWORD tid ; /* thread id (RO) */
OXID oxid ; /* object exporter ID (RO) */
2005-07-05 13:02:54 +02:00
LONG ipidc ; /* interface pointer ID counter, starts at 1 (LOCK) */
2003-06-04 22:11:34 +02:00
CRITICAL_SECTION cs ; /* thread safety */
2005-01-14 18:20:27 +01:00
struct list proxies ; /* imported objects (CS cs) */
struct list stubmgrs ; /* stub managers for exported objects (CS cs) */
2005-01-25 11:57:24 +01:00
BOOL remunk_exported ; /* has the IRemUnknown interface for this apartment been created yet? (CS cs) */
2005-02-15 16:44:25 +01:00
LONG remoting_started ; /* has the RPC system been started for this apartment? (LOCK) */
2006-07-20 20:30:21 +02:00
struct list psclsids ; /* list of registered PS CLSIDs (CS cs) */
2005-01-14 18:20:27 +01:00
2005-02-15 16:44:25 +01:00
/* FIXME: OID's should be given out by RPCSS */
2005-02-08 13:55:26 +01:00
OID oidc ; /* object ID counter, starts at 1, zero is invalid OID (CS cs) */
2006-08-26 13:02:31 +02: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 18:14:33 +01:00
} ;
2003-06-04 22:11:34 +02:00
2005-01-14 18:20:27 +01: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 04:08:23 +01:00
2005-02-15 16:44:25 +01:00
/* Global Interface Table Functions */
2004-12-13 22:19:01 +01:00
extern void * StdGlobalInterfaceTable_Construct ( void ) ;
2003-06-17 05:57:18 +02:00
extern HRESULT StdGlobalInterfaceTable_GetFactory ( LPVOID * ppv ) ;
2005-02-15 16:44:25 +01:00
extern void * StdGlobalInterfaceTableInstance ;
2003-03-11 02:45:38 +01:00
2005-01-14 18:20:27 +01:00
/* FIXME: these shouldn't be needed, except for 16-bit functions */
2002-02-05 19:11:17 +01:00
extern HRESULT WINE_StringFromCLSID ( const CLSID * id , LPSTR idstr ) ;
2005-01-14 18:20:27 +01:00
2005-11-09 11:29:11 +01:00
HRESULT COM_OpenKeyForCLSID ( REFCLSID clsid , LPCWSTR keyname , REGSAM access , HKEY * key ) ;
2006-08-26 12:55:16 +02:00
HRESULT COM_OpenKeyForAppIdFromCLSID ( REFCLSID clsid , REGSAM access , HKEY * subkey ) ;
2002-02-05 19:11:17 +01:00
HRESULT MARSHAL_GetStandardMarshalCF ( LPVOID * ppv ) ;
2006-05-25 00:02:35 +02:00
HRESULT FTMarshalCF_Create ( REFIID riid , LPVOID * ppv ) ;
2002-02-05 19:11:17 +01:00
2005-02-15 16:44:25 +01:00
/* Stub Manager */
2005-01-11 11:45:34 +01:00
ULONG stub_manager_int_addref ( struct stub_manager * This ) ;
ULONG stub_manager_int_release ( struct stub_manager * This ) ;
2005-09-02 13:18:45 +02:00
struct stub_manager * new_stub_manager ( APARTMENT * apt , IUnknown * object ) ;
2005-01-11 11:45:34 +01:00
ULONG stub_manager_ext_addref ( struct stub_manager * m , ULONG refs ) ;
2006-08-03 21:24:57 +02:00
ULONG stub_manager_ext_release ( struct stub_manager * m , ULONG refs , BOOL last_unlock_releases ) ;
2005-09-02 13:18:45 +02: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 17:48:34 +01: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 13:18:45 +02: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 11:57:24 +01:00
HRESULT ipid_to_stub_manager ( const IPID * ipid , APARTMENT * * stub_apt , struct stub_manager * * stubmgr_ret ) ;
2006-01-10 20:08:02 +01:00
HRESULT ipid_get_dispatch_params ( const IPID * ipid , APARTMENT * * stub_apt , IRpcStubBuffer * * stub , IRpcChannelBuffer * * chan ) ;
2005-01-25 11:57:24 +01:00
HRESULT start_apartment_remote_unknown ( void ) ;
2004-12-27 20:21:47 +01:00
2005-03-11 11:19:10 +01:00
HRESULT marshal_object ( APARTMENT * apt , STDOBJREF * stdobjref , REFIID riid , IUnknown * obj , MSHLFLAGS mshlflags ) ;
2005-02-15 16:44:25 +01:00
/* RPC Backend */
2002-02-05 19:11:17 +01:00
2005-03-17 11:26:20 +01:00
struct dispatch_params ;
2005-02-15 16:44:25 +01:00
void RPC_StartRemoting ( struct apartment * apt ) ;
2006-03-05 14:37:34 +01:00
HRESULT RPC_CreateClientChannel ( const OXID * oxid , const IPID * ipid ,
DWORD dest_context , void * dest_context_data ,
IRpcChannelBuffer * * chan ) ;
2006-01-10 20:08:02 +01:00
HRESULT RPC_CreateServerChannel ( IRpcChannelBuffer * * chan ) ;
2005-09-14 12:07:01 +02:00
void RPC_ExecuteCall ( struct dispatch_params * params ) ;
2005-02-15 16:02:49 +01:00
HRESULT RPC_RegisterInterface ( REFIID riid ) ;
2005-02-15 16:44:25 +01: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 19:11:17 +01:00
2000-11-25 04:08:23 +01:00
/* This function initialize the Running Object Table */
2004-12-13 22:19:01 +01:00
HRESULT WINAPI RunningObjectTableImpl_Initialize ( void ) ;
2000-11-25 04:08:23 +01:00
/* This function uninitialize the Running Object Table */
2004-12-13 22:19:01 +01:00
HRESULT WINAPI RunningObjectTableImpl_UnInitialize ( void ) ;
2000-11-25 04:08:23 +01: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 11:57:21 +02:00
int FileMonikerImpl_DecomposePath ( LPCOLESTR str , LPOLESTR * * stringTable ) ;
2000-11-25 04:08:23 +01:00
2005-02-15 16:44:25 +01:00
/* Apartment Functions */
2005-03-11 11:19:10 +01: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 20:09:08 +01:00
HRESULT apartment_createwindowifneeded ( struct apartment * apt ) ;
2006-01-10 20:08:41 +01:00
HWND apartment_getwindow ( struct apartment * apt ) ;
2006-01-09 18:41:19 +01:00
void apartment_joinmta ( void ) ;
2005-01-05 18:14:33 +01:00
2005-03-17 11:26:20 +01: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 12:42:40 +02:00
# define DM_HOSTOBJECT (WM_USER + 1) /* WPARAM = 0, LPARAM = (struct host_object_params *) */
2005-02-14 12:50:51 +01:00
2003-06-04 22:11:34 +02: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 18:14:33 +01:00
/* will create if necessary */
static inline struct oletls * COM_CurrentInfo ( void )
2003-06-04 22:11:34 +02:00
{
2005-01-12 20:48:39 +01:00
if ( ! NtCurrentTeb ( ) - > ReservedForOle )
2005-01-05 18:14:33 +01:00
NtCurrentTeb ( ) - > ReservedForOle = HeapAlloc ( GetProcessHeap ( ) , HEAP_ZERO_MEMORY , sizeof ( struct oletls ) ) ;
2005-01-12 20:48:39 +01:00
2005-01-05 18:14:33 +01:00
return NtCurrentTeb ( ) - > ReservedForOle ;
2003-06-04 22:11:34 +02:00
}
2005-01-05 18:14:33 +01:00
2003-06-04 22:11:34 +02:00
static inline APARTMENT * COM_CurrentApt ( void )
2005-01-05 18:14:33 +01:00
{
return COM_CurrentInfo ( ) - > apt ;
2003-06-04 22:11:34 +02:00
}
2004-08-13 02:44:22 +02:00
# define ICOM_THIS_MULTI(impl,field,iface) impl* const This=(impl*)((char*)(iface) - offsetof(impl,field))
2005-03-17 11:26:20 +01:00
/* helpers for debugging */
2005-09-09 12:19:44 +02: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 11:26:20 +01:00
2005-05-16 16:12:53 +02:00
extern HINSTANCE OLE32_hInstance ; /* FIXME: make static */
2005-06-20 12:33:17 +02:00
# define CHARS_IN_GUID 39 /* including NULL */
2005-11-28 11:16:58 +01:00
/* Exported non-interface Data Advise Holder functions */
HRESULT DataAdviseHolder_OnConnect ( IDataAdviseHolder * iface , IDataObject * pDelegate ) ;
void DataAdviseHolder_OnDisconnect ( IDataAdviseHolder * iface ) ;
2000-11-25 04:08:23 +01:00
# endif /* __WINE_OLE_COMPOBJ_H */