I'm using the Win 32 library. I'm trying to call a callback with a pointer. But when called, the function does not complete, but causes an error.
Example of DLL initialization:
Csclink csc = LibraryLoader.create(Csclink.class).option(LibraryOption.LoadNow, true)
.search(libPath).convention(CallingConvention.STDCALL)
.load("CscLink");
Example of Delegate block:
public interface TEnumTransactions{
@Delegate @StdCall
void callback(int account, double date, Pointer pointer);
}
And function
void GetAccountTransactions(int account, double firstDate, double SecondDate, TEnumTransactions transactions);
//Function call
csc.GetAccountTransactions(16972, 0, 0,(account1, date, pointer) -> {
System.out.println(account1 + " " + date + " " + pointer);
});
After callback i have next message Process finished with exit code -1073741819 (0xC0000005)
Example implementation from C#
private delegate void EnumTransactionsCallback(int Account, DateTime RDate, ref TTransactionInfo info);
public static bool GetAllTransactions(DateTime DateFirst, DateTime DateLast, ref List<ETransactionInfo> listTransactions)
{
try
{
EnumTransactionsCallback callback = new EnumTransactionsCallback(AddTransaction);
if (p_GetAllTransactions(DateFirst, DateLast, callback))
{
LastMsg = "The request GetAllTransactions is successful";
listTransactions = ListTransactions;
return true;
}
LastMsg = GetError();
flag = false;
}
catch (Exception e)
{
LastMsg = e.ToString();
flag = false;
}
return flag;
}
I tried to make a call as a structure, got an error, then I read in the documentation that it is better to call the structure through a pointer. If you remove the pointer from the delegate, the function completes correctly.