'==============================================================================
' Test #3: File Operations with Kernel32 API
' Tests CreateFile, WriteFile, CloseHandle, DeleteFile, GetTickCount
'==============================================================================
#COMPILE EXE
#DIM ALL
#INCLUDE "Windows.inc"

FUNCTION PBMAIN() AS LONG
    LOCAL hFile AS QUAD
    LOCAL written AS DWORD
    LOCAL content AS STRING
    LOCAL ticks AS DWORD
    LOCAL result AS LONG

    ' Create a test file
    hFile = CreateFileA("test_api_output.txt", %GENERIC_WRITE, 0, %NULL, %CREATE_ALWAYS, %FILE_ATTRIBUTE_NORMAL, %NULL)
    IF hFile <> %INVALID_HANDLE_VALUE THEN
        content = "Written by PBXA64 via CreateFileA/WriteFile API" + CHR$(13) + CHR$(10)
        CALL WriteFile(hFile, STRPTR(content), LEN(content), written, %NULL)
        CALL CloseHandle(hFile)
        PRINT "File written: "; written; " bytes"

        ' Clean up
        result = DeleteFileA("test_api_output.txt")
        PRINT "File deleted"
    ELSE
        PRINT "Failed to create file"
    END IF

    ' Test GetTickCount
    ticks = GetTickCount()
    PRINT "System uptime: "; ticks; " ms"

    PRINT "Test #3 PASSED: File API works"
    FUNCTION = 0
END FUNCTION
