我的问题如下。关于C / C ++代码我是相当新的我有一种感觉我使用的东西不正确或者没有使用需要的东西。虽然我做了一个测试应用程序来查看dll代码是否执行但确实如此。我在这上面搜索过很多内容,似乎无法找到任何内容。如果我需要解释更多信息,请告诉我。这是我的第一篇文章BTW我一直都在使用这个网站,虽然很棒。
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
最后是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;
}