![](/img/trans.png)
[英]JNI code fails to call C function on Linux but not Windows
[英]JNI in Windows not registering function
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
);
};
得到它了。
对于任何想知道的人来说,问题在于将javah编译的头文件移至项目中。 我必须手动进入VS2010 studio项目并放入头文件(而不是将其复制粘贴到编辑器中),而不是将其包括在主.cpp文件中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.