簡體   English   中英

Windows中的JNI無法注冊功能

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM