especially if we're doing a simple console application, it is not necessary to always #Include "Windows.bi".
The very same applies of course also, to Frameworks of any 'colour or shape'.
Some of us (including myself) simply don't want those approx. 1.5 MB of predefinitions.
There is a way to do it DIY-style, which offers, among other *goodies, the possibility to:
- see the proper definition of internally used structs (Type in FB)
- see how "Aliases" are defined/used
- declaring such procedures (to later, just call them)
- directly calling a procedure from a "system library" aka: *.DLL (kernel32, user32 etc.)
- to tune things, with straight FB procedures
name (mostly shortening for ease of use in Main-code).
Proof of concept code:
Code: Select all
' Without_Windows_Bi.bas -- (c) 2020-03-07, MrSwiss
'
' uses: WIN-API without #Include's (obviously: WIN only!)
' compile: -s console
'
' whenever a WIN-API call needs a return-struct, we'll have to define it first
Type SysTime ' size 8 x 2 bytes (WORD) = 16 bytes
As UShort _yr, _mth, _dow, _dy, _ ' date-parts & day_of_week (0 = Sunday)
_hr, _min, _sec, _ms ' time-parts
End Type
Type pSysTime As SysTime Ptr ' ptr alias (struct ptr)
Type FileTime As ULongInt ' data-type alias (no struct needed)
Type pFileTime As ULongInt Ptr ' ptr alias
' the obvious advantage is here: we freely declare our own procedure names _
' instead of, being forced to use what M$ has decided to call them !!!
Declare Sub GetSysTime Lib "kernel32" Alias "GetSystemTime"(ByVal As pSysTime)
Declare Sub GetLocTime Lib "kernel32" Alias "GetLocalTime" (ByVal As pSysTime)
Declare Function SysT2FileT Lib "kernel32" Alias "SystemTimeToFileTime" _
(ByVal As pSysTime, ByVal As pFileTime) As Boolean
' Windows bool-type = Long in FB, however, FB's Boolean can also be used!
' FB procedures for convenience: numeric to string conversions
Declare Function DOW2Strg(ByVal DOW As UShort, ByVal sDOW As Boolean = FALSE) ByRef As Const ZString
Declare Function Mth2Strg(ByVal mth As UShort, ByVal smth As Boolean = FALSE) ByRef As Const ZString
' ===== DEMO code =====
' mandatory variables
Dim As SysTime st, lt ' 2 instances of type = struct in C/CPP
Dim As ULongInt ft ' unsigned 64 bit int-type (fixed size)
GetSysTime(@st) ' UTC-Time
Sleep(1, 1) ' force minimal delay (msec check)
GetLocTime(@lt) ' LocalTime
If SysT2FileT(@st, @ft) Then ' using return for ERROR checking
? "FileTime : "; ft : ? ' OK = return result
Else
? "SystemTimeToFileTime() failure!" ' NOK = deal with ERROR (show/quit)
? : ? "press a key, to QUIT "; ' wait for user action, then _
Sleep : End 1 ' return ErrorLevel = 1 (0 = OK)
End If
? "SystemTime UDT in 'UTC' raw: numerical" ' show obtained results
With st
? "Year : "; ._yr
? "Month : "; ._mth
? "DayOfWeek: "; ._dow
? "Day : "; ._dy
? "Hour : "; ._hr
? "Minute : "; ._min
? "Second : "; ._sec
? "MilliSec.: "; ._ms
End With
?
? "SystemTime UDT in 'Local Time'"
? "(tuned with String-Converter Functions)"
With lt
? "Year : "; ._yr
? "Month : "; Mth2Strg(._mth, TRUE) ' conversion to short-cut string
? "DayOfWeek: "; DOW2Strg(._dow) ' conversion to full string (default)
? "Day : "; ._dy
? "Hour : "; ._hr
? "Minute : "; ._min
? "Second : "; ._sec
? "MilliSec.: "; ._ms
End With
? : ? : ? "... done ... ";
Sleep
' ===== end DEMO code =====
' implementation(s) ...
Function DOW2Strg( _ ' DOW to string conversion
ByVal DOW As UShort, _ ' as returned in SysTime._dow
ByVal sDOW As Boolean = FALSE _ ' if TRUE then: short-cut week-day
) ByRef As Const ZString ' just string-data (no header)
Static As ZString * 10 _
DOWl(...) => { "Sunday", "Monday", "Tuesday", "Wednesday", _
"Thursday", "Friday", "Saturday" }
Static As ZString * 4 _
DOWs(...) => { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }
If sDOW Then Return DOWs(DOW) _
Else Return DOWl(DOW)
End Function
Function Mth2Strg( _ ' month to string conversion
ByVal mth As UShort, _ ' as returned in SysTime._mt
ByVal smth As Boolean = FALSE _ ' if TRUE then: short-cut month
) ByRef As Const ZString ' just string-data (no header)
Static As ZString * 10 _
mthl(1 To ...) => { "January", "February", "March", "April", _
"May", "June", "July", "August", "September", _
"October", "November", "December" }
Static As ZString * 4 _
mths(1 To ...) => { "Jan", "Feb", "Mar", "Apr", "May", "Jun", _
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }
If smth Then Return mths(mth) _
Else Return mthl(mth)
End Function
' ----- EOF -----