|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.jinvoke.JInvoke
public class JInvoke
Initializes the J/Invoke runtime for each class importing native methods.
| Method Summary | |
|---|---|
static void |
initialize()
Initializes all native methods in the caller's class and makes them ready to be called using J/Invoke. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static void initialize()
This method must be called once in each class before any native methods marked with the
@NativeImport annotation is called.
This method binds the native methods annotated with the @NativeImport annotation to the
specified exported function in the specified native library (.dll or .so).
A convenient place to call this method is in the static initializer of each class containing @NativeImport annotated native methods.
Example:
The following class declares some native methods and calls JInvoke.initialize()
from it's static initializer
import com.jinvoke.JInvoke;
import com.jinvoke.NativeImport;
public class User32 {
static {
JInvoke.initialize();
}
@NativeImport(library="User32")
public native static int ActivateKeyboardLayout (int hkl, int Flags);
@NativeImport(library="User32")
public native static boolean AdjustWindowRect (Rect lpRect, int dwStyle, boolean bMenu);
// other methods imported from User32.dll
}
Alternatively, this method can also be called any time prior to 'J/Invoking' a native method, as shown in the example below:
import com.jinvoke.JInvoke;
import com.jinvoke.NativeImport;
public class Example {
@NativeImport(library="User32.dll")
public static native int MessageBox(int hwnd, String text, String caption, int type);
public static void main(String[] args) {
JInvoke.initialize();
MessageBox(0, "This MessageBox is a native Win32 MessageBox", "Caption", 0);
}
}
An UnsatisfiedLinkError will be thrown if a native method (annotated with @NativeImport annotation)
is called prior to initializing the containing class using this method.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||