These samples show how custom marshaling can be implemented between Java and COM. Basically, this involves the writing of a hook class to do the marshaling, and using the jactivex tool to create a Java type library file that describes the custom interface.
Suppose you have a COM library that uses various data types as parameters and return values for its methods. For these methods to be callable from Java, the data types must be converted between the COM types and Java types. For some types, like integers, floats, booleans, and strings, the Microsoft virtual machine (Microsoft VM) provides intrinsic marshaling support that does the type conversion for you.
Besides the conversion work, the COM types must be represented as Java types to be callable from Java. This requires a Java class file that contains type declarations in Java format. This class file is usually created by running a type-conversion tool such as jactivex /javatlb on the type library of the COM server. Jactivex generates the proper type mappings for all types that are supported by the intrinsic marshaling of the Microsoft VM.
The Microsoft VM, however, does not have intrinsic support for complex COM library data types such as C structures. In such cases, you will need to create a user-defined Java type and write a hook class that does the marshaling. Also, jactivex cannot automatically create type mappings that will work for user-defined types. You will need to tell jactivex how to generate the Java type declarations. You do this by creating a Java Information (.jnf) file that describes your custom data types, and passing this extra file to jactivex when it creates the COM library class header file.
The custom marshaling samples shown in the following table are provided.
Plotter | Marshals a simple structure type between a COM type library and Java. |
TemplateMarshaler | A skeleton hook class that contains C functions for eight hook methods. |
FixedPtMarshaler | Demonstrates the simplest useful hook class. |
VarStrMarshaler | Maps VARIANTs, which can have embedded resources. |
PointMarshaler | Maps non-constant Java objects. |
RectMarshaler | Demonstrates support for custom allocation. |
AnsiMarshaler | Maps variable-sized data types. |
The \Samples\Com\CustomMarshal\client directory contains the sources for a sample Java client and a C++ inproc COM server that exchange all the various types implemented by the example.
To run the sample
Change the current directory to the run location and type GO.
To build the sample client
Use Nmake.exe to compile the makefile in the \Samples\Com\CustomMarshal directory.