

![]() | Start a set with this search |
![]() | Include this search in one of my sets |
![]() | Exclude this search from one of my sets |
![]() | Permalink to these results Paste this link in email or IM: |
| Atom feed for tracking future search results Paste this URL into your reader: |
11 messages in net.java.dev.jna.usersRe: [jna-users] jna and comdlg32.dll| From | Sent On | Attachments |
|---|---|---|
| Marek Lewczuk | Feb 4, 2008 2:36 pm | |
| Marek Lewczuk | Feb 5, 2008 12:09 am | |
| Timothy Wall | Feb 5, 2008 5:52 am | |
| Marek Lewczuk | Feb 5, 2008 7:13 am | |
| Timothy Wall | Feb 5, 2008 7:33 am | |
| Marek Lewczuk | Feb 5, 2008 7:46 am | |
| Timothy Wall | Feb 5, 2008 8:05 am | |
| Timothy Wall | Feb 5, 2008 8:09 am | |
| Marek Lewczuk | Feb 6, 2008 1:13 am | |
| Timothy Wall | Feb 6, 2008 5:35 am | |
| Marek Lewczuk | Feb 6, 2008 6:00 am |

![]() | Permalink for this message Paste this link in email or IM: |
![]() | Permalink for this thread 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.dll | Actions... |
|---|---|---|
| From: | Timothy Wall (twal...@dev.java.net) | |
| Date: | Feb 5, 2008 5:52:57 am | |
| List: | net.java.dev.jna.users | |
a) use the w32 APIs already defined in com.sun.jna.examples.win32 as an example. pay attention to detail.
On Feb 5, 2008, at 3:10 AM, Marek Lewczuk wrote:
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 {
StdCallLibrary, not Library, or you'll crash.
public static WindowsComDlg32 INSTANCE = (WindowsComDlg32) Native.loadLibrary("c:\\windows\\system32\\comdlg32.dll", WindowsComDlg32.class);
"comdlg32" is sufficient. I'd also recommend using W32API.DEFAULT_OPTIONS so that you don't have to define "-W" suffixes and so that you get proper String conversion for w32 unicode.
public static class OpenFileName extends Structure { public int lStructSize = 76;
If your structure definition doesn't automatically produce the size you're expecting, you've left something out. Just glancing at the structure def here you've omitted a field after hwndOwner, at the very least.
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.
There's no magic here; waving dead chickens means you don't understand something about what you're doing. If it doesn't work, your interface definition is incorrect, so double check number and sizes of arguments, and number and sizes of structure fields.







