In release mode, it does nothing, whilst in debug mode it opens quickly and then closes straight away...
This is with the beta. I had thought in 9.040 it was working :)
What a stupid error. I get an exception "%0xc0020043" in GetOpenFileName API - And have _NO_ idea why or where. The release version works for me, also the debug version in Visual Studio.
What to do now?
Its a tough one...
with win10 and GLB steam version the exception in debug mode is always present
Phew. I'll try to find it again.
Thanks
if it can help I use this code
SETCURRENTDIR("Media") // go to media files
file$=Get_Open_File_Name$()
// --------------------------------- //
// Project: Qedo
// Start: Saturday, June 26, 2021
// IDE Version: 16.793
INLINE
}
#define HINSTANCE W32HINSTANCE
#define HINSTANCE__ W32HINSTANCE__
#define HMODULE W32HMODULE
#undef LPSTR
#undef DECLARE_HANDLE
#undef LPCTSTR
#undef DWORD
#undef LPWSTR
#undef LPCWSTR
#define HWND W32HWND
#define HWND__ W32HWND__
#define HANDLE W32HANDLE
#undef MAX_PATH
#undef TCHAR
#define WIN32_LEAN_AND_MEAN
#define WinMain WinMain2
#include <windows.h>
#include <commdlg.h>
namespace __GLBASIC__ {
ENDINLINE
FUNCTION Get_Open_File_Name$:
INLINE
char filename[ 200 ];
char filetitle[ 200 ];
tagOFNA ofn;
*filename = 0; *filetitle = 0;
for(int i=0; i<sizeof(tagOFNA); ++i) // ZeroMemory
{
((char*)&ofn)[i] = 0;
}
ofn.lStructSize = sizeof( ofn );
ofn.hwndOwner = GetFocus(); // If you have a window to center over, put its HANDLE here
ofn.lpstrFilter = "Jpg & Png File\0*.Jpg;*.png\0All Files(.)\0*.*\0";
ofn.lpstrFile = filename;
ofn.nMaxFile = 1000;
ofn.lpstrTitle = "Select a photo";
ofn.Flags = OFN_DONTADDTORECENT | OFN_FILEMUSTEXIST;
ofn.lpstrInitialDir = "."; // Initial directory.
ofn.lpstrFileTitle = filetitle;
int ret=GetOpenFileNameA(&ofn);
return filename;
ENDINLINE
ENDFUNCTION
try this, maybe?
// --------------------------------- //
// Project: Qedo
// Start: Saturday, June 26, 2021
// IDE Version: 16.793
INLINE
}
#define HINSTANCE W32HINSTANCE
#define HINSTANCE__ W32HINSTANCE__
#define HMODULE W32HMODULE
#undef LPSTR
#undef DECLARE_HANDLE
#undef LPCTSTR
#undef DWORD
#undef LPWSTR
#undef LPCWSTR
#define HWND W32HWND
#define HWND__ W32HWND__
#define HANDLE W32HANDLE
#undef MAX_PATH
#undef TCHAR
#define WIN32_LEAN_AND_MEAN
#define WinMain WinMain2
#include <windows.h>
#include <commdlg.h>
namespace __GLBASIC__ {
ENDINLINE
FUNCTION Get_Open_File_Name$:
INLINE
char filename[ 1024] = "";
// char filetitle[ 1024 ] = "";
tagOFNA ofn;
char extra_memory_just_to_be_safe[1024];
for(int i=0; i<sizeof(tagOFNA); ++i) // ZeroMemory
{
((char*)&ofn)[i] = 0;
}
ofn.lStructSize = sizeof( ofn );
ofn.hwndOwner = HWND(GLBASIC_HWND()); // If you have a window to center over, put its HANDLE here
ofn.lpstrFilter = "Jpg & Png File\0*.Jpg;*.png\0All Files(.)\0*.*\0";
ofn.lpstrFile = filename;
ofn.nMaxFile = 1000;
char title[1024] = "Select a photo";
ofn.lpstrTitle = title;
ofn.Flags = OFN_DONTADDTORECENT | OFN_FILEMUSTEXIST;
ofn.lpstrInitialDir = "."; // Initial directory.
ofn.lpstrFileTitle = NULL;
int ret=GetOpenFileNameA(&ofn);
return DGStr(filename);
ENDINLINE
ENDFUNCTION
See
https://www.glbasic.com/forum/index.php?topic=2129.0
and
https://docs.microsoft.com/en-us/windows/win32/api/commdlg/nf-commdlg-getopenfilenamea
Hints:
LPCTSTR - the 'C' stands for 'const'. If it's ommited, do NOT provide a hard coded string like "test", but a pointer to an allocated stack buffer.
I had problems with a wrong size of the struct once, so I added some extra bytes. Might not be a problem....
lpstrFileTitle should be null.
Thank you Gernot.
Also this version work in normal mode but in Debug mode i get the following:
*** Unhandled exception ***
ExceptionCode = 0xc0020043
it's a stupid problem that complicates debugging of the program but when compiled it works fine
P.S:
thanks for the very useful clarifications
Doens't crash for me in debug mode. I think your problem is somewere else.
SYSTEMPOINTER TRUE
AUTOPAUSE FALSE
LOCAL a$ = Get_Open_File_Name$()
PRINT a$,0,0
SHOWSCREEN
MOUSEWAIT
END
// --------------------------------- //
// Project: Qedo
// Start: Saturday, June 26, 2021
// IDE Version: 16.793
FUNCTION foo:
ENDFUNCTION
INLINE
}
#define HINSTANCE W32HINSTANCE
#define HINSTANCE__ W32HINSTANCE__
#define HMODULE W32HMODULE
#undef LPSTR
#undef DECLARE_HANDLE
#undef LPCTSTR
#undef DWORD
#undef LPWSTR
#undef LPCWSTR
#define HWND W32HWND
#define HWND__ W32HWND__
#define HANDLE W32HANDLE
#undef MAX_PATH
#undef TCHAR
#define WIN32_LEAN_AND_MEAN
#define WinMain WinMain2
#include <windows.h>
#include <commdlg.h>
namespace __GLBASIC__ {
ENDINLINE
FUNCTION Get_Open_File_Name$:
INLINE
char filename[ 1024] = "";
// char filetitle[ 1024 ] = "";
tagOFNA ofn;
char extra_memory_just_to_be_safe[1024];
for(int i=0; i<sizeof(tagOFNA); ++i) // ZeroMemory
{
((char*)&ofn)[i] = 0;
}
ofn.lStructSize = sizeof( ofn );
ofn.hwndOwner = HWND(GLBASIC_HWND()); // If you have a window to center over, put its HANDLE here
ofn.lpstrFilter = "Jpg & Png File\0*.Jpg;*.png\0All Files(.)\0*.*\0";
ofn.lpstrFile = filename;
ofn.nMaxFile = 1000;
char title[1024] = "Select a photo";
ofn.lpstrTitle = title;
ofn.Flags = OFN_DONTADDTORECENT | OFN_FILEMUSTEXIST;
ofn.lpstrInitialDir = "."; // Initial directory.
ofn.lpstrFileTitle = NULL;
int ret=GetOpenFileNameA(&ofn);
return DGStr(filename);
ENDINLINE
ENDFUNCTION
I fear, you're having a buffer overrun somewere else. These are hard to debug and find. Most likely in an INLINE block. Try to make a small as possible program, that crashes and zip it.
It doesn't work, it's definitely a problem with my computer. I loaded your code but except sometimes in debug mode the system crashes
ad maiora
Yikes. Can you debug in GLB and see what line it crashes? (Add some DEBUG() commands to find it in INLINE).
the crash occurs when it executes the line:
int ret = GetOpenFileNameA (& ofn);
However I partially solved it by adding the following code.
? IFDEF GLB_DEBUG
a $ = "C: /image/image.png" // simulate
? ELSE
LOCAL a $ = Get_Open_File_Name $ ()
? ENDIF
Before the dialog opens? Or when you click "OK"?
Before the dialog opens.
Another try:
FUNCTION Get_Open_File_Name$:
INLINE
char filename[ 2048 ] = "";
// char filetitle[ 1024 ] = "";
struct MYOFN : public tagOFNA{
char extra_memory_just_to_be_safe[1024];
};
MYOFN ofn = {};
ofn.lStructSize = sizeof( tagOFNA );
ofn.hwndOwner = HWND(GLBASIC_HWND()); // If you have a window to center over, put its HANDLE here
ofn.lpstrFilter = "Jpg & Png File\0*.Jpg;*.png\0All Files(.)\0*.*\0\0\0\0\0\0\0\0\0\0";
ofn.lpstrFile = filename;
ofn.nMaxFile = 1000;
char title[1024] = "Select a photo";
ofn.lpstrTitle = title;
ofn.Flags = OFN_DONTADDTORECENT | OFN_FILEMUSTEXIST;
DGStr current = GETCURRENTDIR_Str();
ofn.lpstrInitialDir = current.c_str(); // Initial directory.
ofn.lpstrFileTitle = NULL;
int ret=GetOpenFileNameA(&ofn);
return DGStr(filename);
ENDINLINE
ENDFUNCTION
with GLBasic IDE, Version: 16.947 in debug mode always:
"exception 0xc0020043"
Qedo it isn't an issue with your computer, on my pc FileRequest$ also doesn't work but gives other error 'Access Violation Exception', on both Win 8.1/10, it doesn't work in either debug/release modes, and this only applies to v16 (Steam), same code compiled with v15 works properly and opens popup window. Also I can't get those inline examples working, Am I missing some include files or something that's needed to check this?