Author Topic: FILEREQUEST$ in Windows 7 x64 doesn't work  (Read 4966 times)

MrTAToad

  • Guest
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 :)
« Last Edit: 2011-Apr-09 by MrTAToad »

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10859
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: FILEREQUEST$ in Windows 7 x64 doesn't work
« Reply #1 on: 2011-Apr-15 »
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

  • Guest
Re: FILEREQUEST$ in Windows 7 x64 doesn't work
« Reply #2 on: 2011-Apr-15 »
Its a tough one...

Offline Qedo

  • Dr. Type
  • ****
  • Posts: 389
  • to program what I have do how should programming?
    • View Profile
Re: FILEREQUEST$ in Windows 7 x64 doesn't work
« Reply #3 on: 2021-Jun-26 »
with win10 and GLB steam version the exception in debug mode is always present

« Last Edit: 2021-Jun-26 by Qedo »

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10859
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: FILEREQUEST$ in Windows 7 x64 doesn't work
« Reply #4 on: 2021-Jun-29 »
Phew. I'll try to find it again.

Offline Qedo

  • Dr. Type
  • ****
  • Posts: 389
  • to program what I have do how should programming?
    • View Profile
Re: FILEREQUEST$ in Windows 7 x64 doesn't work
« Reply #5 on: 2021-Jun-30 »
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

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10859
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: FILEREQUEST$ in Windows 7 x64 doesn't work
« Reply #6 on: 2021-Jul-01 »
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.




Offline Qedo

  • Dr. Type
  • ****
  • Posts: 389
  • to program what I have do how should programming?
    • View Profile
Re: FILEREQUEST$ in Windows 7 x64 doesn't work
« Reply #7 on: 2021-Jul-01 »
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

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10859
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: FILEREQUEST$ in Windows 7 x64 doesn't work
« Reply #8 on: 2021-Jul-05 »
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.

Offline Qedo

  • Dr. Type
  • ****
  • Posts: 389
  • to program what I have do how should programming?
    • View Profile
Re: FILEREQUEST$ in Windows 7 x64 doesn't work
« Reply #9 on: 2021-Jul-06 »
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

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10859
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: FILEREQUEST$ in Windows 7 x64 doesn't work
« Reply #10 on: 2021-Jul-08 »
Yikes. Can you debug in GLB and see what line it crashes? (Add some DEBUG() commands to find it in INLINE).

Offline Qedo

  • Dr. Type
  • ****
  • Posts: 389
  • to program what I have do how should programming?
    • View Profile
Re: FILEREQUEST$ in Windows 7 x64 doesn't work
« Reply #11 on: 2021-Jul-08 »
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

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10859
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: FILEREQUEST$ in Windows 7 x64 doesn't work
« Reply #12 on: 2021-Jul-10 »
Before the dialog opens? Or when you click "OK"?

Offline Qedo

  • Dr. Type
  • ****
  • Posts: 389
  • to program what I have do how should programming?
    • View Profile
Re: FILEREQUEST$ in Windows 7 x64 doesn't work
« Reply #13 on: 2021-Jul-10 »
Before the dialog opens.

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10859
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: FILEREQUEST$ in Windows 7 x64 doesn't work
« Reply #14 on: 2021-Jul-12 »
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