11 messages in net.java.dev.jna.usersjna 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:jna and comdlg32.dllActions...
From:Marek Lewczuk (mar@lewczuk.com)
Date:Feb 4, 2008 2:36:28 pm
List:net.java.dev.jna.users

Hi,

I would like to use jna to communicate with comdlg32 on windows. I need to call GetOpenFileNameW() or GetOpenFileNameA(). In order to do that I've create following classes/interfaces:

public interface WindowsComDlg32 extends Library {

public static WindowsComDlg32 INSTANCE = (WindowsComDlg32) Native.loadLibrary("c:\\windows\\system32\\comdlg32.dll", WindowsComDlg32.class);

public static class OpenFileName extends Structure { public int lStructSize = 76; public Pointer hwndOwner; public String lpstrFilter; public String lpstrCustomFilter; public int nMaxCustFilter; public int nFilterIndex; public String lpstrFile; public int nMaxFile; public String lpstrFileTitle; public int nMaxFileTitle; public String lpstrInitialDir; public String lpstrTitle; public int Flags; public short nFileOffset; public short nFileExtension; public String lpstrDefExt; public Pointer lCustData; public Pointer lpfnHook; public Pointer lpTemplateName; @Override public int size () { return 76; }

}

public boolean GetOpenFileNameA (OpenFileName params); public boolean GetOpenFileNameW (OpenFileName params); }

In order to execute I use following code: WindowsComDlg32.OpenFileName params = new WindowsComDlg32.OpenFileName(); params.hwndOwner = Native.getWindowPointer(/*a reference to jframe*/); params.lpstrTitle = "This should be my title"; params.lpstrInitialDir = "c:\\windows"; params.Flags = 512; /* allow multiple files selection */ WindowsComDlg32.INSTANCE.GetOpenFileNameW(params);

Now, it is very strange but sometimes it does work and sometimes not - e.g. I need to unset "params.Flags" in order to open a dialog at all. Even if Flags is 0 it doesn't work properly, cause dialog is opened but the dialog title is not read from params. After selection a file and clicking "OK" the chosen file's path should be stored in lpstrFile but it isn't and sometimes JVM crashes just after making a selection and closing the dialog.

I would be really appreciated for help.

ML