FILEREQUEST$ in Windows 7 x64 doesn't work

Previous topic - Next topic

MrTAToad

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 :)

Kitty Hello

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?

MrTAToad


Qedo

with win10 and GLB steam version the exception in debug mode is always present


Kitty Hello

Phew. I'll try to find it again.

Qedo

Thanks
if it can help I use this code

Code (glbasic) Select
SETCURRENTDIR("Media") // go to media files
file$=Get_Open_File_Name$()


Code (glbasic) Select

// --------------------------------- //
// 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

Kitty Hello

try this, maybe?

Code (glbasic) Select


// --------------------------------- //
// 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.




Qedo

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

Kitty Hello

Doens't crash for me in debug mode. I think your problem is somewere else.

Code (glbasic) Select



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.

Qedo

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

Kitty Hello

Yikes. Can you debug in GLB and see what line it crashes? (Add some DEBUG() commands to find it in INLINE).

Qedo

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

Kitty Hello

Before the dialog opens? Or when you click "OK"?

Qedo


Kitty Hello

Another try:
Code (glbasic) Select

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