' windows api testing, build a set of
' useful routines
' starting code is lifted from the qb64.org wiki to
' bootstrap the effort, then i'll add my own stuff.
'
' txb 27 December 2018
' use a cmd console window instead of a screen
' *************************************
' Windows API constants and types
' FINDEX_INFO_LEVELS
CONST FindExInfoStandard
= 0 CONST FindExInfoBasic
= 1
' FINDEX_SEARCH_OPS
CONST FindExSearchNameMatch
= 0 CONST FindExSearchLimitToDirectories
= 1 CONST FindExSearchLimitToDevices
= 2
' Error codes from Windows
CONST ERROR_FILE_NOT_FOUND
= 2 CONST ERROR_NO_MORE_FILES
= 18
' WIN32_FIND_DATA
CreationTime
AS STRING * 8 ' actually these are FileTimes, 64 bit nanoseconds from 1601 AlternateFileName
AS STRING * 14 ' DOS 8.3 format name
' *************************************
' Windows API functions, some originally from
' qb64.org/wiki examples, others created for this
' effort.
' Per FillippeHeitor at qb64.org, moved from 'declare library'
' to 'declare customtype library' to get around a C++
' compile error. Interestingly, the various functions in the
' above 'declare library' fail if put under 'customtype'.
' *************************************
' Variables and more variables
DIM CurrentDirectory$
, ModuleFileName$
' *************************************
' Some process related information
' SHOW CURRENT DIRECTORY
CurrentDirectory$
= SPACE$(MAX_PATH
)ResultLength& = GetCurrentDirectory(MAX_PATH, CurrentDirectory$)
PRINT "CURRENT DIRECTORY: ";
LEFT$(CurrentDirectory$
, ResultLength&
)
' SHOW CURRENT PROGRAM
ModuleFileName$
= SPACE$(MAX_PATH
)ResultLength& = GetModuleFileName(0, ModuleFileName$, MAX_PATH)
PRINT "CURRENTLY EXECUTING PROGRAM: ";
LEFT$(ModuleFileName$
, ResultLength&
)
' *************************************
' look for a likely non-existing file to demonstrate
' error handling
'***to be provided***
' *************************************
' list all the *.bas files in the directory
searchString
= "*.*" + CHR$(0)PRINT "seeking files matching "; searchString
hFind& = FindFirstFileEx&(searchString, FindExInfoStandard&, ffd, 0&, FindExSearchNameMatch, 0&)
LastError& = GetLastError&
PRINT "find first failed for "; searchString
PRINT "found some files:" PRINT LEFT$(ffd.FileName$
, Strlen
(ffd.FileName$
, MAX_PATH
)) 'PRINT "found ", ffd.FileName$
'PRINT Strlen(ffd.FileName$, MAX_PATH%)
Result% = FindNextFile&(hFind&, ffd)
Result% = FindClose(hFind&)
' and done
' *************************************
' Return length of a null terminated (asciiz) string
'
' this is bugged, it isn't going to handle zero
' length strings correctly
' nor max length strings
i = 1
i = i + 1
Strlen% = i - 1