PDA

View Full Version : How to read the value of a function API Win32 ???



Tolo68
06-06-2022, 12:48
Hello, I am new to the forum
I'm starting to use ThinBasic, I also use FreeBasic.

I have this code but it gives me an error.
I need to do it like this to later call some non-windows DLLs.

'-----------------------------------------------
Uses "Console"

Declare Function timeGetTime Lib "winmm.dll" () As Long

PrintL (timeGetTime) '<--------- error here

WaitKey
'-----------------------------------------------

Thank you very much in advance.
Cheers

ErosOlmi
06-06-2022, 15:33
Ciao,

please indicate the Alias parameter in the Declare: https://help.thinbasic.com/declare.htm?zoom_highlightsub=declare
Alias name is the internal DLL name of the function.

Also return value of the function is a DWORD: https://docs.microsoft.com/en-us/windows/win32/api/timeapi/nf-timeapi-timegettime



'-----------------------------------------------
Uses "Console"


Declare Function timeGetTime Lib "winmm.dll" ALIAS "timeGetTime" () As dword


PrintL (timeGetTime)


WaitKey
'-----------------------------------------------


Let me know.
Ciao

Tolo68
06-06-2022, 17:57
Ciao,

please indicate the Alias parameter in the Declare: https://help.thinbasic.com/declare.htm?zoom_highlightsub=declare
Alias name is the internal DLL name of the function.

Also return value of the function is a DWORD: https://docs.microsoft.com/en-us/windows/win32/api/timeapi/nf-timeapi-timegettime



'-----------------------------------------------
Uses "Console"


Declare Function timeGetTime Lib "winmm.dll" ALIAS "timeGetTime" () As dword


PrintL (timeGetTime)


WaitKey
'-----------------------------------------------


Let me know.
Ciao


Thank you very much, it went well for me, even with LONG instead of DWORD
Cheers

ErosOlmi
06-06-2022, 18:40
Great.

Yes LONG or DWORD are both 32 bits (4 bytes) numbers so calling WIN32 API function will not generate errors.
But LONG is signed while DWORD is unsigned and have different number range.
Here thinBasic numeric data types and their ranges: https://help.thinbasic.com/numericvariables.htm?zoom_highlightsub=long

Ciao
Eros