In order for COM to correctly marshal and unmarshal parameters, it must know the exact method signature, including all data types, types of structure members, and sizes of any arrays in the parameter list. Java can implement custom interfaces that contain methods for passing standard Automation data types, as well as structures, custom data types, and COM objects. You implement custom interfaces in a COM object by defining the object and all of its interfaces using IDL, and then compiling it with a MIDL compiler. The Microsoft-provided MIDL compiler is Midl.exe, available in the Platform SDK on the MSDN Library and with Microsoft® Visual C++®.
The MIDL compiler takes the .idl file as input and generates a type library (.tlb file) and some C code that implements a proxy and a stub for the custom object.
Java classes that represent the custom interfaces and the custom object can be generated using Jactivex. Jactivex takes any standard type library file and generates corresponding .java files for the COM objects, interfaces, and structures defined in the type library. These Java files contain the correct @com directives for specifying the .java files as Java-Callable Wrappers (JCWs). Clients can use the COM object remotely through the IDispatch interface with only the type library installed on the client and server machines. In this case, no proxy/stub is required.
A simple .tlb file can be generated for Java developed COM components using javareg. In order to customize the type library, or to generate the proxy/stub code required for using custom interfaces from the Java COM object remotely, an IDL-defined interface is required. Once a type library file has been created (either through using MIDL to compile an IDL file, or from javareg) jactivex tool can be run on the type library to generate Java COM wrapper classes that represent the interfaces and the COM object. These classes can simply be imported into a Java project and used like any other Java class.
To create a COM interface
Use ComLib.ptrRelease to release a reference on the interface, given a raw COM interface pointer.
Use ComLib.ptrToUnknown to map a raw pointer to a Java-callable wrapper.
Finally, explicitly call ComLib.release to release all outstanding reference counts on the com.IStream objects before returning from the com.IMarshal methods that have an IStream parameter.