CAEngine::SetCallbackObject
(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.
Usage
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 { public: 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; } AddRef(); 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() { CoInitialize(NULL); CAEnginePtr pAde(__uuidof(_CAEngine)); pAde->SetCallbackObject(new MyCallback); ... CoUninitilize(); }
Enable comment auto-refresher