CallBack functions (original enhancement)

CallBack functions are those that can be invoked from inside of DLLs.
We can use at most 10 call-back functions, which are identified by numbers from 0 to 9.

Indicates CallBack functions

We write the identification number for the call-back function at the tail of the procedure that is used for a CallBack function in the following form. The identification number must be a constant within from 0 to 9.
FUNCTION function_name( parameters),CALLBACK id_number
SUB sub_name(parameters),CALLBACK id_number
Either internal or external procedures can be assigned as CallBack.
Arguments are always passed by value. A pointer to a null-terminated string can be assigned to a string parameter. Any other arguments are assumed to be 32bit signed integers and should be assigned to numerical parameters. (Note that a pointer except a pointer that points a null-terminated string must be assigned to a numerical parameter.)
An argument larger than 32 bits should be assigned to numerical parameters by separating into 32 bits.
The byte size of the whole arguments including padding must coincide with the number of parameters multiplied by 4.
Truth values can be accepted as a numerical value. Normally non-zero means true.
Conversely, when a DLL requires a truth value, we define the function such that it returns -1 or 1 if the result is true, 0 if false.

Acquisition of the address of CallBack functions

We acquire the address of a CallBack function using a CallBackAdr function, of which parameter is the identification number of it.
We are not allowed to indicate an internal procedure that is located in a different program unit.

Example that uses CallBack

110 LET Name$ = REPEAT$(CHR$(0),255)
120 CALL EnumWindows(CallBackAdr(9), 0)
130 SUB EnumWindows(IpEnumFunc, IPalam)
140    ASSIGN "user32.dll","EnumWindows"
160 FUNCTION GetWindowText(hWnd,IpString$,cch)
170    ASSIGN "user32.dll","GetWindowTextA"
190 FUNCTION Enum(Handle), CALLBACK 9
200    IF GetWindowText(Handle, Name$, LEN(Name$))<>0 THEN
210       PRINT NAME$(1:POS(NAME$,CHR$(0))-1)
220    END IF
230    LET Enum = -1
250 END

CallBack functions cannot be invoked asynchronously.
The mistake in the number of parameters cannot be checked either on compiling or on executing. That may damage the computer system.