RequestCallback - Try to install a callback

Top  Previous  Next

Syntax

 

<nAddress> := RequestCallback( <cbCallbackBlock>, [<nCallConvention>] )

 

Parameters

 

<cbCallbackBlock>

 

Codeblock to be executed when a call to the returned address takes place.

 

<nCallConvention>

 

Calling convention to be used for the callback. See Callback.ch for supported conventions. Default is CALLBACK_CALLCONVENTION_STDCALL.

 

Return value

 

A LONG value representing an address that can be called like a C function or NIL if installation of the callback fails.

 

Description

 

A call to the address returned by RequestCallback leads to the execution of <cbCallbackBlock>. Parameters given by the caller are passed on as LONG values to <cbCallbackBlock>. <cbCallbackBlock> must receive exactly the number of parameters that are passed and the calling convention specified in <nCallConvention> must match the convention expected by the caller. If the callback cannot be installed in memory, NIL is returned by RequestCallback(). A callback installed with RequestCallback should be released with ReleaseCallback if it is not used any longer to free resources.

 

For more details about callbacks turn to Callbacks.

 

Classification

 

Core

 

Category

 

Calls and Callbacks

 

Quick Info

 

Library: cckptcor.lib / cckptcor.dll

Header: Callback.ch

 

See also

 

Callback, ReleaseCallback.

 

Example

 

 

#INCLUDE "CockpitCoreLibs.ch"

#INCLUDE "Callback.ch"

 

FUNCTION Main

 

LOCAL callbackAddress

 

* Create a callback for a function to be called via CallAddress

callbackAddress := RequestCallback({|a,b,c|MyCallback(a,b,c)},CALLBACK_CALLCONVENTION_STDCALL)

 

* Throw an error if installation failed

IF callbackAddress == NIL

  SysError("Couldn't install test callback.")

ENDIF

 

* Call the function via its address passing some test parameters

? CallAddress(callbackAddress,1,2,3)

 

RETURN NIL

 

 

* Function to be called via CallAddress

STATIC FUNCTION MyCallback(a,b,c)

 

* Display the parameters passed

? a,b,c

 

* Return the sum

RETURN a+b+c