public class Test { static { System.loadLibrary("testdll");/* testdll为dll名 */ } public native int SetComm1(); /*dll提供 */ public native int SetComm2(); /*dll提供 */
public class SysSetup { static { System.loadLibrary("C:\Lotus\Domino\Data\SJ_KM\DLL\DllSendSms.dll");/* testdll为dll名 */ } public native int Connect(); /*dll提供 */ /*dll提供 */
}oadLibrary出错
DllSendSms.dll有没有用到JNI?方法: step1.写.java文件,格式为: public class Test { static { System.loadLibrary("testdll");/* testdll为dll名 */ } public native int func1(); /*dll提供 */ public native int func2(); /*dll提供 */ ... step2.编译.java文件 step3.用javah -jni 你的类 生成.h文件 step4.在vc(或c++/C,以vc为例创建mfc dll) 中加入该.h文件 step5.比如VC的工程名为mypro,那么在mypro.h后面(不是.cpp)中写 public native int func1(); /*dll提供 */ public native int func2(); /*dll提供 */ 的实现代码,格式为: JNIEXPORT jint JNICALL Java_test_func1(JNIEnv* env,jobject obj) { //..........你要实现的代码 } JNIEXPORT jint JNICALL Java_test_func2(JNIEnv* env,jobject obj) { //..........你要实现的代码 } step6.编译mypro step7.把mypro.dll拷到path目录下 step8.运行你的java程序吧
static {
System.loadLibrary("testdll");/* testdll为dll名 */
} public native int SetComm1(); /*dll提供 */
public native int SetComm2(); /*dll提供 */
一个例子,希望 对你有帮助
static {
System.loadLibrary("C:\Lotus\Domino\Data\SJ_KM\DLL\DllSendSms.dll");/* testdll为dll名 */
} public native int Connect(); /*dll提供 */
/*dll提供 */
}oadLibrary出错
step1.写.java文件,格式为:
public class Test {
static {
System.loadLibrary("testdll");/* testdll为dll名 */
} public native int func1(); /*dll提供 */
public native int func2(); /*dll提供 */
...
step2.编译.java文件
step3.用javah -jni 你的类 生成.h文件
step4.在vc(或c++/C,以vc为例创建mfc dll) 中加入该.h文件
step5.比如VC的工程名为mypro,那么在mypro.h后面(不是.cpp)中写
public native int func1(); /*dll提供 */
public native int func2(); /*dll提供 */
的实现代码,格式为:
JNIEXPORT jint JNICALL Java_test_func1(JNIEnv* env,jobject obj) {
//..........你要实现的代码
}
JNIEXPORT jint JNICALL Java_test_func2(JNIEnv* env,jobject obj) {
//..........你要实现的代码
}
step6.编译mypro
step7.把mypro.dll拷到path目录下
step8.运行你的java程序吧
跟普通VJ,JB都不一样阿!