call a given callback function from an control extension (dll)

Find and share HowTos to various installations / configurations!
Search

Post Reply
4 posts • Page 1 of 1
mmarchha
Posts: 6
Joined: Mon May 16, 2011 8:33 am

call a given callback function from an control extension (dll)

Post by mmarchha »

Is there a way that a own control extension can call a callback function?

One example usescase would be that your control extension has a function that starts a calculation that might take a while an in your code you do not require the result immediately but you like to get a notification with the result.

e.g:

Code: Select all

//button clicked event
{
   .....
 
    registerResultCallBack("resultCB");   //function in your control extension to register the callback function that should be called
    startCalculation();   //function in your control extension that starts the calculation 

   .....
}


resultCB(int value)   //function that is called from your control extension as soon as the calculation has finished
{
   txt1.text = value;
}
If it is possible, are there any examples available how to implement this?

User avatar
mkoller
Posts: 741
Joined: Fri Sep 17, 2010 9:03 am

Re: call a given callback function from an control extension (dll)

Post by mkoller »

Yes, this is possible and easy to do. E.g. it's how the HTTP Server starts the registered callbacks.
To start the registered function in a new thread, call CtrlScript::startFunc(), e,g.

Code: Select all

IntegerVar value(17);
script->startFunc("funcName", &value);
If you want to pass multiple values as arguments, use:

Code: Select all

RecVar args;
args.append(new TextVar("first"));
args.append(new IntegerVar(17));

script->startFunc("funcName", &args);

mmarchha
Posts: 6
Joined: Mon May 16, 2011 8:33 am

Re: call a given callback function from an control extension (dll)

Post by mmarchha »

Works perfectly :woohoo:

One thing to add is how to get to the pointer of the script.
I'm doing it in the execute function.
e.g.:

Code: Select all

const Variable *myExternHdl::execute(ExecuteParamRec& param)
{
  ....
  CtrlScript *script = param.thread->getScript();
  ....
}
Is this the correct way?

User avatar
mkoller
Posts: 741
Joined: Fri Sep 17, 2010 9:03 am

Re: call a given callback function from an control extension (dll)

Post by mkoller »

yes

Post Reply
4 posts • Page 1 of 1