There is a bug in 3.0.2 which mistakenly uses a struct by value even
when the method signature does not declare it so. You'll need a build
from version control to fix the bug; as a workaround you'll need to
pass a non-ByValue struct instead.
On May 19, 2008, at 6:19 PM, Ramiro Brescia - wrote:
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