I'm trying to use a C API that uses callbacks to handle several session events (logged in, logged out, connection problem...).
The session object (called `sp_session` is an opaque struct). All the callbacks are registered in a `sp_session_callbacks` structure. According to the API, I am supposed to declare the callbacks object, and put it into a Config object that I will provide when creating the `sp_session` object. If I don't want to use certain callbacks, I am supposed to initialize them with `null`. The API is using the `__stdcall` calling convention.
Here is a snippet of the C header that's relevant to my problem:
Here is my equivalent JNA code:
The sp_session object
The sp_session_callbacks object, containing all the callbacks
The callbacks object (here is LoggedIn, but of course I have one for each callback)
The native library, with the declaration of all the methods
**And my main class, binding it all together**
So, the sessionCreate function call makes the JRE crash with the trace at the end of the post `EXCEPTION_ACCESS_VIOLATION (0xc0000005) problematic frame: C [jna3757192097716619498.tmp+0x8ce7]`.
It looks like the logged_in callback is causing this, because when I set it to `null` it runs ok. Plus, if I initialize the `connection_error` callback, that has the exact same signature, it doesn't crash either.
I think in order to extend structure, I need to know the different fields of a C struct, don't I?
I happen to read that opaque struct should be converted to PointerType in JNA.
Also, if it was the problem, wouldn't it also crash when I set up the logged_in callback as null?
But I can try.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com