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.
To use J/Direct, you must install the latest versions of the Microsoft compiler for Java (jvc) and the Microsoft VM. These are available with the latest version of the Microsoft SDK for Java. To display the version number, execute jvc with no arguments on the command line. If you are manually copying the compiler, be aware that the Microsoft compiler includes one executable and two .dll files: Jvc.exe, Jps.dll, and Msjvc.dll.
To find out what version of jvc.exe is installed using Microsoft® Windows® Explorer, find the Msjava.dll file, which is normally installed in your %Windir%\System[32] directory.
Note If the file doesn't appear, make sure Windows Explorer is configured to show all files. To do this, open the %Windir%\System[32] folder. On the View menu, select Options. Click the View tab, and then click Show all Files. Click Apply, and then click OK.
Right-click Msjava.dll. On the pop-up menu, select Properties, and then select the Version tab. The version number is displayed next to File Version.
Code samples that use J/Direct are in the %SDKDIR%\Samples\JDirect\ subdirectory of the Microsoft SDK for Java. For more information, see the J/Direct Samples Overview. For more information about other samples in this SDK, see the Samples Overview.
The com.ms.dll package helps you link your Java code with DLLs. Use the methods in these classes along with J/Direct technology to call functions located in Win32 DLLs, OLE API functions, and third-party DLLs.
This section contains the following topics:
Comparison of J/Direct, RNI, and Java/COM discusses the advantages and drawbacks of the major ways to integrate Java and native code.
Compiler Directives for J/Direct introduces the @dll.import, @dll.struct, and @dll.structmap compiler directives.
The J/Direct Message Box Example demonstrates a message box application that uses @dll.import.
Accessing the Win32 API briefly introduces the com.ms.win32 package, all or parts of which you can import to access Win32 DLL functions.
How Data Types are Marshaled discusses data type mapping between Java and C or C++, and related issues.
Invoking OLE API Functions discusses the ole modifier of the @dll.import directive.
Aliasing, or method renaming, shows how to use @dll.import with the entrypoint modifier, which allows you to use a name for a Java method that is different from the name that the DLL uses when it exports the function.
Linking by Ordinal shows how to use @dll.import with the entrypoint modifier so you can call DLLs that export functions by ordinal (a 16-bit integer).
Specifying @dll.import for an Entire Class shows how to use @dll.import prior to the class definition to set a library name for all native methods declared in that class.
Obtaining the Error Code Set By a DLL Function describes the setLastError modifier of @dll.import so you can reliably access a DLL function's error code.
Dynamically Loading and Invoking DLLs shows how to use @dll.import modifiers for more control over the loading and linking process.
J/Direct Security Issues describes how J/Direct works with the security system of the Microsoft VM.
J/Direct Error Messages lists the error and exception messages that may be thrown when you use J/Direct.
J/Direct Troubleshooting Tips offers solutions to typical problems arising in connection with J/Direct.