FUNCTION PBMAIN() AS LONG ... program statements ...END FUNCTION
PBMAIN is the designated entry point for PBXA64 executable programs (compiled with #COMPILE EXE). When the operating system launches the program, execution begins at PBMAIN. This is analogous to main() in C or WinMain in traditional Windows programming.
PBMAIN must be declared as a FUNCTION returning LONG and takes no parameters. The return value is the program's exit code, where 0 typically indicates success and non-zero values indicate error conditions. This exit code is available to the calling process or shell.
Every PBXA64 executable must have exactly one PBMAIN function. DLL projects (#COMPILE DLL) do not use PBMAIN and instead rely on DllMain for initialization.
| Parameter | Description |
|---|---|
| (none) | PBMAIN takes no parameters. For command-line arguments, use the built-in COMMAND$ function. |
#COMPILE EXE
FUNCTION PBMAIN() AS LONG
LOCAL cmdLine AS STRING
PRINT "PBXA64 Program Started"
cmdLine = COMMAND$
IF LEN(cmdLine) > 0 THEN
PRINT "Arguments: "; cmdLine
ELSE
PRINT "No arguments provided."
END IF
PRINT "Program finished."
FUNCTION = 0 ' Exit code 0 = success
END FUNCTION
; The linker sets the PE entry point to __pb_crt_startup
__pb_crt_startup:
sub rsp, 288h ; Shadow space for WinAPI calls
xor ecx, ecx ; dwFlags = 0 (console app)
call [__imp_SetConsoleMode] ; Initialize console I/O
add rsp, 288h
xor ecx, ecx ; Clear RAX for return value
call PBMAIN ; Jump to user code
mov ecx, eax ; Exit code = PBMAIN return value
call [__imp_ExitProcess] ; Terminate process
ret
PBMAIN:
push rbp
mov rbp, rsp
sub rsp, frame_size ; Allocate stack frame for LOCALs
; ... body ...
mov rax, [rbp - return_offset] ; Load FUNCTION = value
add rsp, frame_size
pop rbp
ret
PBMAIN is only valid when #COMPILE EXE is specified. It must not appear in DLL projects.AS LONG. Returning other types will produce a compile-time error.PBMAIN is missing from an EXE project, the compiler reports an error at link time.COMMAND$ to retrieve the full command line passed to the program. Use COMMAND$(n) to access individual arguments by index.PBMAIN is called. No manual initialization is required.