PBMAIN — Program Entry Point
Syntax:
FUNCTION PBMAIN() AS LONG ... program statements ...END FUNCTION
Description
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.
Parameters
| Parameter | Description |
|---|---|
| (none) | PBMAIN takes no parameters. For command-line arguments, use the built-in COMMAND$ function. |
Example
#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
Generated Assembly
CRT Startup & Entry Point
; 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 Prologue
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
Notes
PBMAINis only valid when#COMPILE EXEis specified. It must not appear in DLL projects.- The return type must always be
AS LONG. Returning other types will produce a compile-time error. - If
PBMAINis missing from an EXE project, the compiler reports an error at link time. - Use
COMMAND$to retrieve the full command line passed to the program. UseCOMMAND$(n)to access individual arguments by index. - PBXA64 initializes the runtime library automatically before
PBMAINis called. No manual initialization is required. - Console windows are automatically allocated for console-mode EXEs. For GUI applications, use the appropriate subsystem option.