Page 1 of 1
RANDOM FileName ?
Posted: Sat Aug 13, 2022 12:23 am
by Jimmy
hi,
i know
Code: Select all | Expand
GetTempFileName( LPCSTR tmpdir, LPCSTR prefix, UINT unique, LPSTR filename )
but it seems not available under harbour
did somebody have made a HB_FUNC( GetTempFileName ) and can share it
p.s. need "A" and/or "W" Function
Re: RANDOM FileName ?
Posted: Sat Aug 13, 2022 8:37 am
by Enrico Maria Giordano
Try cNewFileName() or cTempFile(). Look at source\function\filename.prg.
Re: RANDOM FileName ?
Posted: Sun Aug 14, 2022 5:21 pm
by Jimmy
hi,
Enrico Maria Giordano wrote:Try cNewFileName() or cTempFile(). Look at source\function\filename.prg.
Ok,
Thx for Answer
Re: RANDOM FileName ?
Posted: Mon Aug 15, 2022 4:35 pm
by carlos vargas
Code: Select all | Expand
#include "fileio.ch"
FUNCTION TempFile( cDir, cExt, nAttr )
LOCAL cName
LOCAL fhnd
IF HB_ISSTRING( cDir )
cDir := hb_DirSepAdd( cDir )
ENDIF
IF HB_ISSTRING( cExt ) .AND. !( Left( cExt, 1 ) == "." )
cExt := "." + cExt
ENDIF
hb_default( @nAttr, SetFCreate() )
fhnd := hb_FTempCreateEx( @cName, cDir,, cExt, nAttr )
IF fhnd != F_ERROR
FClose( fhnd )
RETURN cName
ENDIF
RETURN ""
this function, exist in in hbct lib, please try
Re: RANDOM FileName ?
Posted: Mon Aug 15, 2022 7:28 pm
by Jimmy
hi
carlos vargas wrote:this function, exist in in hbct lib, please try
Aha, OK
Thx for Advice
Re: RANDOM FileName ?
Posted: Mon Aug 15, 2022 7:32 pm
by Rick Lipkin
Been using this for years ... not complicated ..
Code: Select all | Expand
cDEFA :="C"
DO WHILE .T.
SITEDBF := "TEMP"+(SUBSTR(TIME(),7,2)+SUBSTR(TIME(),4,2))
IF .not. FILE( cDefa+"\DBTMP\"+SITEDBF+".DBF" )
EXIT
ENDIF
ENDDO
Rick Lipkin
Re: RANDOM FileName ?
Posted: Mon Aug 15, 2022 7:39 pm
by Jimmy
hi,
Rick Lipkin wrote:Been using this for years ... not complicated ..
Yes,
i have use something like this as Workaround.
Re: RANDOM FileName ?
Posted: Tue Aug 16, 2022 5:58 am
by Otto
Dear Antonio,
can you please show how we can include this API function?
I tried different ways, but I am missing something. I get errors.
Best regards,
Otto
These are my tests:
Code: Select all | Expand
function main
/*
UINT GetTempFileNameA(
[in] LPCSTR lpPathName,
[in] LPCSTR lpPrefixString,
[in] UINT uUnique,
[out] LPSTR lpTempFileName
);
*/
? GetTmpFileName('c:\fwh\samples\',"ABC","123")
DLL32 Function GetTmpFileName ( lpszPath As String, lpPrefixString As String, wUnique As Long, lpTempFileName As String) As Long PASCAL ;
FROM "GetTempFileNameA" LIB "kernel32.dll"
/*
#pragma BEGINDUMP
#include <stdio.h>
#include <hbapi.h>
#include <windows.h>
HB_FUNC( GETTEMPFILENAMEA )
{
hb_retl( GetTempFileNameA( hb_parnl( 1 ), hb_parnl( 2 ), hb_parnl( 3 ), hb_parnl( 4 ) ) );
}
#pragma ENDDUMP
//----------------------------------------------------------------------------//
Re: RANDOM FileName ?
Posted: Tue Aug 16, 2022 6:23 am
by Antonio Linares
Dear Otto,
Using dynamic linking:
Code: Select all | Expand
#include "FiveWin.ch"
function Main()
local cFileName := Space( 50 )
/*
UINT GetTempFileNameA(
[in] LPCSTR lpPathName,
[in] LPCSTR lpPrefixString,
[in] UINT uUnique,
[out] LPSTR lpTempFileName
);
*/
GetTmpFileName( 'c:\fwh\samples', "ABC", 0, @cFileName )
MsgInfo( cFileName )
return nil
DLL32 Function GetTmpFileName( lpszPath AS LPSTR, lpPrefixString AS LPSTR, nUnique AS LONG, @lpTempFileName AS LPSTR ) AS LONG PASCAL ;
FROM "GetTempFileNameA" LIB "kernel32.dll"
Using static linking: (in this case we directly return the created name)
Code: Select all | Expand
#include "FiveWin.ch"
function Main()
local cFileName := Space( 50 )
/*
UINT GetTempFileNameA(
[in] LPCSTR lpPathName,
[in] LPCSTR lpPrefixString,
[in] UINT uUnique,
[out] LPSTR lpTempFileName
);
*/
? GetTmpFileName( 'c:\fwh\samples', "ABC", 0, @cFileName )
return nil
// DLL32 Function GetTmpFileName( lpszPath AS LPSTR, lpPrefixString AS LPSTR, nUnique AS LONG, @lpTempFileName AS LPSTR ) AS LONG PASCAL ;
// FROM "GetTempFileNameA" LIB "kernel32.dll"
#pragma BEGINDUMP
#include <hbapi.h>
#include <windows.h>
HB_FUNC( GETTMPFILENAME )
{
char * cFileName = ( char * ) hb_xgrab( 50 );
GetTempFileNameA( hb_parc( 1 ), hb_parc( 2 ), hb_parnl( 3 ), cFileName );
hb_retc( cFileName );
hb_xfree( cFileName );
}
#pragma ENDDUMP
Re: RANDOM FileName ?
Posted: Tue Aug 16, 2022 7:44 am
by Otto
Dear Antonio,
thank you so much.
Best regards,
Otto
PS; Have you seen the email from Renate?
Re: RANDOM FileName ?
Posted: Tue Aug 16, 2022 7:03 pm
by Antonio Linares
Dear Otto,
I haven't got any email from her
Please send your family my best regards
Re: RANDOM FileName ?
Posted: Tue Aug 16, 2022 8:17 pm
by nageswaragunupudi
Windows API function GetTempFileName() always uses ".TMP" extension.
FWH functions are better.