On Feb 5, 2008, at 10:13 AM, Marek Lewczuk wrote:
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:
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.