The Interop::GetCallbackPtr function returns a pointer to a native function for callback use. This is useful when calling a function in an external library (like the Windows API) that requires a function address as parameter to send its result.
[number] GetCallbackPtr( [string] FunctionName );
The address of a function to use as parameter in Call. This value must be used immediately and not stored for later or repeated use.
This function typically fails for the following reasons:
Developers who use callback functions must be very careful about the functions they call and the parameters they accept. Here is a list of requirements for this function to succeed:
The address returned by this function must be used immediately. This means that the only place allowed for the call is Interop.Call and Interop.Call2.
Remember that the use of callback functions is restricted to synchronous calls. This means that all the calls made to the callback function must be done before the callee returns. Asynchronous calls are not permitted and must not be attempted in any circumstances.
This code traces the list of handles (numbers) of all the top-level windows currently displayed in the user's session.
function OnEvent_Initialize(MessengerStart) { Debug.Trace("EnumWindows result:"); Interop.Call("User32.dll", "EnumWindows", Interop.GetCallbackPtr("EnumCallback"), 0); } function EnumCallback(hWnd, lParam) { Debug.Trace(" - window handle: " + hWnd); return true; }
Object | Interop |
---|---|
Availability | Messenger Plus! Live 4.60 |