I am using JNA to call functions of a dll file.
simpleDLL.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);
};
}
simpleDLL.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;
}
}
My Java Interface looks like this:
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);
}
And finally the 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;
}
});
}
My problem is that I got the error, that java cannot find the function setCallback. What's wrong on my code?
Thank you for your help!