Exception in thread "main" java.lang.UnsatisfiedLinkError: dlltestproject.DLLTestProject.inDll()V
at dlltestproject.DLLTestProject.inDll(Native Method)
at dlltestproject.DLLTestProject.main(DLLTestProject.java:22)
Java Result: 1
我正在尝试运行 JNI 以在 W7 X64 机器上调用内置于 VS 2010 Express 的 DLL,但我总是收到上述错误。(注意:DLLTestProject.java/.class 在 dlltestproject 包下
源代码 :
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package dlltestproject;
/**
*
* @author Arhowk
*/
public class DLLTestProject {
/**
* @param args the command line arguments
*/
static{
System.loadLibrary("NewDLLTest");
}
public static void main(String[] args) {
System.out.println(System.getProperty("java.home"));
DLLTestProject t = new DLLTestProject();
t.inDll();
}
public native void inDll();
}
DLL 头文件:
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class dlltestproject_DLLTestProject */
#ifndef _Included_dlltestproject_DLLTestProject
#define _Included_dlltestproject_DLLTestProject
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: dlltestproject_DLLTestProject
* Method: inDll
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_dlltestproject_DLLTestProject_inDll
(JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#endif
DLL 源:
// NewDLLTest.cpp : Defines the exported functions for the DLL application.
//
#include "stdafx.h"
#include "NewDLLTest.h"
#include <jni.h>
#include <Windows.h>
#include <Winuser.h>
JNIEXPORT void JNICALL Java_dlltestproject_DLLTestProject_inDll(JNIEnv *env, jobject obj)
{
int msgboxID = MessageBox(
NULL,
(LPCWSTR)L"Resource not available\nDo you want to try again?",
(LPCWSTR)L"Account Details",
MB_ICONWARNING | MB_CANCELTRYCONTINUE | MB_DEFBUTTON2
);
};