1

我的问题如下。我对 C/C++ 代码相当陌生,我感觉我使用了不正确的东西或者没有使用需要的东西。虽然我制作了一个测试应用程序来查看 dll 代码是否执行并且它确实执行了。我在这方面搜索了很多,似乎找不到任何东西。如果我需要更多解释,请告诉我。这是我的第一篇文章顺便说一句我一直在使用这个网站,虽然它很棒。

Java 代码返回错误:

Exception in thread "Thread-2" java.lang.UnsatisfiedLinkError: ghostclickerredux.GlobbyMouse.whatButton()I

以下所有代码都在 java 中,并包含在实现可运行接口的类中。线程启动并将执行循环,只要......你得到了剩下的。如果我要评论 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

最后是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;
}
4

0 回答 0