'==============================================================================
' Win32 API Core Declares for PBXA64
' Essential Windows API functions for daily work
' (C) 2026 Theo Gottwald / www.smart-package.com
'==============================================================================

' --- Kernel32: Console ---

DECLARE FUNCTION GetStdHandle LIB "kernel32.dll" ALIAS "GetStdHandle" ( _
    BYVAL nStdHandle AS DWORD _
) AS QUAD

DECLARE FUNCTION WriteFile LIB "kernel32.dll" ALIAS "WriteFile" ( _
    BYVAL hFile AS QUAD, _
    BYVAL lpBuffer AS ASCIIZ PTR, _
    BYVAL nNumberOfBytesToWrite AS DWORD, _
    BYREF lpNumberOfBytesWritten AS DWORD, _
    BYVAL lpOverlapped AS QUAD _
) AS LONG

DECLARE FUNCTION ReadFile LIB "kernel32.dll" ALIAS "ReadFile" ( _
    BYVAL hFile AS QUAD, _
    BYVAL lpBuffer AS ASCIIZ PTR, _
    BYVAL nNumberOfBytesToRead AS DWORD, _
    BYREF lpNumberOfBytesRead AS DWORD, _
    BYVAL lpOverlapped AS QUAD _
) AS LONG

DECLARE FUNCTION SetConsoleTitleA LIB "kernel32.dll" ALIAS "SetConsoleTitleA" ( _
    BYVAL lpConsoleTitle AS ASCIIZ PTR _
) AS LONG

DECLARE FUNCTION GetConsoleTitleA LIB "kernel32.dll" ALIAS "GetConsoleTitleA" ( _
    BYVAL lpConsoleTitle AS ASCIIZ PTR, _
    BYVAL nSize AS DWORD _
) AS DWORD

' --- Kernel32: File I/O ---

DECLARE FUNCTION CreateFileA LIB "kernel32.dll" ALIAS "CreateFileA" ( _
    BYVAL lpFileName AS ASCIIZ PTR, _
    BYVAL dwDesiredAccess AS DWORD, _
    BYVAL dwShareMode AS DWORD, _
    BYVAL lpSecurityAttributes AS QUAD, _
    BYVAL dwCreationDisposition AS DWORD, _
    BYVAL dwFlagsAndAttributes AS DWORD, _
    BYVAL hTemplateFile AS QUAD _
) AS QUAD

DECLARE FUNCTION CreateFileW LIB "kernel32.dll" ALIAS "CreateFileW" ( _
    BYVAL lpFileName AS WSTRING, _
    BYVAL dwDesiredAccess AS DWORD, _
    BYVAL dwShareMode AS DWORD, _
    BYVAL lpSecurityAttributes AS QUAD, _
    BYVAL dwCreationDisposition AS DWORD, _
    BYVAL dwFlagsAndAttributes AS DWORD, _
    BYVAL hTemplateFile AS QUAD _
) AS QUAD

DECLARE FUNCTION CloseHandle LIB "kernel32.dll" ALIAS "CloseHandle" ( _
    BYVAL hObject AS QUAD _
) AS LONG

DECLARE FUNCTION SetFilePointer LIB "kernel32.dll" ALIAS "SetFilePointer" ( _
    BYVAL hFile AS QUAD, _
    BYVAL lDistanceToMove AS LONG, _
    BYVAL lpDistanceToMoveHigh AS QUAD, _
    BYVAL dwMoveMethod AS DWORD _
) AS DWORD

DECLARE FUNCTION GetFileSize LIB "kernel32.dll" ALIAS "GetFileSize" ( _
    BYVAL hFile AS QUAD, _
    BYVAL lpFileSizeHigh AS QUAD _
) AS DWORD

DECLARE FUNCTION DeleteFileA LIB "kernel32.dll" ALIAS "DeleteFileA" ( _
    BYVAL lpFileName AS ASCIIZ PTR _
) AS LONG

DECLARE FUNCTION CopyFileA LIB "kernel32.dll" ALIAS "CopyFileA" ( _
    BYVAL lpExistingFileName AS ASCIIZ PTR, _
    BYVAL lpNewFileName AS ASCIIZ PTR, _
    BYVAL bFailIfExists AS LONG _
) AS LONG

DECLARE FUNCTION MoveFileA LIB "kernel32.dll" ALIAS "MoveFileA" ( _
    BYVAL lpExistingFileName AS ASCIIZ PTR, _
    BYVAL lpNewFileName AS ASCIIZ PTR _
) AS LONG

DECLARE FUNCTION GetFileAttributesA LIB "kernel32.dll" ALIAS "GetFileAttributesA" ( _
    BYVAL lpFileName AS ASCIIZ PTR _
) AS DWORD

DECLARE FUNCTION SetFileAttributesA LIB "kernel32.dll" ALIAS "SetFileAttributesA" ( _
    BYVAL lpFileName AS ASCIIZ PTR, _
    BYVAL dwFileAttributes AS DWORD _
) AS LONG

' --- Kernel32: Directory ---

DECLARE FUNCTION CreateDirectoryA LIB "kernel32.dll" ALIAS "CreateDirectoryA" ( _
    BYVAL lpPathName AS ASCIIZ PTR, _
    BYVAL lpSecurityAttributes AS QUAD _
) AS LONG

DECLARE FUNCTION RemoveDirectoryA LIB "kernel32.dll" ALIAS "RemoveDirectoryA" ( _
    BYVAL lpPathName AS ASCIIZ PTR _
) AS LONG

DECLARE FUNCTION GetCurrentDirectoryA LIB "kernel32.dll" ALIAS "GetCurrentDirectoryA" ( _
    BYVAL nBufferLength AS DWORD, _
    BYVAL lpBuffer AS ASCIIZ PTR _
) AS DWORD

DECLARE FUNCTION SetCurrentDirectoryA LIB "kernel32.dll" ALIAS "SetCurrentDirectoryA" ( _
    BYVAL lpPathName AS ASCIIZ PTR _
) AS LONG

' --- Kernel32: Process & Thread ---

DECLARE FUNCTION ExitProcess LIB "kernel32.dll" ALIAS "ExitProcess" ( _
    BYVAL uExitCode AS DWORD _
)

DECLARE FUNCTION GetCurrentProcess LIB "kernel32.dll" ALIAS "GetCurrentProcess" () AS QUAD

DECLARE FUNCTION GetCurrentProcessId LIB "kernel32.dll" ALIAS "GetCurrentProcessId" () AS DWORD

DECLARE FUNCTION GetCurrentThread LIB "kernel32.dll" ALIAS "GetCurrentThread" () AS QUAD

DECLARE FUNCTION GetCurrentThreadId LIB "kernel32.dll" ALIAS "GetCurrentThreadId" () AS DWORD

DECLARE FUNCTION Sleep LIB "kernel32.dll" ALIAS "Sleep" ( _
    BYVAL dwMilliseconds AS DWORD _
)

DECLARE FUNCTION CreateProcessA LIB "kernel32.dll" ALIAS "CreateProcessA" ( _
    BYVAL lpApplicationName AS QUAD, _
    BYVAL lpCommandLine AS ASCIIZ PTR, _
    BYVAL lpProcessAttributes AS QUAD, _
    BYVAL lpThreadAttributes AS QUAD, _
    BYVAL bInheritHandles AS LONG, _
    BYVAL dwCreationFlags AS DWORD, _
    BYVAL lpEnvironment AS QUAD, _
    BYVAL lpCurrentDirectory AS QUAD, _
    BYREF lpStartupInfo AS ASCIIZ PTR, _
    BYREF lpProcessInformation AS ASCIIZ PTR _
) AS LONG

' --- Kernel32: Memory ---

DECLARE FUNCTION GlobalAlloc LIB "kernel32.dll" ALIAS "GlobalAlloc" ( _
    BYVAL uFlags AS DWORD, _
    BYVAL dwBytes AS QUAD _
) AS QUAD

DECLARE FUNCTION GlobalFree LIB "kernel32.dll" ALIAS "GlobalFree" ( _
    BYVAL hMem AS QUAD _
) AS QUAD

DECLARE FUNCTION GlobalLock LIB "kernel32.dll" ALIAS "GlobalLock" ( _
    BYVAL hMem AS QUAD _
) AS QUAD

DECLARE FUNCTION GlobalUnlock LIB "kernel32.dll" ALIAS "GlobalUnlock" ( _
    BYVAL hMem AS QUAD _
) AS LONG

DECLARE FUNCTION VirtualAlloc LIB "kernel32.dll" ALIAS "VirtualAlloc" ( _
    BYVAL lpAddress AS QUAD, _
    BYVAL dwSize AS QUAD, _
    BYVAL flAllocationType AS DWORD, _
    BYVAL flProtect AS DWORD _
) AS QUAD

DECLARE FUNCTION VirtualFree LIB "kernel32.dll" ALIAS "VirtualFree" ( _
    BYVAL lpAddress AS QUAD, _
    BYVAL dwSize AS QUAD, _
    BYVAL dwFreeType AS DWORD _
) AS LONG

' --- Kernel32: Time ---

DECLARE FUNCTION GetTickCount LIB "kernel32.dll" ALIAS "GetTickCount" () AS DWORD

DECLARE FUNCTION GetSystemTime LIB "kernel32.dll" ALIAS "GetSystemTime" ( _
    BYREF lpSystemTime AS ASCIIZ PTR _
)

DECLARE FUNCTION GetLocalTime LIB "kernel32.dll" ALIAS "GetLocalTime" ( _
    BYREF lpSystemTime AS ASCIIZ PTR _
)

' --- Kernel32: Environment ---

DECLARE FUNCTION GetCommandLineA LIB "kernel32.dll" ALIAS "GetCommandLineA" () AS QUAD

DECLARE FUNCTION GetEnvironmentVariableA LIB "kernel32.dll" ALIAS "GetEnvironmentVariableA" ( _
    BYVAL lpName AS ASCIIZ PTR, _
    BYVAL lpBuffer AS ASCIIZ PTR, _
    BYVAL nSize AS DWORD _
) AS DWORD

DECLARE FUNCTION SetEnvironmentVariableA LIB "kernel32.dll" ALIAS "SetEnvironmentVariableA" ( _
    BYVAL lpName AS ASCIIZ PTR, _
    BYVAL lpValue AS ASCIIZ PTR _
) AS LONG

' --- Kernel32: Error ---

DECLARE FUNCTION GetLastError LIB "kernel32.dll" ALIAS "GetLastError" () AS DWORD

DECLARE FUNCTION SetLastError LIB "kernel32.dll" ALIAS "SetLastError" ( _
    BYVAL dwErrCode AS DWORD _
)

DECLARE FUNCTION FormatMessageA LIB "kernel32.dll" ALIAS "FormatMessageA" ( _
    BYVAL dwFlags AS DWORD, _
    BYVAL lpSource AS QUAD, _
    BYVAL dwMessageId AS DWORD, _
    BYVAL dwLanguageId AS DWORD, _
    BYVAL lpBuffer AS ASCIIZ PTR, _
    BYVAL nSize AS DWORD, _
    BYVAL Arguments AS QUAD _
) AS DWORD
