• Try to call Win32 GetOpenFileName

    From Michael Hagl@21:1/5 to All on Mon Apr 12 07:38:19 2021
    Hi,
    I try to have a windows Dialog to select a file form disk.
    Herefor I want to call Win32/GetOpenfilename but function hb_ArrayToStrcture allways ends with error.

    Test:
    aOpenFilename := Array(5)
    aOpenFilename[1] := 20
    aOpenFilename[2] := 0
    aOpenFilename[3] := 0
    aOpenFilename[4] := "Alle Dateien (*.*)"
    aOpenFilename[5] := ""
    aTypes := Array(5)
    aTypes[1] := CTYPE_LONG
    aTypes[2] := CTYPE_LONG
    aTypes[3] := CTYPE_LONG
    aTypes[4] := CTYPE_CHAR
    aTypes[5] := CTYPE_CHAR

    cStruc := hb_ArrayToStructure(aOpenFileName,aTypes,4)

    Here there is an error in hb_ArrayToStructure(): Unrecorerable error 9011: hb_xfree called witch a NULL pointer. Called from hb_stackInit(0)

    What is wrong?

    Michael Hagl

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mel Smith@21:1/5 to in...@hagl.de on Tue Apr 13 07:56:57 2021
    On Monday, April 12, 2021 at 8:38:21 AM UTC-6, in...@hagl.de wrote:
    Hi,
    I try to have a windows Dialog to select a file form disk.
    Herefor I want to call Win32/GetOpenfilename but function hb_ArrayToStrcture allways ends with error.

    Test:
    aOpenFilename := Array(5)
    aOpenFilename[1] := 20
    aOpenFilename[2] := 0
    aOpenFilename[3] := 0
    aOpenFilename[4] := "Alle Dateien (*.*)"
    aOpenFilename[5] := ""
    aTypes := Array(5)
    aTypes[1] := CTYPE_LONG
    aTypes[2] := CTYPE_LONG
    aTypes[3] := CTYPE_LONG
    aTypes[4] := CTYPE_CHAR
    aTypes[5] := CTYPE_CHAR

    cStruc := hb_ArrayToStructure(aOpenFileName,aTypes,4)

    Here there is an error in hb_ArrayToStructure(): Unrecorerable error 9011: hb_xfree called witch a NULL pointer. Called from hb_stackInit(0)

    What is wrong?

    Michael Hagl

    Hi Michael:

    Below is a small modification of your code that works correctly.

    I believe that your use of *strings* of characters rather than just one character may be the problem for this function. But I would examine the CTYPE_CHAR values, and play with them. I don't really know what else to try.
    Good luck.
    -Mel Smith

    ***** my code based on your example *****
    #include "cStruct.ch"
    PROCEDURE Main
    aOpenFilename := Array(5)
    aOpenFilename[1] := 10
    aOpenFilename[2] := 20
    aOpenFilename[3] := 30
    aOpenFilename[4] := "M"
    aOpenFilename[5] := "S"
    aTypes := Array(5)
    aTypes[1] := CTYPE_LONG
    aTypes[2] := CTYPE_LONG
    aTypes[3] := CTYPE_LONG
    aTypes[4] := CTYPE_CHAR
    aTypes[5] := CTYPE_CHAR

    cStruc := hb_ArrayToStructure(aOpenFileName,aTypes,4)
    cls


    ? " Length of Structure: " + NTOC(Len( cStruc ))

    ? " Left 4 chars of struct converted to Integer: "+NTOC(Bin2L( Left( cStruc, 4 ) ))

    ?
    ? "Here is cStruc below - bounded by < > chars:"
    ? "<"+cStruc+">"
    ?
    ? "Press any Key: "
    inkey(0)

    RETURN
    **********

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Enrico Maria Giordano@21:1/5 to All on Tue Apr 13 17:25:50 2021
    Il 12/04/2021 16:38, Michael Hagl ha scritto:

    Hi,
    I try to have a windows Dialog to select a file form disk.
    Herefor I want to call Win32/GetOpenfilename but function hb_ArrayToStrcture allways ends with error.

    This is a working sample:

    FUNCTION MAIN()

    LOCAL cFile := CGETFILE()

    ? cFile

    INKEY( 0 )

    RETURN NIL


    #pragma BEGINDUMP

    #include "windows.h"
    #include "hbapi.h"

    HB_FUNC( CGETFILE )
    {
    OPENFILENAME ofn;

    char File[ MAX_PATH ] = "";

    ofn.lStructSize = 76;
    ofn.hwndOwner = GetActiveWindow();
    ofn.lpstrFilter = 0;
    ofn.lpstrCustomFilter = 0;
    ofn.nFilterIndex = 0;
    ofn.lpstrFile = File;
    ofn.nMaxFile = MAX_PATH;
    ofn.lpstrFileTitle = 0;
    ofn.lpstrInitialDir = ".";
    ofn.lpstrTitle = "Apri";
    ofn.Flags = OFN_HIDEREADONLY | OFN_NOCHANGEDIR | OFN_NODEREFERENCELINKS | OFN_NOTESTFILECREATE | OFN_PATHMUSTEXIST;
    ofn.lpstrDefExt = 0;

    if ( GetOpenFileName( &ofn ) )
    hb_retclen( File, lstrlen( File ) );
    else
    hb_retc( "" );
    }

    #pragma ENDDUMP

    EMG

    http://www.emagsoftware.it
    http://www.emagsoftware.it/emgmusic
    http://www.emagsoftware.it/spectrum
    http://www.emagsoftware.it/tbosg

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mel Smith@21:1/5 to All on Tue Apr 13 15:26:06 2021
    Hi Again:
    FWIW, here's the correction for Michaels's program to compile and run successfully.
    I also understand that Enrico has provided a proper solution for his program, but I'm a bit intrigued by the HB_ARRAYTOSTRUCTURE() function, and what we could use it for. Is it just a loose appendage to our language, or is it useful for some of us. I'
    m baffled by it but, anyway, it *does* now work without failure using Michael's parameters.

    The working version is shown below.

    -Mel

    ***** Working version of Michael's proggie *****
    #include "cStruct.ch"

    PROCEDURE Main

    aOpenFilename := Array(5)
    aOpenFilename[1] := 20
    aOpenFilename[2] := 0
    aOpenFilename[3] := 0
    aOpenFilename[4] := "Alle Dateien (*.*)"
    aOpenFilename[5] := ""
    aTypes := Array(5)
    aTypes[1] := CTYPE_LONG
    aTypes[2] := CTYPE_LONG
    aTypes[3] := CTYPE_LONG
    aTypes[4] := CTYPE_UNSIGNED_CHAR_PTR
    aTypes[5] := CTYPE_UNSIGNED_CHAR_PTR

    cStruc := hb_ArrayToStructure(aOpenFileName,aTypes,4)
    cls


    ? " Length of Structure: " + NTOC(Len( cStruc ))

    ? " Left 4 chars of struct converted to Integer: "+NTOC(Bin2L( Left( cStruc, 4 ) ))

    ?
    ? "Here is cStruc below - bounded by < > chars:"
    ? "<"+cStruc+">"
    ?
    ? "Press any Key: "
    inkey(0)

    RETURN

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Michael Hagl@21:1/5 to Enrico Maria Giordano on Wed Apr 14 05:43:24 2021
    Hi Enrico,
    sorry for delay.

    thank you, your function works, but after calling and select a file, my XHb mouse system does not work anymore:
    MLeftDown() is always .t. and. UI can not find how to silve this problem.

    Michael Hagl


    Enrico Maria Giordano schrieb am Dienstag, 13. April 2021 um 17:25:54 UTC+2:
    Il 12/04/2021 16:38, Michael Hagl ha scritto:

    Hi,
    I try to have a windows Dialog to select a file form disk.
    Herefor I want to call Win32/GetOpenfilename but function hb_ArrayToStrcture allways ends with error.
    This is a working sample:

    FUNCTION MAIN()

    LOCAL cFile := CGETFILE()

    ? cFile

    INKEY( 0 )

    RETURN NIL


    #pragma BEGINDUMP

    #include "windows.h"
    #include "hbapi.h"

    HB_FUNC( CGETFILE )
    {
    OPENFILENAME ofn;

    char File[ MAX_PATH ] = "";

    ofn.lStructSize = 76;
    ofn.hwndOwner = GetActiveWindow();
    ofn.lpstrFilter = 0;
    ofn.lpstrCustomFilter = 0;
    ofn.nFilterIndex = 0;
    ofn.lpstrFile = File;
    ofn.nMaxFile = MAX_PATH;
    ofn.lpstrFileTitle = 0;
    ofn.lpstrInitialDir = ".";
    ofn.lpstrTitle = "Apri";
    ofn.Flags = OFN_HIDEREADONLY | OFN_NOCHANGEDIR |
    OFN_NODEREFERENCELINKS | OFN_NOTESTFILECREATE | OFN_PATHMUSTEXIST; ofn.lpstrDefExt = 0;

    if ( GetOpenFileName( &ofn ) )
    hb_retclen( File, lstrlen( File ) );
    else
    hb_retc( "" );
    }

    #pragma ENDDUMP

    EMG

    http://www.emagsoftware.it
    http://www.emagsoftware.it/emgmusic
    http://www.emagsoftware.it/spectrum
    http://www.emagsoftware.it/tbosg

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Michael Hagl@21:1/5 to meds...@gmail.com on Wed Apr 14 06:35:32 2021
    Hi Mel,

    sorry for delay
    thank you, this seems to work, but the calling of dll function GetOpenFileName does not work.

    What is wrong?

    Michael Hagl

    FUNCTION Win_GetOpenFileName2()
    LOCAL cFile, nRet, i
    LOCAL aOpenFilename, aTypes, cStruc, nHandle
    Set Console on
    aOpenFilename := Array(20)
    aOpenFilename[1] := 20 //nStructSize As Long Länge der Struktur IN Bytes
    aOpenFilename[2] := 0 //hwndOwner As Long Windows-Handle des "Besitzerfensters"
    aOpenFilename[3] := 0 //hInstance As Long für VB/A uninteressant
    aOpenFilename[4] := "" //sFilter As String s.o. die Eigenschaft Filter
    aOpenFilename[5] := "" //sCustomFilter As String für VB/A uninteressant
    aOpenFilename[6] := 0 //nCustFilterSize As Long für VB/A uninteressant
    aOpenFilename[7] := 1 //nFilterIndex As Long s.o. die Eigenschaft FilterIndex
    aOpenFilename[8] := Space(256) //sFile As String s.o. die Eigenschaft FileName
    aOpenFilename[9] := 256 //nFileSize As Long s.o. die Eigenschaft MaxFileSize
    aOpenFilename[10] := Space(256) //sFileTitle As String s.o. die Eigenschaft FileTitle
    aOpenFilename[11] := 256 //nTitleSize As Long Länge des Buffers für sFileTitle
    aOpenFilename[12] := "X:\TEMP" //sInitDir As String s.o. die Eigenschaft InitDir
    aOpenFilename[13] := "Test" //sDlgTitle As String s.o. die Eigenschaft DialogTitle
    aOpenFilename[14] := 0 //Flags As Long s.o. die Eigenschaft Flags
    aOpenFilename[15] := 1 //nFileOffset As Integer Offset des ersten Dateinamens bei Mehrfachauswahl
    aOpenFilename[16] := 1 //nFileExt As Integer Offset des ersten Dateiendung bei Mehrfachauswahl
    aOpenFilename[17] := "" //sDefFileExt As String s.o. die Eigenschaft DefaultExt
    aOpenFilename[18] := 0 //nCustData As Long Message für Hook-Funktion des Dialogs
    aOpenFilename[19] := 0 //fnHook As Long Funktionsadresse einer Hook-Funktion
    aOpenFilename[20] := "" //sTemplateName As String für VB/A uninteressant

    aTypes := Array(20)
    aTypes[1] := CTYPE_LONG // As Long Länge der Struktur IN Bytes
    aTypes[2] := CTYPE_LONG // As Long Windows-Handle des "Besitzerfensters"
    aTypes[3] := CTYPE_LONG // As Long für VB/A uninteressant
    aTypes[4] := CTYPE_UNSIGNED_CHAR_PTR // As String s.o. die Eigenschaft Filter
    aTypes[5] := CTYPE_UNSIGNED_CHAR_PTR // As String für VB/A uninteressant
    aTypes[6] := CTYPE_LONG // As Long für VB/A uninteressant
    aTypes[7] := CTYPE_LONG // As Long s.o. die Eigenschaft FilterIndex
    aTypes[8] := CTYPE_UNSIGNED_CHAR_PTR // As String s.o. die Eigenschaft FileName
    aTypes[9] := CTYPE_LONG // As Long s.o. die Eigenschaft MaxFileSize
    aTypes[10] := CTYPE_UNSIGNED_CHAR_PTR // As String s.o. die Eigenschaft FileTitle
    aTypes[11] := CTYPE_LONG // As Long Länge des Buffers für sFileTitle
    aTypes[12] := CTYPE_UNSIGNED_CHAR_PTR // As String s.o. die Eigenschaft InitDir
    aTypes[13] := CTYPE_UNSIGNED_CHAR_PTR // As String s.o. die Eigenschaft DialogTitle
    aTypes[14] := CTYPE_LONG // As Long s.o. die Eigenschaft Flags
    aTypes[15] := CTYPE_INT // As Integer Offset des ersten Dateinamens bei Mehrfachauswahl
    aTypes[16] := CTYPE_INT // As Integer Offset des ersten Dateiendung bei Mehrfachauswahl
    aTypes[17] := CTYPE_UNSIGNED_CHAR_PTR // As String s.o. die Eigenschaft DefaultExt
    aTypes[18] := CTYPE_LONG // As Long Message für Hook-Funktion des Dialogs
    aTypes[19] := CTYPE_LONG // As Long Funktionsadresse einer Hook-Funktion
    aTypes[20] := CTYPE_UNSIGNED_CHAR_PTR // As String für VB/A uninteressant

    cStruc := hb_arraytoStructure(aOpenFileName,aTypes,4)

    //nHandle := LoadLibrary( "Comdlg32")

    nRet := DllCall("Comdlg32", 0x0020, "GetOpenFileNameA", cStruc)
    ? nRet
    //FreeLibrary( nHandle )

    aOpenFileName := HB_StructureToArray(cStruc,aTypes,4,.f.,aOpenFileName)
    FOR i := 1 TO 20
    ? aOpenFilename[i]
    NEXT
    Wait "Press any key"

    Set Console off

    RETURN cFile


    meds...@gmail.com schrieb am Mittwoch, 14. April 2021 um 00:26:07 UTC+2:
    Hi Again:
    FWIW, here's the correction for Michaels's program to compile and run successfully.
    I also understand that Enrico has provided a proper solution for his program, but I'm a bit intrigued by the HB_ARRAYTOSTRUCTURE() function, and what we could use it for. Is it just a loose appendage to our language, or is it useful for some of us. I'm
    baffled by it but, anyway, it *does* now work without failure using Michael's parameters.

    The working version is shown below.

    -Mel

    ***** Working version of Michael's proggie *****
    #include "cStruct.ch"

    PROCEDURE Main

    aOpenFilename := Array(5)
    aOpenFilename[1] := 20
    aOpenFilename[2] := 0
    aOpenFilename[3] := 0
    aOpenFilename[4] := "Alle Dateien (*.*)"
    aOpenFilename[5] := ""
    aTypes := Array(5)
    aTypes[1] := CTYPE_LONG
    aTypes[2] := CTYPE_LONG
    aTypes[3] := CTYPE_LONG
    aTypes[4] := CTYPE_UNSIGNED_CHAR_PTR
    aTypes[5] := CTYPE_UNSIGNED_CHAR_PTR
    cStruc := hb_ArrayToStructure(aOpenFileName,aTypes,4)
    cls


    ? " Length of Structure: " + NTOC(Len( cStruc ))

    ? " Left 4 chars of struct converted to Integer: "+NTOC(Bin2L( Left( cStruc, 4 ) ))

    ?
    ? "Here is cStruc below - bounded by < > chars:"
    ? "<"+cStruc+">"
    ?
    ? "Press any Key: "
    inkey(0)

    RETURN

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Enrico Maria Giordano@21:1/5 to All on Wed Apr 14 17:00:00 2021
    Il 14/04/2021 16:56, Enrico Maria Giordano ha scritto:

    Sorry, I have no idea about this problem. I can't see how using a
    Windows API can break your mouse system...

    In my sample, try replacing this:

    ofn.lStructSize = 76;

    with this other:

    ofn.lStructSize = sizeof( ofn );

    EMG

    http://www.emagsoftware.it
    http://www.emagsoftware.it/emgmusic
    http://www.emagsoftware.it/spectrum
    http://www.emagsoftware.it/tbosg

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Enrico Maria Giordano@21:1/5 to All on Wed Apr 14 16:56:57 2021
    Il 14/04/2021 14:43, Michael Hagl ha scritto:

    Hi Enrico,
    sorry for delay.

    thank you, your function works, but after calling and select a file, my XHb mouse system does not work anymore:
    MLeftDown() is always .t. and. UI can not find how to silve this problem.

    Sorry, I have no idea about this problem. I can't see how using a
    Windows API can break your mouse system...

    EMG

    http://www.emagsoftware.it
    http://www.emagsoftware.it/emgmusic
    http://www.emagsoftware.it/spectrum
    http://www.emagsoftware.it/tbosg

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Daniele@21:1/5 to All on Wed Apr 14 17:42:48 2021
    Il 12/04/2021 16:38, Michael Hagl ha scritto:
    Hi,
    I try to have a windows Dialog to select a file form disk.
    Herefor I want to call Win32/GetOpenfilename but function hb_ArrayToStrcture allways ends with error.

    Test:
    aOpenFilename := Array(5)
    aOpenFilename[1] := 20
    aOpenFilename[2] := 0
    aOpenFilename[3] := 0
    aOpenFilename[4] := "Alle Dateien (*.*)"
    aOpenFilename[5] := ""
    aTypes := Array(5)
    aTypes[1] := CTYPE_LONG
    aTypes[2] := CTYPE_LONG
    aTypes[3] := CTYPE_LONG
    aTypes[4] := CTYPE_CHAR
    aTypes[5] := CTYPE_CHAR

    cStruc := hb_ArrayToStructure(aOpenFileName,aTypes,4)

    Here there is an error in hb_ArrayToStructure(): Unrecorerable error 9011: hb_xfree called witch a NULL pointer. Called from hb_stackInit(0)

    What is wrong?

    Michael Hagl


    HI,
    GetOpenFileName, a correct implementation to open f.e. a .xls file:

    #include "commdlg.ch" // from what32 contrib

    procedure main
    // no OFN_ALLOWMULTISELECT, returns one file
    cFNam := getOpenFileName (,,"File", {{"Files .xls", "*.xls"}}, ;
    OFN_EXPLORER + OFN_NOCHANGEDIR, "", "xls")
    alert(cFnam)
    return

    /*
    GetOpenFileName( hWnd, @cPath, cTitle, aFilter, nFlags, cInitDir,
    cDefExt, nIndex)

    hWnd: Handle to parent window
    cPath: (optional) if OFN_ALLOWMULTISELECT the path is stored
    cTitle: Window Title
    aFilter: Array of Files Types i.e. { {'Data Bases','*.dbf'},{'Clipper','*.prg'} }
    nFlags: OFN_* values default to OFN_EXPLORER
    cInitDir: Initial directory
    cDefExt: Default Extension i.e. 'DBF'
    nIndex: Index position of types

    Returns: If OFN_ALLOWMULTISELECT
    Array of files selected
    else
    FileName
    endif

    Nota:
    OFN_NOCHANGEDIR = 8
    OFN_FILEMUSTEXIST = 4096
    OFN_EXPLORER = 524288
    */


    *+ Function GetOpenFileName()
    *+
    *+--------------------------------------------------------------------
    *+
    FUNCTION GetOpenFileName( hWnd, cPath, cTitle, aaFilters, nFlags, ;
    cIniDir, cDefExt, nIndex)

    LOCAL aFiles, cRet, cFile, x, aFilter, cFilter := "",cItem, nAt, cChar

    IF cPath == NIL
    cPath := ""
    ENDIF

    IF ValType(aaFilters) == "A"
    FOR EACH aFilter IN aaFilters
    cFilter += aFilter[1]+Chr(0)+aFilter[2]+Chr(0)
    NEXT
    ENDIF

    IF AND(nFlags,OFN_ALLOWMULTISELECT) > 0
    cFile := Space(32000)
    ELSE
    cFile := Padr(Trim(cPath),256,Chr(0))
    ENDIF

    cRet := _GetOpenFileName( hWnd, @cFile, cTitle, cFilter, nFlags,;
    cIniDir, cDefExt, @nIndex)

    IF AND(nFlags,OFN_ALLOWMULTISELECT) > 0
    nAt := At(Chr(0)+Chr(0),cFile)

    cFile := Left(cFile,nAt)
    aFiles := {}

    IF nAt == 0 // no double chr(0) user must have pressed cancel
    RETURN (aFiles)
    ENDIF

    x := At(Chr(0),cFile) // fist null
    cPath := Left(cFile,x)

    cFile := StrTran(cFile,cPath,"")

    IF !Empty(cFile) // user selected more than 1 file
    cItem := ""

    FOR EACH cChar IN cFile
    IF cChar == 0
    aAdd(aFiles,StrTran(cPath,Chr(0),"")+'\'+cItem)
    cItem := ""
    LOOP
    ENDIF

    cItem += cChar
    NEXT
    ELSE
    aFiles := {StrTran(cPath,CHR(0),"")}
    ENDIF

    Return (aFiles)
    ENDIF

    RETURN cRet

    //-----------------------------------------------------*
    #pragma BEGINDUMP

    #include "hbapi.h"
    #include <windows.h>
    #include "hbapiitm.h"

    HB_FUNC( _GETOPENFILENAME )
    {
    OPENFILENAME ofn;
    char *szFileName =(char*) hb_xgrab( hb_parcsiz(2));

    strcpy( szFileName, hb_parcx( 2 ) );

    ZeroMemory( &ofn, sizeof(ofn) );
    ofn.hInstance = GetModuleHandle(NULL) ;
    ofn.lStructSize = sizeof(ofn);
    ofn.hwndOwner = (ISNIL (1) ? GetActiveWindow() : (HWND) hb_parnl(1));
    ofn.lpstrTitle = hb_parc (3);
    ofn.lpstrFilter = hb_parc (4);
    ofn.Flags = (ISNIL (5) ? OFN_EXPLORER : hb_parnl(5) );
    ofn.lpstrInitialDir = hb_parc (6);
    ofn.lpstrDefExt = hb_parc (7);
    ofn.nFilterIndex = hb_parni(8);
    ofn.lpstrFile = szFileName;
    ofn.nMaxFile = hb_parcsiz(2);

    if( GetOpenFileName( &ofn ) )
    {
    hb_stornl( ofn.nFilterIndex, 8 );
    hb_storclen( szFileName, hb_parcsiz(2), 2 ) ;
    hb_xfree( szFileName );
    hb_retc( ( char * ) ofn.lpstrFile );
    }
    else
    {
    hb_retc( "" );
    }
    }

    #pragma ENDDUMP

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mel Smith@21:1/5 to in...@hagl.de on Wed Apr 14 11:35:26 2021
    On Wednesday, April 14, 2021 at 7:35:33 AM UTC-6, in...@hagl.de wrote:
    Hi Mel,

    sorry for delay
    thank you, this seems to work, but the calling of dll function GetOpenFileName does not work.
    What is wrong?

    Michael Hagl
    FUNCTION Win_GetOpenFileName2()
    LOCAL cFile, nRet, i
    LOCAL aOpenFilename, aTypes, cStruc, nHandle
    Set Console on
    aOpenFilename := Array(20)
    aOpenFilename[1] := 20 //nStructSize As Long Länge der Struktur IN Bytes aOpenFilename[2] := 0 //hwndOwner As Long Windows-Handle des "Besitzerfensters"
    aOpenFilename[3] := 0 //hInstance As Long für VB/A uninteressant aOpenFilename[4] := "" //sFilter As String s.o. die Eigenschaft Filter aOpenFilename[5] := "" //sCustomFilter As String für VB/A uninteressant aOpenFilename[6] := 0 //nCustFilterSize As Long für VB/A uninteressant aOpenFilename[7] := 1 //nFilterIndex As Long s.o. die Eigenschaft FilterIndex
    aOpenFilename[8] := Space(256) //sFile As String s.o. die Eigenschaft FileName
    aOpenFilename[9] := 256 //nFileSize As Long s.o. die Eigenschaft MaxFileSize aOpenFilename[10] := Space(256) //sFileTitle As String s.o. die Eigenschaft FileTitle
    aOpenFilename[11] := 256 //nTitleSize As Long Länge des Buffers für sFileTitle
    aOpenFilename[12] := "X:\TEMP" //sInitDir As String s.o. die Eigenschaft InitDir
    aOpenFilename[13] := "Test" //sDlgTitle As String s.o. die Eigenschaft DialogTitle
    aOpenFilename[14] := 0 //Flags As Long s.o. die Eigenschaft Flags aOpenFilename[15] := 1 //nFileOffset As Integer Offset des ersten Dateinamens bei Mehrfachauswahl
    aOpenFilename[16] := 1 //nFileExt As Integer Offset des ersten Dateiendung bei Mehrfachauswahl
    aOpenFilename[17] := "" //sDefFileExt As String s.o. die Eigenschaft DefaultExt
    aOpenFilename[18] := 0 //nCustData As Long Message für Hook-Funktion des Dialogs
    aOpenFilename[19] := 0 //fnHook As Long Funktionsadresse einer Hook-Funktion aOpenFilename[20] := "" //sTemplateName As String für VB/A uninteressant

    aTypes := Array(20)
    aTypes[1] := CTYPE_LONG // As Long Länge der Struktur IN Bytes
    aTypes[2] := CTYPE_LONG // As Long Windows-Handle des "Besitzerfensters" aTypes[3] := CTYPE_LONG // As Long für VB/A uninteressant
    aTypes[4] := CTYPE_UNSIGNED_CHAR_PTR // As String s.o. die Eigenschaft Filter
    aTypes[5] := CTYPE_UNSIGNED_CHAR_PTR // As String für VB/A uninteressant aTypes[6] := CTYPE_LONG // As Long für VB/A uninteressant
    aTypes[7] := CTYPE_LONG // As Long s.o. die Eigenschaft FilterIndex aTypes[8] := CTYPE_UNSIGNED_CHAR_PTR // As String s.o. die Eigenschaft FileName
    aTypes[9] := CTYPE_LONG // As Long s.o. die Eigenschaft MaxFileSize aTypes[10] := CTYPE_UNSIGNED_CHAR_PTR // As String s.o. die Eigenschaft FileTitle
    aTypes[11] := CTYPE_LONG // As Long Länge des Buffers für sFileTitle aTypes[12] := CTYPE_UNSIGNED_CHAR_PTR // As String s.o. die Eigenschaft InitDir
    aTypes[13] := CTYPE_UNSIGNED_CHAR_PTR // As String s.o. die Eigenschaft DialogTitle
    aTypes[14] := CTYPE_LONG // As Long s.o. die Eigenschaft Flags
    aTypes[15] := CTYPE_INT // As Integer Offset des ersten Dateinamens bei Mehrfachauswahl
    aTypes[16] := CTYPE_INT // As Integer Offset des ersten Dateiendung bei Mehrfachauswahl
    aTypes[17] := CTYPE_UNSIGNED_CHAR_PTR // As String s.o. die Eigenschaft DefaultExt
    aTypes[18] := CTYPE_LONG // As Long Message für Hook-Funktion des Dialogs aTypes[19] := CTYPE_LONG // As Long Funktionsadresse einer Hook-Funktion aTypes[20] := CTYPE_UNSIGNED_CHAR_PTR // As String für VB/A uninteressant

    cStruc := hb_arraytoStructure(aOpenFileName,aTypes,4)

    //nHandle := LoadLibrary( "Comdlg32")

    nRet := DllCall("Comdlg32", 0x0020, "GetOpenFileNameA", cStruc)
    ? nRet
    //FreeLibrary( nHandle )

    aOpenFileName := HB_StructureToArray(cStruc,aTypes,4,.f.,aOpenFileName)
    FOR i := 1 TO 20
    ? aOpenFilename[i]
    NEXT
    Wait "Press any key"

    Set Console off

    RETURN cFile
    meds...@gmail.com schrieb am Mittwoch, 14. April 2021 um 00:26:07 UTC+2:
    Hi Again:
    FWIW, here's the correction for Michaels's program to compile and run successfully.
    I also understand that Enrico has provided a proper solution for his program, but I'm a bit intrigued by the HB_ARRAYTOSTRUCTURE() function, and what we could use it for. Is it just a loose appendage to our language, or is it useful for some of us. I'
    m baffled by it but, anyway, it *does* now work without failure using Michael's parameters.

    The working version is shown below.

    -Mel

    ***** Working version of Michael's proggie *****
    #include "cStruct.ch"

    PROCEDURE Main

    aOpenFilename := Array(5)
    aOpenFilename[1] := 20
    aOpenFilename[2] := 0
    aOpenFilename[3] := 0
    aOpenFilename[4] := "Alle Dateien (*.*)"
    aOpenFilename[5] := ""
    aTypes := Array(5)
    aTypes[1] := CTYPE_LONG
    aTypes[2] := CTYPE_LONG
    aTypes[3] := CTYPE_LONG
    aTypes[4] := CTYPE_UNSIGNED_CHAR_PTR
    aTypes[5] := CTYPE_UNSIGNED_CHAR_PTR
    cStruc := hb_ArrayToStructure(aOpenFileName,aTypes,4)
    cls


    ? " Length of Structure: " + NTOC(Len( cStruc ))

    ? " Left 4 chars of struct converted to Integer: "+NTOC(Bin2L( Left( cStruc, 4 ) ))

    ?
    ? "Here is cStruc below - bounded by < > chars:"
    ? "<"+cStruc+">"
    ?
    ? "Press any Key: "
    inkey(0)

    RETURN

    Hi Michael:
    Sorry, I can't provide any more help at this point.
    It appears that you are somehow not passing the parameter (cStruc) to GetOpenFileNameA() correctly, and
    I can't find an example that shows how to do this :((
    ... And the dll filename (Comdlg32) is case-sensitive, and must be the complete path.
    So, maybe "c:\Windows\system32\comdlg32" is better ???
    Good Luck !
    -Mel

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)