Reputation: 130
I'm making some callbacks but in the DLL that I'm using I got some functions that use another functions as parameters, I already tried to use the interface but I couldn't make it work.
The function in DLL is like:
extern "C" { __declspec(dllexport) DIRET_CALLBACK void RegEnterString(pCallBackEnterString);}
I got an example in C#:
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
public delegate void _RegEnterString(_CallBackEnterString cbEnterString);
private _RegEnterString dllRegEnterString;
public delegate int _CallBackEnterString(StringBuilder parte1, int tamParte1, StringBuilder parte2, int tamParte2);
Upvotes: 0
Views: 321
Reputation: 130
If someone stuck in this same problem.
you need to create an interface to each function that is used as parameter then use the interface to create the reference like the delegates in C#
public interface anInterface extends Library {
anInterface INSTANCE = (anInterface)Native.loadLibrary("dll"),
anInterface.class);
public interface iCallback extends StdCallLibrary.StdCallCallback{
public int passedFunction(String label);
}
public void aFunction(iCallback cb);
}
you will need to use: import com.sun.jna.win32.StdCallLibrary;
Upvotes: 1