Below code under Win10 fires "else clause" which indicated the open file dialog failed.I struggled to choose the right version between string,zstring ptr,wstring ptr,zstring*n,wstring*n to pass to OPENFILENAME .lpstrFile,lpstrFilter but all faied to open the selected file.
Any help would be appreciated.
Code: Select all
#define UNICODE
#include "windows.bi"
#include "win/commdlg.bi"
sub openFileDialog()
dim filename as wstring ptr
filename=allocate(256)
dim filter as wstring ptr
filter=allocate(256)
*filter=!"Text Files\0*.txt\0All Files\0*.*\0\0"
dim info as OPENFILENAME
info.lStructSize=sizeof(OPENFILENAME)
info.lpstrFilter=filter
info.nMaxFile=len(filename)
info.lpstrFile=filename
info.nFilterIndex=1
info.Flags=OFN_PATHMUSTEXIST or OFN_FILEMUSTEXIST
if(GetOpenFileName(@info)) then
MessageBox(null,info.lpstrFile,"You picked",0)
else
MessageBox(null,"Failed to open the file","Error",MB_OK or MB_ICONEXCLAMATION)
end if
end sub
print("Testing...")
openFileDialog()