HOWTO: Call Native (DLL) Code From Java Using JNIID: Q222092
|
This article details the process of calling native C/C++ code (in a DLL) from Java using JNI (Java Native Interface). This article presumes a working knowledge of the Visual C++ command-line compiler, CL.EXE.
public class TestJNI {
public native void greetings();
static {
System.loadLibrary("greet");
}
public static void main(String args[]) {
new TestJNI().greetings();
}
}
jvc TestJNI.java
javah -jni TestJNI
#include "TestJNI.h"
#include <stdio.h>
JNIEXPORT void JNICALL Java_TestJNI_greetings(JNIEnv *env,jobject jobj) {
printf("Hello from Visual C++!");
}
cl greet.cpp -Ic:\sdk-java.31\include -Fegreet.dll -MD -LD
jview TestJNI
Things to note:
For more information on the the legal action brought by Sun regarding Microsoft's Java agreement, visit the Java lawsuit information center.
For the latest Knowledge Base articles and other support information on Visual J++ and the SDK for Java,
please see the following pages on the Microsoft Technical Support site:
http://support.microsoft.com/support/visualj/
http://support.microsoft.com/support/java/
Additional query words:
Keywords : kbJavaVM kbJNative kbSDKJava kbVJ600 kbGrpJava
Version : WINDOWS:3.1,6.0
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: June 22, 1999