I've finally found the source of the bug.
It was, as often, a really small mapping problem between my native code and the
java interface which, instead of crushing my JVM, made my application have this
really strange behaviour for some reason.
It seems that the wrong mapping could work without a swing app but not within
one.
I'm sorry for the disturbance.
Thanks a lot for the time spent on thinking on this problem.
Yours sincerely
Jean-Michel Tonneau
Timothy Wall <twal...@dev.java.net> a écrit :
On Apr 30, 2008, at 11:25 AM, Flávio wrote:
6 - DLL function:
Str1 TestFunction() {
struct Str1 info;
info.a=1;
Beep(500,1000);
info.b=2;
Beep(1000,1000);
return info;
}
Where is "struct Str1 info" in memory?
What happens to that memory when TestFunction returns?
Does TestFunction return a structure by value or by reference (i.e. a
pointer)?
What is JNA expecting?
The one answer I'll give you is that by default JNA handles
com.sun.jna.Structure as a pointer to struct (by reference). If you
need by value semantics, you need to make a subclass of your Structure
which implements ByValue (see the Structure javadcos and the javadoc
overview for details).
If you're not familiar with how structures are used in C, I recommend
you read the relevant chapter(s) in the K&R C book, or any other basic
book on C programming.