5 messages in net.java.dev.jna.users[jna-users] java.lang.Error: Invalid ...
FromSent OnAttachments
sofistaMay 15, 2009 4:48 am 
Daniel KaufmannMay 17, 2009 7:48 am 
sofistaMay 17, 2009 7:59 am 
Timothy WallMay 17, 2009 9:11 am 
sofistaMay 17, 2009 3:36 pm 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:[jna-users] java.lang.Error: Invalid memory access when calling JNA codeActions...
From:sofista (jbz@gmail.com)
Date:May 15, 2009 4:48:48 am
List:net.java.dev.jna.users

I get following exception, and frankly I have no idea what I'm doing wrong:

java.lang.Error: Invalid memory access at com.sun.jna.Function.invokeInt(Native Method) at com.sun.jna.Function.invoke(Function.java:292) at com.sun.jna.Function.invoke(Function.java:223) at com.sun.jna.Library$Handler.invoke(Library.java:204) at cx.jbzdak.diesIrae.genieConnector.$Proxy6.SadGetStatus(Unknown Source) at cx.jbzdak.diesIrae.genieConnector.LibraryConnector.getDetailedError(GenieConnector.java:166) at cx.jbzdak.diesIrae.genieConnector.GenieConnectorTest.testGetStatus(GenieConnectorTest.java:51)

Here is the C prototype:

short SadGetStatus(HMEM hDSC, ULONG * pulRC, short * psCli, USHORT * pusAct)

HMEM hDSC is really void * - a pointer that is supposed do be initialized elsewhere in the library ULONG * pulRC - is a pointer that will be holding the result of functions short * psCli, USHORT * pusAc - are unused by design allocated pointers that have to be passed ;)

Here is JNA prototype:

public short SadGetStatus (DscPointer dscPointer, NativeLongByReference result, ShortByReference dummy1, ShortByReference dummy2);

And it is called in following way:

static long getDetailedError(DscPointer dsc){ NativeLongByReference details = new NativeLongByReference(); ShortByReference s1 = new ShortByReference(), s2 = new ShortByReference(); GENIE_LIBRARY.SadGetStatus(dsc, details, s1, s2); //This is the call to to native library return details.getValue().longValue(); }

Only reason for this exception is that HMEM hDSC is not initialized, i initialize it in following way:

PointerByReference dsc = new PointerByReference(new IntByReference(0).getPointer().getPointer(0)); try { LibraryConnector.iUtlCreateFileDSC2(dsc,0,0); } catch (ConnectorException e) { throw new GenieException("Error while opening VDM", e.getCode()); } this.dsc = new DscPointer(dsc.getPointer());

And C prototype is: int iUtlCreateFileDSC(HMEM * phDSC, BOOL fAdvise, HWND hAdvise)

And LibraryConnector.iUtlCreateFileDSC2(dsc) doesn't throw an error so library that I'm linking to is thinking all is ok :) Is there any way to check if pointer by reference gets initialized with new value, so I can tell if it really gets initialized?

Thanks in advance!

PS. Werid thing - this code worked yesterday night ;) so it might be something nontrivial.

The fact that I'm running Windows on Virtualbox on Ubuntu shouldn't change anything?