1
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
    );
};
4

1 回答 1

0

知道了。

对于任何想知道的人来说,问题是将 javah 编译的头文件移动到项目中。我必须手动进入 VS2010 工作室项目并放入头文件(而不是在编辑器中复制粘贴)而不是将其包含在主 .cpp 文件中

于 2013-08-21T02:47:03.933 回答