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
);
};
答案 0 :(得分:0)
知道了。
对于任何想知道的人来说,问题是将javah编译的头文件移动到项目中。我不得不手动进入VS2010工作室项目并输入头文件(而不是将其粘贴到编辑器中),而不是将其包含在主.cpp文件中