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
Only external procedures can be assigned as CallBack.
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.
EXTERNAL FUNCTION function_name( parameters),CALLBACK id_number
EXTERNAL SUB sub_name(parameters),CALLBACK id_number
Remark. id_numberis must be a numeral 0 to 9, not containig variables.
In 32bit Windows, “ , CDECL” or“, STDCALL” can be added.
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.)
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.
Example that uses CallBack
10 OPTION CHARACTER BYTE 20 CALL EnumWindows(CallBackAdr(1),0) 30 SUB EnumWindows(IpEnumFunc, IPalam) 40 ASSIGN "user32.dll","EnumWindows" 50 END SUB 60 END 100 EXTERNAL FUNCTION GetWindowText(hWnd,IpString$,cch) 110 ASSIGN "user32.dll","GetWindowTextA" 120 END FUNCTION 200 EXTERNAL FUNCTION Enum(Handle), CALLBACK 1 210 LET Name$ = REPEAT$(CHR$(0),255) 220 IF GetWindowText(Handle, Name$, LEN(Name$))<>0 THEN 230 PRINT ImportANSI$(NAME$(1:POS(NAME$,CHR$(0))-1)) 240 END IF 250 LET Enum = -1 260 END FUNCTION
Notice.
CallBack functions cannot be invoked asynchronously.
The mistake in the number of parameters cannot be checked either on compiling or on executing.