|< BACK  NEXT >|
An interface can be marshaled using either the MIDL-generated code or by writing explicit marshaling code.
Marshaling based on MIDL-generated code is referred to as standard marshaling.
In some circumstances, the developers may wish to write their own marshaling code. Marshaling based on such code is referred to as custom marshaling. For most cases, however, standard marshaling is very performance-efficient.
Standard marshaling could be driven by either the MIDL-generated proxy/stub code or by the MIDL-generated type library.
The proxy/stub code has to be compiled and linked to create the proxy/stub DLL. This DLL acts as a COM server and has to be registered on both the client and the server machine. COM provides a tool called regsvr32.exe that can be used to register or unregister a COM server DLL, as follows:
regsvr32.exe myproxystub.dll // Register the proxy/stub on the // local machine regsvr32.exe u myproxystub.dll // Unregister it
Building a proxy/stub DLL requires some specific compiler switches, a module definition file, and some specific libraries to link with. If you use ATL to create a COM server project, ATL will generate the module definition file and a makefile to build a proxy/stub DLL. If you are not using ATL or if you just want to create proxy/stub DLL for interfaces in a specific IDL file, you can use the CreatePS utility I have put on the accompanying CD. This utility generates the module definition file and the makefile to create a proxy/stub DLL, similar to what ATL does.
If type-library-driven marshaling is desired for an interface, the parameters in the interface methods are restricted to use automation-compatible type. In addition, the interface should be marked as either oleautomation or dual. The type library has to be registered on both the client and the server machine. The SDK provides an API, LoadTypeLibEx, that can be used to register a type library. If you are using ATL, the wizard generates the registration code for you.
The infrastructure that is responsible for carrying out type-library marshaling is referred to as the universal marshaler. It is currently implemented in OLEAUT32.DLL, a DLL supplied by COM.
It is important to understand that marshaling happens on the interface level, not on the object level. An object may support many interfaces. Each interface may have its own marshaling mechanism.
Also note that an interface cannot have more than one marshaling mechanism.
To marshal an interface, register only one entity either its proxy/stub DLL or its type-library. If you register both, the behavior is unpredictable.
|< BACK  NEXT >|