ReplaceCallback - Replace an existing callback with a new one

Top  Previous  Next

Syntax

 

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

 

Parameters

 

<nAddress>

 

Address of old callback to be replaced with new one.

 

<cbCallbackBlock>

 

New codeblock to be executed when a call to <nAddress> takes place.

 

<nCallConvention>

 

Calling convention to be used for the callback. See Callback.ch for supported conventions. Default is the convention currently used for the installed callback at address <nAddress>.

 

Return value

 

Always NIL. A SysError is thrown if an error occurs.

 

Description

 

ReplaceCallback can be used to change the codeblock to be executed when a certain callback is called. This can be helpful if the first-time codeblock must do some initializing. It can then call ReplaceCallback to install a different codeblock that takes care of subsequent calls. If an error condition is met (e.g. unknown <nAddress> given), SysError is called.

 

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, RequestCallback, ReleaseCallback.

 

Example

 

 

#INCLUDE "CockpitCoreLibs.ch"

#INCLUDE "Callback.ch"

 

FUNCTION Main

 

LOCAL callbackAddress

 

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

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

                           "Test Callback")

 

* Call the function via its address passing some test parameters

? CallAddress(callbackAddress,1,2,3)

 

* Replace the initial codeblock with a new one

ReplaceCallback(callbackAddress,{|a,b|MyCallback2(a,b)})

 

* Call the second function via its address passing a different number of parameters

? CallAddress(callbackAddress,4,5)

 

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

 

 

* Second function to be called via CallAddress

STATIC FUNCTION MyCallback2(a,b)

 

* Display the parameters passed

? a,b

 

* Return the product

RETURN a*b