3 messages in net.java.dev.jna.usersRe: [jna-users] const pointer problem...
FromSent OnAttachments
Ramiro Brescia - < Datahost S.R.L. >May 19, 2008 3:19 pm 
Timothy WallMay 19, 2008 3:26 pm 
Ramiro BresciaMay 21, 2008 6:31 am 
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] const pointer problems by passing a Structure.ByValue referenceActions...
From:Ramiro Brescia (rami@datahost.com.ar)
Date:May 21, 2008 6:31:45 am
List:net.java.dev.jna.users

Thanks Timothy. I will try that way. Later, I will tell you how it went.

Ramiro

Hi, sorry for my English. I am working with a library that manages a String wrapper (MyString), because it does not use null terminated Strings. Then it has a function to create from a null terminated String.

Data mapping:

------------- In the C side: struct MyString { char *ptr; int slen; }

MyString mystr_create(char *str){ MyString dst; dst.ptr = str; dst.slen = strlen(str);

return dst; }

int mystr_len(const MyString *str){ return str->slen; }

In the java side: public class MyString extends Structure { public static class ByValue extends MyString implemets Structure.ByValue {} public Pointer ptr; public int slen; }

public MyString.ByValue mystr_create(String str);

public int mystr_len(MyString str);

An use example (java):

---------------------- MyString myStr = fooLibrary.mystr_create(new String("Hello world!")); System.out.println(myStr); System.out.println("Length: " + fooLibrary.mystr_len(myStr));

Out:

---- MyString$ByValue(allocated@0xafd3c10 (8 bytes)) { Pointer ptr@0=native@0xafd3bc8 int slen@4=12 } Length: 1870078063

As we can see, the creation is ok, but when pass a Struct.ByValue reference in a const pointer parameter the integer value is wrong. The example is runnig on: Windows XP SP2 + Eclipse 3.2.0 + jdk1.6.0_04 + dll is compiled with Visual C++ 2008 Express.

Best regards and exelent work! Ramiro

--------------------------------------------------------------------- To unsubscribe, e-mail: user@jna.dev.java.net For additional commands, e-mail: user@jna.dev.java.net

------------------------------------------------------------------------

No virus found in this incoming message. Checked by AVG. Version: 8.0.100 / Virus Database: 269.23.21/1454 - Release Date: 19/05/2008
7:44