ADE User Guide > ADE Server Class Reference > CAEngine

Other languages:
English • ‎中文

(New to ADE 4.3)

This feature is currently experimental

CAEngine::SetCallbackObject(IUnknown* pCallbackObj)

When ADE is evaluating a model or typescript, various functions may be encountered that would invoke a user interaction when the model is evaluated in desktop Analytica. For example, if an expression contains a MsgBox function, Analytica would display a question to the user in a message box and obtain a response from the user. Since ADE does not have a user interface, it cannot directly process these user interactions. CAEngine::SetCallbackObject provides a way for you to receive a callback when events like this occur so that your program can take the desired action, such as displaying a message box to the user.

ADE defines various callback interfaces for various events (functions or commands) that may trigger a user-interface interaction. At present, the following interfaces exist:

Note: the plan is that once this is moved past the experimental stage, other callback interfaces will be added, for things such as ShowProgressBar, AskMsgNumber, AskMsgText, display warning, Show command (show result, show definition, show graph), etc.


To use a callback, you must implement a COM class that derives from the interfaces you want to handle and implements their methods. As a COM class, it must implement the standard IUnknown::QueryInterface COM method, which must report that it supports each of these interfaces. You then instantiate an instance of that class and pass it to this method.

In C++

#import "ADE.exe"
using namespace ADE;
class MyCallback : public IAMsgBoxCallback {
   STDMETHODIMP QueryInterface(REFIID riid, LPVOID* ppv) 
       if (riid==IID_IUnknown) {
           *ppv = (LPVOID)dynamic_cast<IUnknown*>(this);
       } else if (riid == __uuidof(IAMsgBoxCallback)) {
           *ppv = (LPVOID)dynamic_cast<IAMsgBoxCallback*>(this);
       } else {
           *ppv = NULL;
           return E_NOINTERFACE;
       return S_OK;
   STDMETHOD(ShowMsgBox)(BSTR title, BSTR text, LONG buttons, LONG* /*out*/ whatPressed) 
       *whatPressed = MessageBox(NULL,text,title,buttons);
       return S_OK;
void main()
    CAEnginePtr pAde(__uuidof(_CAEngine));
    pAde->SetCallbackObject(new MyCallback);

In C#

We have not yet been able to get this to work from .NET -- which is why this is still considered an experimental feature. We believe the C# implementation should look something like what we show here. Since we haven't gotten it to successfully work yet, we're obviously not quite there. Our two theories are that some additional .NET attribute decoration on the class is still required, or that some additional registry settings need to be configured. We provide this here to aid with experimentation.

using ADE;
namespace MyApp
   [Guid("2576608A-833D-4742-BF63-794869E642C3")]    // use the Create GUID tool in DevStudio to create your own unique GUID
   public class MyCallback : IAdeMsgBoxCallback
       public int ShowMsgBox(string title, string text, int buttons)
           MessageBoxButtons btns = (MessageBoxButtons)buttons;
           DialogResult res = MessageBox.Show(text, title, btns);
           return (int)res;
   class Program
       static void Main(string[] args)
           CAEngine ade = new CAEngine();
           ade.SetCallbackObject(new MyCallback());

You are not allowed to post comments.