aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes C callback with JNA makes JRE crash Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "C callback with JNA makes JRE crash" Watch "C callback with JNA makes JRE crash" New topic
Author

C callback with JNA makes JRE crash

Nathan Barraille
Greenhorn

Joined: Mar 01, 2011
Posts: 6

Hello,
I'm having more problems with JNA .

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.

Thank you!

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19783
    
  20

Shouldn't sp_session extend Structure? After all, that's how you declare it.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Nathan Barraille
Greenhorn

Joined: Mar 01, 2011
Posts: 6

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.

Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: C callback with JNA makes JRE crash