Java/COM Communications Sample

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

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

This sample demonstrates Java/COM and COM/Java communications. The sample is invoked from Java. The constructor of the class we invoke instantiates a COM-implemented object. Three methods are then exercised.

The first two methods take and return numeric arguments. The third method instantiates a Java-implemented object, and passes the interface pointer back to Java, caching a local copy for its own use later on. The new Java object is then transparently used from both Java and COM. That is, the COM object treats it no differently than any other COM object, and Java treats it as a Java object.

Using the Sample

To compile the sample

The executable files that are built from this sample are included; you do not need to build the sample to run it. However, the following information shows how to build the sample yourself.

  1. Dependencies are Jvc.exe, Cpdbase.dll, Msjvc.dll, Jactivex.exe, and Javareg.exe.

    These are included in the %SDKDIR%\Bin directory.

  2. Use Nmake.exe to compile the makefile in the \Samples\Com\Native_com directory. Type the following command:

    Nmake

To run the sample

Run Go.bat, which does the following:

The output in the console window is as follows:

2 * 5 = 10
inc.Square(10) = 100
invoked from COM: Hello World
invoked from Java: Hello World

Key Project Files

JMain.java

This class demonstrates the implementation of Java-callable wrappers (JCWs) and COM-callable wrappers (CCWs).

JMain.java

This class implements the jcNatComImpl interface as a COM-callable wrapper (CCW).

Technologies Demonstrated

Java/COM

This sample shows how to use:

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