'==============================================================================
' Test #1: WinAPI Console - WriteFile via GetStdHandle
'==============================================================================
#COMPILE EXE
#DIM ALL

DECLARE FUNCTION GetStdHandle LIB "kernel32.dll" ALIAS "GetStdHandle" (BYVAL nStdHandle AS LONG) AS QUAD
DECLARE FUNCTION WriteFile LIB "kernel32.dll" ALIAS "WriteFile" (BYVAL hFile AS QUAD, BYVAL lpBuffer AS ASCIIZ PTR, BYVAL nBytes AS LONG, BYREF lpWritten AS LONG, BYVAL lpOverlapped AS QUAD) AS LONG
DECLARE FUNCTION ExitProcess LIB "kernel32.dll" ALIAS "ExitProcess" (BYVAL uExitCode AS LONG)
DECLARE FUNCTION lstrlenA LIB "kernel32.dll" ALIAS "lstrlenA" (BYVAL lpString AS ASCIIZ PTR) AS LONG

%STD_OUTPUT_HANDLE = -11&
%NULL = 0

FUNCTION PBMAIN() AS LONG
    LOCAL hOut AS QUAD
    LOCAL written AS LONG
    LOCAL msg AS STRING

    msg = "PBXA64 WinAPI Test - Console Output OK"
    hOut = GetStdHandle(%STD_OUTPUT_HANDLE)
    CALL WriteFile(hOut, STRPTR(msg), lstrlenA(STRPTR(msg)), written, %NULL)

    PRINT "Test #1 PASSED"
    FUNCTION = 0
END FUNCTION
