These samples demonstrate how to use the new @dll.import directive that allows quick and easy access to functions exported from DLLs (Dynamic Link Libraries).
To execute a sample, go to any subdirectory and run the "go.bat" batch file. It is recommended you run the "Simple" sample first. For simplicity, all of the samples are written as console-mode Java applications that execute under "jview". Therefore, it is best to execute "go.bat" from a command-line window (COMMAND.COM under Windows 95, CMD.EXE under NT).
These samples are located in the subdirectories of "[SDKRoot]\Samples\JDirect".
Simple Samples
Simple |
The "Hello World" J/Direct application - use to ensure J/Direct is correctly installed. |
Strings |
Demonstrates passing and receiving strings from DLL's. |
Structs |
Demonstrates how to represent a C structure using J/Direct. |
SDump |
Displays layout of any J/Direct structure - handy for debugging. |
FuncPtr1 |
Shows how to simulate a function pointer using J/Direct. |
FuncPtr2 |
A more complex function pointer example. |
Pointers |
Shows how to emulate pointer operations using J/Direct. |
LastErr |
Shows how to capture error codes from Windows api. |
AutoMode |
Shows how to use automatic character-size selection for optimal performance. |
OleMode |
Shows special features designed for calling Ole api. |
Advanced Samples
CdPlayer |
An Audio CD player application using the MCI device interface. |
CdPlay2 |
An Audio CD player application using the MCI device interface through the
Win32 API classes for J/Direct. |
TBarIcon |
Displays and captures mouse messages from a TaskBar notification icon. |
In order for the below code to work, it needs the com.ms.win32 package, which is included with the Win32 API classes for J/Direct.
/* Copyright (C) 1997 Microsoft Corporation. All rights reserved.
*
* This example calls the MessageBox api using the new @dll.import
* directive.
*
*/
import com.ms.win32.*;
public class Simple
{
public static void main(String args[])
{
try {
User32.MessageBox(0, "MessageBox successfully called.", "Java", 0);
} catch (UnsatisfiedLinkError ule) {
System.err.println("Caught exception: " + ule);
System.err.println("Probably wrong version of Java compiler.");
}
}
}