IMarshal Sample

This sample is located in \Samples\Com\IMarshal.

Note   To use this sample, it is recommended that you have Microsoft® Visual C++® version 5.0 or higher installed.

Description
Using the Sample
Key Project Files
Technologies Demonstrated

Description

Marshaling Java COM Objects by Value Example

It is sometimes interesting to be able to marshal Java-implemented COM objects by value when passing Java/COM objects as parameters. This example shows how a generic class can be used to marshal any Java-implemented object or Java-implemented COM object (sample.marshal.ByValue.java). A simple generic proxy is used to unmarshal all Java and Java/COM objects that are passed by value. This proxy is registered in the client's address space through a call to sample.marshal.MarshalLib.registerProxy. Essentially this function calls CoRegisterClassObject to register a class factory for the generic proxy as an in-process server, so that COM will not need to go to the registry to create the proxy. This method also calls CoRegisterPSClsid.

The sample.server package contains the JCServer.java class, which registers a Java-implemented COM object in the running Class table, and acts as an out-of-process server for its class factory. This server hosts the JavaCOM.java COM object that will be used to illustrate the marshaling by value. It also hosts a class factory that will serve up an instance of java.util.Vector, which will be marshaled by value to the client.

The sample.marshal.* classes are generic utilities that can be used to marshal any Java object by value.

Using the Sample

To compile the sample

The Marshaling sample consists of Java classes and a proxy/stub DLL that is used for creating an instance of a Java/COM object out-of-process. This COM object is not the one that will be passed by value, but will be used to illustrate how Java/COM object methods can return objects by value.

The build process has three parts.

To build the Marshal sample, use Nmake.exe to compile the makefile in the \Samples\Com\IMarshal directory. This makefile compiles the Java files and generates the proxy/stub DLL Type the following command:

Nmake

The client and server windows will display messages indicating what the client and server code is doing. Of particular interest will be the messages outlining the marshaling process that is occurring, and the ping messages displayed from the by-reference and by-value COM object parameter.

To install the sample

Use the following command from the base directory \Samples\Com\IMarshal to register the proxy/stub DLL on the client and server computers:

regsvr32 proxystub.dll

To uninstall the sample

Use the following command from the base directory to remove the proxy/stub DLL from the registry on the client and server computers:

regsvr32 /u proxystub.dll

To run the sample

Key Project Files

sample.dcom.* classes

These generic helper classes call COM functions, Java/COM wrappers for some COM interfaces that are used, and Java implementations of the required C structures.

sample.marshal.* classes

These are generic helper classes for marshaling Java/COM objects by value.

sample.client.* classes

This is a simple command-line client that creates an instance of the served COM objects and illustrates how a client can receive Java/COM objects by value.

sample.server.* classes

This is the out-of-process COM object server that serves the Java/COM objects used in this example to illustrate marshaling by value.

sample.util.* classes

These are generic utility classes for creating an array of structures to be used in Microsoft® J/Direct™ calls.

Technologies Demonstrated

J/Direct

COM

This sample shows how to:

© 1999 Microsoft Corporation. All rights reserved. Terms of use.