Forums: Forum of Decimal BASIC (Thread #37884)

Trying to Get System Time with API (2016-07-13 21:37 by toml12953 #78338)

I'm trying to get the Windows system time (UTC seconds since 1 January 1601) using an API call but when I run it, I get an EXTYPE -9900 error. Can anyone see what I'm doing wrong? I know I'll have to convert the output buffer into an actual value once I get it working but the call shouldn't error out in any case. Thanks for any help!

DECLARE EXTERNAL FUNCTION SystemTime$
PRINT SystemTime$
END
EXTERNAL FUNCTION SystemTime$
OPTION CHARACTER BYTE
FUNCTION GetSystemTime(n,s$)
ASSIGN "kernel32.dll","GetSystemTime"
END FUNCTION
LET s$=REPEAT$(" ", 50)
LET n=GetSystemTime(50,s$)
LET SystemTime$=s$(1:n)
END FUNCTION

Reply to #78338×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

Re: Trying to Get System Time with API (2016-07-14 04:13 by TomL_12953 #78341)

[Reply To Message #78338]

I figured it out. GetSystemTimeAsFileTime doesn't return a value. It just fills an 8-byte buffer with the number of milliseconds since 1/1/1601. The program below prints the correct value.

DECLARE EXTERNAL FUNCTION systemtime

PRINT USING "###########.####":systemtime

END

EXTERNAL FUNCTION systemtime

OPTION CHARACTER BYTE

FUNCTION GetSystemTime(s$)
ASSIGN "kernel32.dll","GetSystemTimeAsFileTime"
END FUNCTION

LET s$=REPEAT$(" ", 8)
LET temp=GetSystemTime(s$)
LET temp = 0
FOR i=1 TO 8
LET temp = temp + ORD(s$(i:i))*256^(i-1)
NEXT i

LET systemtime = temp / 10000000

END FUNCTION
Reply to #78338

Reply to #78341×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login