Microsoft SDK for Java

Native Code Samples

The Microsoft virtual machine supports the integration of Java with native code. These samples demonstrate some of ways in which Java can be integrated with native code, including using the Raw Native Interface (RNI), J/Direct, and Java/COM integration. For more information, see the following sections:

Integrating Java and COM

Integrating JavaBeans and ActiveX

Integrating Java and Win32 using J/Direct

Integrating Java and Windows using Raw Native Interface (RNI)

The following native code samples are provided.

Sample Description
Browser Applet Control Location: \Samples\Native\BrowserAppletControl

Technologies: Native code

Demonstrates:

  • Using the Microsoft® ActiveX® Browser Applet Control.

  • Creating an application in C that can host Java applets.
Debugger Location: \Samples\Debugger

Technologies: VM debugger interfaces, native code

Demonstrates:

  • How to use the debugger interfaces exposed by the Microsoft VM. The sample contains examples of creating a C++ debugger, tracing a method call, and implementing a Java debugger.
Invocation Location: \Samples\Native\Invocation

Technologies: RNI

Demonstrates:

  • Using the PrepareThreadForJava and UnprepareThreadForJava invocation APIs.

  • Using a Java object from a C application.
IPersist Location: \Samples\Com\Ipersist

Technologies: COM, native code

Demonstrates:

  • How the Microsoft virtual machine automatically exposes an IPersist interface for any Java object that implements java.io.Externalizable or java.io.Serializable. The sample uses the exposed COM persist interfaces to write the Java/COM object into a simple IStream and to a structured storage file.

  • How a C application can create an instance of a Java/COM object and use its IPersistStreamInit interface.
Java/COM Apartment Model Threading Location: \Samples\Com\JCOMApartment

Technologies: COM, native code

Demonstrates:

  • Implementing a Java/COM object with an IDL-defined interface.

  • Building a Java application that creates and uses out-of-process Java/COM objects with a custom interface.

  • Creating a C application that hosts Single-Threaded Apartment Java/COM objects.
Jexegen Location: \Samples\Native\Jexegen

Technologies: Native code, packaging

Demonstrates:

  • Packaging Java applications as executables using the jexegen tool.

  • Attaching an arbitrary native stub to a Java application to create stand-alone executables.

  • Starting the Microsoft VM using C code and running an arbitrary Java application.
JView Location: \Samples\Native\JView

Technologies: Native code

Demonstrates:

  • Creating an instance of the Microsoft VM in a C application to run Java applications.
NT Service Location: \Samples\Com\NTService

Technologies: COM, native code, J/Direct, Windows

Demonstrates:

  • Building an Microsoft® Windows NT® Service using only Java, and implementing the Service Main and Service Control as Java classes.

  • Using the Windows NT Event Log with a custom message file.
Raw Native Interface Location: \Samples\Native\Native_raw

Technologies: RNI

Demonstrates:

  • The native interface of the Microsoft VM and native code operations that are garbage-collector safe.
RNI Security Location: \Samples\Security\Rni

Technologies: Security, RNI

Demonstrates:

  • Protecting access to resources from native code.
Sample Monitor Location: \Samples\Profiler\SampMon

Technologies: Profiler, native code

Demonstrates:

  • Defining a simple implementation of several Microsoft VM event monitor interfaces.

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