5 messages in net.java.dev.jna.usersRe: [jna-users] struct containing wch...
FromSent OnAttachments
seb bratieresJul 17, 2007 3:43 am 
Timothy WallJul 17, 2007 4:38 am 
j impalaJul 18, 2007 9:59 am 
Timothy WallJul 18, 2007 11:24 am 
Timothy WallJul 18, 2007 12:42 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] struct containing wchar_t*Actions...
From:Timothy Wall (twal@dev.java.net)
Date:Jul 17, 2007 4:38:45 am
List:net.java.dev.jna.users

It's a bug in Structure.java that is using a String to set the field value instead of wrapping it in a WString (see Structure.readField).

NOTE: you don't normally have to call Structure.write() prior to a function call; it will be done automatically prior to function invocation by the JNA library.

On Jul 17, 2007, at 6:43 AM, seb bratieres wrote:

Hi, I have a problem passing a structure which contains a string. Here is what I am doing. Is that the right way to go? I get the expected result, but it triggers an exception, so I suppose something in my usage of JNA is wrong. But what ?

Thank you Sebastien

* C type definition typedef struct VI_TagEntry_t{ TCHAR* name; } VI_TagEntry;

* Java JNA type definition public static class VI_TagEntry extends Structure { public WString name; }

* Java test code (in test class called JNATest) public void testVI_TagEntry() { Dll.VI_TagEntry tagEntry = new Dll.VI_TagEntry(); tagEntry.name = new WString("sample text"); tagEntry.write(); lib.testVI_TagEntry(tagEntry); /* throws exception, see below */ }

* called C code _declspec(dllexport) void __cdecl testVI_TagEntry(VI_TagEntry* tagEntry) { printf("tagEntry.name=%S \n", tagEntry->name); }

* output tagEntry.name=sample text

* Exception at the line marked above java.lang.RuntimeException: Exception setting field "name" at com.sun.jna.Structure.readField(Structure.java:329) at com.sun.jna.Structure.read(Structure.java:203) at com.sun.jna.Function.invoke(Function.java:191) at com.sun.jna.Library$Handler.invoke(Library.java:144) at $Proxy0.testVI_TagEntry(Unknown Source) at JNATest.testVI_TagEntry(JNATest.java:82) (etc) Caused by: java.lang.IllegalArgumentException at sun.reflect.UnsafeObjectFieldAccessorImpl.set (UnsafeObjectFieldAccessorImpl.java:63) at java.lang.reflect.Field.set(Field.java:656) at com.sun.jna.Structure.readField(Structure.java:326) ... 24 more

Beginnen Sie den Tag mit den neuesten Nachrichten. Machen Sie Yahoo! zu Ihrer Startseite!