Writing Windows-Based Applications with J/Direct
J/Direct is a new feature of Microsoft Visual J++ that provides easy access to Microsoft Windows dynamic-link libraries (DLLs). Using J/Direct, you can make direct calls to standard Win32 system DLLs (such as KERNEL32 and USER32) and third-party DLLs. J/Direct is far simpler to use than the older Raw Native Interface or the Java Native Interface (known as RNI and JNI, respectively), both of which require you to write a specialized wrapper DLL and perform all non-trivial data type translations yourself. With J/Direct, the vast majority of pre-existing DLL functions can be invoked by simply declaring the function and calling it. J/Direct uses the @dll.import directive, which is similar to Visual Basic's DECLARE facility.
To use J/Direct, you need to have installed Microsoft Visual J++ and Microsoft Internet Explorer, version 4.0 or higher. To quickly build applications that take advantage of the native power of J/Direct, use the J/Direct Call Builder, which is a part of the Visual J++ development environment.
This section explains how to use the @dll.import directive to invoke a DLL function from Java. It also offers details about how each data type is passed and received, and describes how the @dll.struct directive is used to pass and receive structures from DLL methods.
For more information on writing Windows-based applications with J/Direct, see:
- Message Box Example
- J/Direct Call Builder
- Quick Syntax Reference
- How Data Types are Marshaled
- Invoking OLE API Functions
- Aliasing (Method Renaming)
- Linking by Ordinal
- Specifying @dll.import for an Entire Class
- How the VM Chooses Between ANSI and Unicode
- Obtaining the Error Code Set By a DLL Function
- Dynamically Loading and Invoking DLLs
- Comparing J/Direct to Raw Native Interface
- Security Issues
- Error Messages
- Troubleshooting Tips