Microsoft SDK for Java

J/Direct Samples

Microsoft® J/Direct™ allows you to directly call an unmodified dynamic-link library (DLL) without having to write an intermediate wrapper DLL. J/Direct provides seamless and automatic type conversion of a large set of commonly used data types, eliminating most manual type conversion.

One specific use of J/Direct is to provide Java processes with access to the Microsoft® Win32® APIs. Another use of J/Direct is to call custom APIs provided in third-party DLLs. The Microsoft virtual machine (Microsoft VM) automatically translates common Java data types to those expected by C functions. For more info, see Integrating Java and Win32 using J/Direct.

The following J/Direct samples are provided.

Sample Description
AutoMode Location: \Samples\JDirect\automode

Technologies: J/Direct

Demonstrates:

  • Using @dll.import with the auto keyword.
CdPlayer Location: \Samples\JDirect\Cdplayer

Technologies: J/Direct

Demonstrates:

  • Using @dll.import calls to the com.ms.win32.Winmm API.
CdPlay2 Location: \Samples\JDirect\Cdplay2

Technologies: J/Direct

Demonstrates:

  • Using the com.ms.win32 APIs.
Class Decoder Location: \Samples\Wfc\ClassDecoder

Technologies: WFC, AFC, COM, 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, form a local server, and form a remote client.
Cryptography Location: \Samples\Windows\Crypto

Technologies: Windows, J/Direct

Demonstrates:

  • Using the Windows Cryptography API from Java.

  • Importing Win32 API functions that use Windows error codes and mapping these to Java methods that throw com.ms.dll.Win32Exceptions.

  • Creating a custom input and output stream class.
C to Java Parser Location: \Samples\JDirect\CToJParser

Technologies: J/Direct

Demonstrates:

  • Exposing functions from DLLs and providing access to them in Java using J/Direct.
FuncPtr1 Location: \Samples\JDirect\Funcptr1

Technologies: J/Direct

Demonstrates:

  • Using @dll.import to call USER32.DLL.

  • Using Handles (hWnds) and abstract classes.
FuncPtr2 Location: \Samples\JDirect\Funcptr2

Technologies: J/Direct

Demonstrates:

  • Using the com.ms.dll.DllLib.ptrToStruct method to work around the limitation that the callback can take only integer parameters. The ptrToStruct method acts like a C-style cast.

  • Using the auto parameter of @dll.struct.
LastErr Location: \Samples\JDirect\Lasterr

Technologies: J/Direct

Demonstrates:

  • Using com.ms.dll.Win32Exception.

  • Using @dll.import.

  • Using @dll.struct.
Java and Tables Location: \Samples\ASP

Technologies: ASP, Windows, J/Direct

Demonstrates:

  • Creating an HTML table based on attributes set by the caller.
Java Media Player Location: \Samples\JDirect\mediaplayer

Technologies: JDirect

Demonstrates:

  • Calling one function (MCISendCommand) to play different media files (audio and video) for the Windows format.
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.
Pointers Location: \Samples\JDirect\Pointers

Technologies: J/Direct

Demonstrates:

  • Parsing data through a double-indirected pointer.
SDump Location: \Samples\JDirect\Sdump

Technologies: J/Direct

Demonstrates:

  • Using the Reflection API with com.ms.com.DllLib to examine the physical layout of a class declared with @dll.struct.
Simple J/Direct Sample Location: \Samples\JDirect\Simple

Technologies: J/Direct

Demonstrates:

  • Using the @dll.import J/Direct directive in code.
Strings Location: \Samples\JDirect\Strings

Technologies: J/Direct

Demonstrates:

  • Using @dll.import to read the contents of KERNEL.DLL.

  • Using the com.ms.dll.DllLib.ptrToStringAnsi method, which extracts strings from a series of concatenated strings.
Structs Location: \Samples\JDirect\Structs

Technologies: J/Direct

Demonstrates:

  • Using @dll.import and @dll.struct to read the memory contents of KERNEL.DLL and display the results.

  • Passing a pointer to a simple structure. To declare a native structure in Java, use the @dll.struct directive as shown in the MEMORYSTATUS structure in Structs.java.
TBarIcon Location: \Samples\JDirect\Tbaricon

Technologies: J/Direct, Windows

Demonstrates:

  • Using mouse events and callback classes.

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