|
Post by Walt Decker on Apr 28, 2023 15:10:27 GMT -5
CALLBACK is not used much here, but someone should give it a go.
|
|
|
Post by Walt Decker on May 3, 2023 14:54:35 GMT -5
SYNTAX: CALLBACK CodePtr, FunctionName(DataType, DataType, DataType ...) returns DataType
CALLBACK = LB function CodePtr = code address of function DataType = type of data, not variable name, of expected data Return DataType = type of data to return to the function.
USAGE:
Obtain a series of data from a DLL function and indicate through the return value whether the function is to continue executing or perform some actlon.
This function is required for most of the Windows OS Enum and application hook functions. When invoking one of these function the OS does not care about the data types in the function, it only cares about the address of the function that receives the data. This works because, unlike variable space in ram, code space in ram does not move.
From LB Help '[/div][div] texteditor #win.te, 10, 10, 250, 250 open "Enum Windows Example" for window as #win print #win, "trapclose [quit]" 'set the variable named address to be the memory address for 'enumWndProc() using TYPES handle and ulong, and set 'the return TYPE of enumWndProc() to be a boolean callback address, enumWndProc(handle, ulong), boolean 'call EnumWindows, which in turn calls back into the 'BASIC function at address. calldll #user32, "EnumWindows", _ address as ulong, _ 0 as long, _ result as boolean wait [quit] close #win end
function enumWndProc(hwnd, lparam) labelBuffer$ = space$(71) calldll #user32, "GetWindowTextA", _ hwnd as ulong, _ labelBuffer$ as ptr, _ 70 as long, _ result as long if left$(labelBuffer$, 1) <> chr$(0) then print #win.te, labelBuffer$ call setCount getCount()+1 end if if getCount() = 5 then enumWndProc = 0 'returning 0 causes EnumWindows to return else enumWndProc = 1 end if end function
sub setCount value count(0) = value end sub
function getCount() getCount = count(0) end function[/div][div]'
CALLBACK is not limited to API functions. It can also be used to regulate program flow in an application. For usage see:
|
|