

![]() | 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: | Marek Lewczuk (mar...@lewczuk.com) | |
| Date: | Feb 5, 2008 7:13:27 am | |
| List: | net.java.dev.jna.users | |
Timothy Wall pisze:
a) use the w32 APIs already defined in com.sun.jna.examples.win32 as an example. pay attention to detail. StdCallLibrary, not Library, or you'll crash. W32API.DEFAULT_OPTIONS so that you don't have to define "-W" suffixes and so that you get proper String conversion for w32 unicode.
I did, it helped. Now it doesn't crash :-). Thanks.
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.
I fix that too, however it still doesn't work at it should. Dialog is opened as I want with properties that I've send (e.g title or flags), but after file selection struct's lpstrFile is always null. Why ??? After calling struct's toString I've get following result: WindowsComDlg32$OpenFileName(allocated@0xc9307c8 (76 bytes)) { int lStructSize@0=76 Pointer hwndOwner@4=native@0x480636 Pointer hInstance@8=null String lpstrFilter@c=All Files String lpstrCustomFilter@10=null int nMaxCustFilter@14=0 int nFilterIndex@18=1 String lpstrFile@1c=null int nMaxFile@20=0 String lpstrFileTitle@24=null int nMaxFileTitle@28=0 String lpstrInitialDir@2c=null String lpstrTitle@30=dsdsd int Flags@34=524808 short nFileOffset@38=3 short nFileExtension@3a=9 String lpstrDefExt@3c=null Pointer lCustData@40=null Pointer lpfnHook@44=null Pointer lpTemplateName@48=null }
So as you see lpstrFile is null, but nFileOffset and nFileExtension is not. What I'm doing wrong ??? Below fixed code:
import com.sun.jna.Native; import com.sun.jna.Pointer; import com.sun.jna.Structure; import com.sun.jna.examples.win32.W32API; import com.sun.jna.win32.StdCallLibrary;
public interface WindowsComDlg32 extends StdCallLibrary {
public static WindowsComDlg32 INSTANCE = (WindowsComDlg32) Native.loadLibrary("comdlg32.dll", WindowsComDlg32.class, W32API.DEFAULT_OPTIONS);
public static class OpenFileName extends Structure {
public final static int OFN_READONLY = 0x00000001; public final static int OFN_OVERWRITEPROMPT = 0x00000002; public static final int OFN_HIDEREADONLY = 0x00000004; public static final int OFN_NOCHANGEDIR = 0x00000008; public static final int OFN_SHOWHELP = 0x00000010; public static final int OFN_ENABLEHOOK = 0x00000020; public static final int OFN_ENABLETEMPLATE = 0x00000040; public static final int OFN_ENABLETEMPLATEHANDLE = 0x00000080; public static final int OFN_NOVALIDATE = 0x00000100; public static final int OFN_ALLOWMULTISELECT = 0x00000200; public static final int OFN_EXTENSIONDIFFERENT = 0x00000400; public static final int OFN_PATHMUSTEXIST = 0x00000800; public static final int OFN_FILEMUSTEXIST = 0x00001000; public static final int OFN_CREATEPROMPT = 0x00002000; public static final int OFN_SHAREAWARE = 0x00004000; public static final int OFN_NOREADONLYRETURN = 0x00008000; public static final int OFN_NOTESTFILECREATE = 0x00010000; public static final int OFN_NONETWORKBUTTON = 0x00020000; public static final int OFN_NOLONGNAMES = 0x00040000; public static final int OFN_EXPLORER = 0x00080000; public static final int OFN_NODEREFERENCELINKS = 0x00100000; public static final int OFN_LONGNAMES = 0x00200000; public static final int OFN_ENABLEINCLUDENOTIFY = 0x00400000; public static final int OFN_ENABLESIZING = 0x00800000; public static final int OFN_DONTADDTORECENT = 0x02000000; public static final int OFN_FORCESHOWHIDDEN = 0x10000000; public static final int OFN_EX_NOPLACESBAR = 0x00000001;
public OpenFileName () { lStructSize = size(); }
public int lStructSize; public Pointer hwndOwner; public Pointer hInstance; 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; }
public boolean GetOpenFileNameW (OpenFileName params);
}
WindowsComDlg32.OpenFileName params = new WindowsComDlg32.OpenFileName(); params.hwndOwner = Native.getWindowPointer(/*jframe object*/); params.lpstrTitle = "dsdsd"; params.lpstrFilter = "All Files\0*.*\0\0"; params.lpstrInitialDir = "c:\\windows"; params.Flags = WindowsComDlg32.OpenFileName.OFN_ALLOWMULTISELECT | WindowsComDlg32.OpenFileName.OFN_EXPLORER | WindowsComDlg32.OpenFileName.OFN_NOCHANGEDIR; System.out.println(WindowsComDlg32.INSTANCE.GetOpenFileNameW(params)); System.out.println(params);
Thanks for help.
ML







