我正在使用 JNA 调用 dll 文件的函数。
简单DLL.h:
typedef int (__stdcall *eventCallback)(unsigned int id, int value);
namespace test
{
class hotas
{
public:
static __declspec(dllexport) int readValue(int a);
static __declspec(dllexport) void setCallback(eventCallback evnHnd);
};
}
简单DLL.cpp:
#include "simpleDLL.h"
#include <stdexcept>
using namespace std;
namespace test
{
eventCallback callback1 = NULL;
int test::readValue(int a)
{
return 2*a;
}
void test::setCallback(eventCallback evnHnd)
{
callback1 = evnHnd;
}
}
我的 Java 界面如下所示:
public interface DLLMapping extends Library{
DLLMapping INSTANCE = (DLLMapping) Native.loadLibrary("simpleDLL", DLLMapping.class);
int readValue(int a);
public interface eventCallback extends Callback {
boolean callback(int id, int value);
}
public void setCallback(eventCallback evnHnd);
}
最后是java main:
public static void main(String[] args) {
DLLMapping sdll = DLLMapping.INSTANCE;
int a = 3;
int result = sdll.readValue(a);
System.out.println("Result: " + result);
sdll.setCallback(new eventCallback(){
public boolean callback(int id, int value) {
//System.out.println("bla");
return true;
}
});
}
我的问题是我得到了错误,java 找不到函数 setCallback。我的代码有什么问题?
谢谢您的帮助!