5 messages in net.java.dev.jna.usersRe: [jna-users] java.lang.Error: Inva...
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:Re: [jna-users] java.lang.Error: Invalid memory access when calling JNA codeActions...
From:sofista (jbz@gmail.com)
Date:May 17, 2009 7:59:28 am
List:net.java.dev.jna.users

Yep, it came to being when I was trying to debug this stuff - i added logging statements that were supposed to assert whether dsc gets initialized, and I failed (logging statements just returned some junk numbers that were left unchanged after call).

dsc is to by initialized by call to native library - from my standpoint it's just a junk of memory that I from one call to another.

BTW how should I check if PointerByReference is initialized after function call (i.e. pointer's value change).

On Sun, May 17, 2009 at 16:48, Daniel Kaufmann <dani@gmail.com> wrote:

It is pretty unclear what you are trying to do with this code:PointerByReference dsc = new PointerByReference(new IntByReference(0).getPointer().getPointer(0)); maybe it is not doing what you think is doing.

new IntByReference(0).getPointer().getPointer(0) just returns null.

so you can write the above code as PointerByReference dsc = new PointerByReference(null); this.dsc = new DscPointer(dsc.getPointer());

Is this how you want to initialize dsc. -Daniel

On Fri, May 15, 2009 at 7:49 AM, sofista <jbz@gmail.com> wrote:

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?