Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java JNI Java.lang.UnsatisfiedLinkError在DLL中使用GetaSyncKeyState_Java_C++_Java Native Interface_Unsatisfiedlinkerror - Fatal编程技术网

Java JNI Java.lang.UnsatisfiedLinkError在DLL中使用GetaSyncKeyState

Java JNI Java.lang.UnsatisfiedLinkError在DLL中使用GetaSyncKeyState,java,c++,java-native-interface,unsatisfiedlinkerror,Java,C++,Java Native Interface,Unsatisfiedlinkerror,我的问题如下。我对C/C++代码相当陌生,我有一种感觉,我使用了不正确的东西,或者没有使用需要的东西。虽然我做了一个测试应用程序,看看dll代码是否执行,它是否执行。我在谷歌上搜索了很多,但似乎找不到任何相关内容。如果我还需要解释什么,请告诉我。这是我的第一篇帖子,顺便说一句,我一直在使用这个网站,尽管它很棒 Java代码返回错误: Exception in thread "Thread-2" java.lang.UnsatisfiedLinkError: ghostclickerredux.G

我的问题如下。我对C/C++代码相当陌生,我有一种感觉,我使用了不正确的东西,或者没有使用需要的东西。虽然我做了一个测试应用程序,看看dll代码是否执行,它是否执行。我在谷歌上搜索了很多,但似乎找不到任何相关内容。如果我还需要解释什么,请告诉我。这是我的第一篇帖子,顺便说一句,我一直在使用这个网站,尽管它很棒

Java代码返回错误:

Exception in thread "Thread-2" java.lang.UnsatisfiedLinkError: ghostclickerredux.GlobbyMouse.whatButton()I
下面的所有代码都是java代码,包含在实现runnable接口的类中。线程启动并将执行循环,只要。。。剩下的就交给你吧。如果我评论gM.whatButton()行,一切正常

boolean recording = true;
do {
    if(xT != gM.getMouseX() || yT != gM.getMouseY()){
        xT = gM.getMouseX(); // This Works.
        yT = gM.getMouseY(); // This Works.
        System.out.println("Mouse X: " + xT + " Y: " + yT); // This Works.
        System.out.println(gM.whatButton()); // This throws me the error.
    }
} while (recording);
下面是javah创建的头文件

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class ghostclickerredux_GlobbyMouse */

#ifndef _Included_ghostclickerredux_GlobbyMouse
#define _Included_ghostclickerredux_GlobbyMouse
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     ghostclickerredux_GlobbyMouse
 * Method:    getMouseX
 * Signature: ()I
 */
JNIEXPORT jint JNICALL Java_ghostclickerredux_GlobbyMouse_getMouseX
  (JNIEnv *, jobject);

/*
 * Class:     ghostclickerredux_GlobbyMouse
 * Method:    getMouseY
 * Signature: ()I
 */
JNIEXPORT jint JNICALL Java_ghostclickerredux_GlobbyMouse_getMouseY
  (JNIEnv *, jobject);

/*
 * Class:     ghostclickerredux_GlobbyMouse
 * Method:    whatButton
 * Signature: ()I
 */
JNIEXPORT jint JNICALL Java_ghostclickerredux_GlobbyMouse_whatButton
  (JNIEnv *, jobject);

#ifdef __cplusplus
}
#endif
#endif
/*不要编辑此文件-它是机器生成的*/
#包括
/*类ghostclickerredux_GlobbyMouse的标题*/
#如果包含鼠标,请单击鼠标返回鼠标
#定义包含的幻影单击鼠标删除全局鼠标
#ifdef_uucplusplus
外部“C”{
#恩迪夫
/*
*类别:ghostclickerredux_GlobbyMouse
*方法:getMouseX
*签字:()一
*/
JNIEXPORT jint JNICALL Java_ghostclickerredux_GlobbyMouse_getMouseX
(JNIEnv*,jobject);
/*
*类别:ghostclickerredux_GlobbyMouse
*方法:getMouseY
*签字:()一
*/
JNIEXPORT jint JNICALL Java_ghostclickerredux_GlobbyMouse_getMouseY
(JNIEnv*,jobject);
/*
*类别:ghostclickerredux_GlobbyMouse
*方法:whatButton
*签字:()一
*/
JNIEXPORT jint JNICALL Java_ghostclickerredux_GlobbyMouse_whatButton
(JNIEnv*,jobject);
#ifdef_uucplusplus
}
#恩迪夫
#恩迪夫
最后是CPP代码

#include <cstdlib>
#include <iostream>
#include <windows.h>
#include <winuser.h>
#include "GlobbyMouse.h"

using namespace std;

int mouseX = 0;
int mouseY = 0;
POINT p;

void setMousePos() {
    if (GetCursorPos(&p)) {
        mouseX = p.x;
        mouseY = p.y;
    } else {
        cout << "Could not set mouse variables..." << endl;
    }
}

JNIEXPORT jint JNICALL Java_ghostclickerredux_GlobbyMouse_whatButton
(JNIEnv *, jobject) {
    if (GetAsyncKeyState(VK_LBUTTON) & 0x8000) {
        return 0;
    } else
        if (GetAsyncKeyState(VK_MBUTTON) & 0x8000) {
        return 1;
    } else
        if (GetAsyncKeyState(VK_RBUTTON) & 0x8000) {
        return 2;
    } else
        if (GetAsyncKeyState(VK_XBUTTON1) & 0x8000) {
        return 3;
    } else
        if (GetAsyncKeyState(VK_XBUTTON2) & 0x8000) {
        return 4;
    } else {
        return -1;
    }
}

JNIEXPORT jint JNICALL Java_ghostclickerredux_GlobbyMouse_getMouseX
(JNIEnv *, jobject) {
    setMousePos();
    return mouseX;
}

JNIEXPORT jint JNICALL Java_ghostclickerredux_GlobbyMouse_getMouseY
(JNIEnv *, jobject) {
    setMousePos();
    return mouseY;
}
#包括
#包括
#包括
#包括
#包括“GlobbyMouse.h”
使用名称空间std;
int-mouseX=0;
int mouseY=0;
p点;
void setMousePos(){
if(GetCursorPos&p)){
mouseX=p.x;
mouseY=p.y;
}否则{

我不是JNI方面的专家,但我最近也有类似的不满意的链接错误。我已经通过在MinGW中使用gcc而不是Cygwin来解决了这个问题。以防您使用gcc和Cygwin。我使用的是64位版本的MinGW,因为我是从64位计算机编译的er.Java也是从64位JDK编译的。我不知道你说的链接器是什么意思,但我有MinGW,包括它从JDK包含文件夹中需要的所有内容。哦,它也在使用G++来编译它。@McSpreads你如何调用编译器和链接器?我最近在MingW64中遇到了类似的问题-对于32位的构建,我必须使用def文件来映射函数名,它不适用于MingW64,我必须使用稍微不同的链接器选项据我所知,Andreas的问题是,在控制台中的“g++”之后写什么?在-Wl之后指定了什么选项?