Creating A Component (Recap) : Interface and Process Boundary
Creating A Component (Recap) : Interface and Process Boundary
creates
returns ISprite Process 2
Sprite
Process 2 address space 0x0BAD0ADD
pISprite uses ISprite ISprite
ISprite
pFoo 0x0000ABBA
pFoo
1
Local Procedure Call (LPC) Marshaling
• LPCs are for communication between • Marshaling is, passing of parameters from
different processes on the same machine the address space of the client to the address
– single machine, inter-process communication space of the component
technique based on remote procedure call (RPC) • Local Server
• Implemented by the operating system – data in one process needs to be copied to the
– OS knows the physical addresses of the address space of the other process
corresponding logical address for each process • Remote Server
• OS can call functions in any process – data has to be put in a standard format to
account for difference between machine
EXE DLL
Client Component
Component
Interface Description Language
• IDL richly describes the interface and data
in-proc service shared by the client and the component
EXE EXE
• From Open Software Foundation’s (OSF)
process boundary
2
import " unknwn.idl" ; includes definitions from other IDL file
[
// Interface ISprite attribute list uuid(B0A0A1E2 -00EC- 11d2- 9B2C-00C04FCCA483),
[ version(1.0),
object, interface is a COM interface helpstring("Sprite1.0 For LocalServer")
uuid(B0A0A1E0 -00EC- 11d2- 9B2C-00C04FCCA483), interface IID ]
helpstring("ISprite interface"),
pointer_default(unique) how to treat pointers library SpriteTypeLibrary
] {
importlib("stdole32.tlb") ;
// Interface ISprite description MIDL requires COM interface
interface ISprite : IUnknown functions to return HRESULT // Sprite implementation
{ [
HRESULT Load( [in] char* fileName ) = 0; uuid(B0A0A1E1 -00EC- 11d2- 9B2C-00C04FCCA483), class CLSID
HRESULT SetPose( [in] int pose ) = 0; helpstring("Sprite Class For Local Server")
HRESULT SetPosition ( [in] int x, [in] int y) = 0; ]
coclass Sprite class Sprite implements the
HRESULT Draw( [in] HWND win ) = 0; { ISprite interface
}; [default ] interface ISprite;
};
[in] parameter goes from the client to the component, stub does not send information back };
All this goes into a file sprite.idl
[out] parameter goes from the component to the client , proxy does not need to marshal
• Compiles the IDL file to generate code for the Will generate,
DLL that implements proxy and stub sprite.h , guid.c, proxy.c and dlldata .c
midl sprite.idl
Generates, You provide,
sprite.h defines interfaces described in the IDL file proxy.def exporting functions for the proxy/stub DLL
sprite_i.c defines the GUIDs used in the IDL file sprite. cpp implementing the component for the
sprite_p.c implements the proxy and stub for interfaces component’s server
described in the IDL file client. cpp implementing the client
dlldata .c implements the DLL that contain the proxy and
stub code
; proxy.def file
LIBRARY proxy.dll
DESCRIPTION ’Proxy/Stub DLL' Registering the Proxy/Stub
EXPORTS
DllGetClassObject @1 PRIVATE
• Define REGISTER_PROXY_DLL for
DllCanUnloadNow @2 PRIVATE compiling files proxy.c and dlldata.c
GetProxyDllInfo @3 PRIVATE
DllRegisterServer @4 PRIVATE – code for registering proxy/stub is generated
DllUnegisterServer @5 PRIVATE
• Proxy is registered using
guids.c regsvr32 /s proxy.dll
sprite.idl midl.exe proxy.c Compiler
and
• Makes an entry into the registry indicating
dlldata.c Linker – ISprite is served by a proxy/stub
sprite.h
Building the Proxy DLL proxy.dll
– in-proc server is proxy.dll
3
Local Server implementation CoRegisterClassObject
CoCreateInstance->CoGetClassObject- >->DllGetClassObject
= IClassFactory pointer for creating components using
• CoRegisterClassObject is used by
in-proc server the local server to register class factories
• Local server is an EXE
STDAPI CoRegisterClassObject(
– cannot export functions
REFCLSID clsid , // Component class id.
– has to have a main
IUnknown* iUnknown, // Factory interface
• COM maintains a private table of registered DWORD dwClsContext, // Server context
class factories DWORD flags, // connection type
• CoGetClassObject first checks the LPDWORD ppv ); // return registration id.
4
DCOMCNFG.EXE Registry entry
• A DCOM configuration tool allows to set
HKEY_CLASSES_ROOT\
various parameters of the application CLSID\
MULTI_QI Summary
• Structure defined by DCOM to query for • IDL helps a lot in creating out-of-proc
several interfaces in one call components
typedef struct _MULTI_QI { • DCOM helps in converting local servers to
const IID* pIID, //interface id.
remote servers just by making changes in
IUnknown* pItf , //interface requested
the Registry
HRESULT hr //QueryInterface return value
} MULTI_QI;
• Remote proxy provides implementation for
an interface IMultiQI which has a
funtion QueryMultipleInterfaces