On Feb 5, 2008, at 10:46 AM, Marek Lewczuk wrote:
Timothy Wall pisze:
The unicode version of the structure uses wchar_t-based strings,
which are represented by WString in JNA, unless you define a type
converter for String to WString (see W32API.DEFAULT_OPTIONS).
It's easier (and results in a cleaner interface definition) to
pass W32API.DEFAULT_OPTIONS to loadLibrary, then you can omit the
"-W" suffix from methods and use String for LPTCSTR.
I did that (public static WindowsComDlg32 INSTANCE =
(WindowsComDlg32) Native.loadLibrary("comdlg32.dll",
WindowsComDlg32.class, W32API.DEFAULT_OPTIONS)) but it still
doesn't work - after selection lpstrFile is null.
According to MSDN, lpstrFile must be a pointer to a buffer, with the
length specified by nMaxFile. This and any other fields which are
populated by the call needs to be a buffer, not a read-only String.
You can use char[], byte[], com.sun.jna.Memory, or java.nio.Buffer to
provide a buffer. In this case, char[] is probably the easiest;
after the call you can retrieve the String value via Native.toString
(char[]).