11 messages in net.java.dev.jna.usersRe: [jna-users] jna and comdlg32.dll
FromSent OnAttachments
Marek LewczukFeb 4, 2008 2:36 pm 
Marek LewczukFeb 5, 2008 12:09 am 
Timothy WallFeb 5, 2008 5:52 am 
Marek LewczukFeb 5, 2008 7:13 am 
Timothy WallFeb 5, 2008 7:33 am 
Marek LewczukFeb 5, 2008 7:46 am 
Timothy WallFeb 5, 2008 8:05 am 
Timothy WallFeb 5, 2008 8:09 am 
Marek LewczukFeb 6, 2008 1:13 am 
Timothy WallFeb 6, 2008 5:35 am 
Marek LewczukFeb 6, 2008 6:00 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] jna and comdlg32.dllActions...
From:Timothy Wall (twal@dev.java.net)
Date:Feb 5, 2008 8:05:58 am
List:net.java.dev.jna.users

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[]).