Microsoft SDK for Java

COM Samples

Java/COM integration lets you combine Java's advantages with COM and develop components that can interact with operating systems, applications, and services written in any COM-compliant language on any platform.

Most of the Microsoft® Windows® functionality is exposed through COM, and most Microsoft applications provide COM interfaces to their object models. At the same time, Java offers automatic garbage collection and replaces pointers with references, while the Microsoft virtual machine (Microsoft VM) automatically handles object references, cleanup, and interface queries for any COM object used in Java, whether the component was written in Java or another COM-compliant language.

The Microsoft VM also provides automatic mapping, allowing a Java object to be a COM object, and allowing any COM object to be accessible as a Java object. For more information, see Integrating Java and COM.

The following COM samples are provided.

Sample Description
Class Decoder Location: \Samples\Wfc\ClassDecoder

Technologies: WFC, AFC, COM, Microsoft® J/Direct™

Demonstrates:

  • Building a WFC application.

  • Decoding Java class files into the attributes, structures, and properties that make up the class.
CoCreateInstanceEx Location: \Samples\Com\CCIEx

Technologies: COM, DCOM, J/Direct

Demonstrates:

  • Implementing a Java/COM object with custom IDL-defined interfaces.

  • Implementing a Java client application that uses a J/Direct call to CoCreateInstanceEx to create instances of an in-process COM object from a local server and from a remote client.
COM Location: \Samples\Com\Com

Technologies: COM

Demonstrates:

  • Implementing a simple Java/COM object and register it using javareg.

  • Using jactivex with a type library to generate Java wrappers and use them in a Java application.
COM Class Object Location: \Samples\Com\ComClassObject

Technologies: COM

Demonstrates:

  • Implementing a COM class object and a small class client that co-creates the object through the same Java implemented interface.
COM iid_is and size_is Location: \Samples\Com\iid_is_size_is

Technologies: COM, Jactivex

Demonstrates:

  • Creating an interface that uses the new iid_iis and size_is marshaling support of the 32xx series Microsoft VM and jactivex.
COM Security Location: \Samples\Com\Security_com

Technologies: COM, security

Demonstrates:

  • Implementing Call security on a Java/COM object using the com.ms.security package.

  • Implementing a Java/COM object with a custom interface.

  • Implementing a C COM object with a custom interface.

  • Defining a custom interface in IDL.
Custom Marshaling Location: \Samples\Com\CustomMarshal

Technologies: COM, custom marshaling

Demonstrates:

  • Implementing custom marshaling between Java and COM.

  • Marshaling simple structure types, variable-sized data, VARIANTs, and mutable Java objects.

  • Using hook classes.

  • Custom allocation support.
Dispatch Location: \Samples\Com\Dispatch

Technologies: COM

Demonstrates:

  • Implementing and registering a simple Java/COM object.

  • Creating an instance of Java/COM object using CoCreateInstanceEx from a J/Direct call.

  • Invoking methods on a COM object using its IDispatch interface through the com.ms.com.Dispatch class.
IMarshal Location: \Samples\Com\IMarshal

Technologies: COM, J/Direct

Demonstrates:

  • Using Java-implemented structures, arrays of structures, and embedded structures.

  • Implementing the IMarshal interface on a Java/COM object.

  • Creating a COM server in Java by creating a Java/COM object that implements IClassFactory.

  • Implementing a COM proxy object in Java that can be used by a client without registry settings.
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.
Java/COM Communications Location: \Samples\Com\Native_com

Technologies: COM, native code

Demonstrates:

  • Java-COM and COM-Java communications

  • Java-Callable Wrappers

  • COM-Callable Wrappers
Java/COM DLL Stub Location: \Samples\Com\Jexegen\Stub

Technologies: Jexegen

Demonstrates:

  • Creating a DLL and implementing a component in that DLL.
Raw Native Interface Location: \Samples\Native\Native_raw

Technologies: Native interface, COM

Demonstrates:

  • The native interface of the Microsoft VM and native code operations that are garbage-collector safe.
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.
OleMode Location: \Samples\JDirect\olemode

Technologies: J/Direct, COM

Demonstrates:

  • Using @dll.import with the ole keyword.
SafeArray Location: \Samples\Com\SafeArray

Technologies: COM, J/Direct

Demonstrates:

  • Using @com directives with CLSIDs and IIDs.

  • How to create a SafeArray in Java, pass it to a COM server written in Visual Basic, inspect the SafeArray when returned from a COM server, and extract all or some of its elements.
Variant SafeArray Location: \Samples\Com\VariantSafeArray

Technologies: COM

Demonstrates:

  • Passing Variants and SafeArrays of data between a Microsoft® Visual Basic® COM component and a Java application.

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