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,
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.
Il 12/04/2021 16:38, Michael Hagl ha scritto:
Hi,This is a working sample:
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.
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
Hi Again:baffled by it but, anyway, it *does* now work without failure using Michael's parameters.
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
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
Sorry, I have no idea about this problem. I can't see how using a
Windows API can break your mouse system...
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.
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 Mel,m baffled by it but, anyway, it *does* now work without failure using Michael's parameters.
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'
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
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 405 |
Nodes: | 16 (2 / 14) |
Uptime: | 92:16:20 |
Calls: | 8,516 |
Calls today: | 6 |
Files: | 13,209 |
Messages: | 5,920,964 |