
How automation client recognizes that automation server unloaded
How automation client recognizes that automation server has been
manually unloaded by the user?
Hi all,
I have client C++ application, which connects to whatever automation server.
For it, I wrote simple UtAtomation class which encapsulates IDispatch
interfeace.
Everything works good, but if user manually unloads Automation server, and
continue to work with our application, he/she gets messages likes as "RPC
is unavailable...".
How my application may recognize that server has been unloaded ?
My solution is :
static UtAutomation* m_pAutomation;
className:method {
// init UtAutomation, create object ,save in the class members
IUknown*,IDispatch*...
m_pAutomation = new UtAutomation("..");
ASSERT(m_pAutomation, UtIncorrectCodeError);
result = m_pAutomation -> CreateObject();
>> ..........here goes automation scripts.....
here additional worker thread runs, whith the next thread procedure :
{
// check whether server still running
while(m_pAutomation -> isServerLoaded(false)) {;}
// send message to main thread - server has been unloaded , do something
::PostMessage(*(HWND*) pWin,WM_WORD_UNLOADED_BY_USER,0,0);
return 0;
Quote:
}
below code for UtAutomation::isServerLoaded method :
bool UtAutomation::isServerLoaded(bool i_showError)
{
IUnknown *pUnknownInterface;
if (!m_pUnknownInterface) return false;
HRESULT hr;
hr = ::GetActiveObject (m_classID, NULL,&pUnknownInterface);
if (FAILED(hr) || pUnknownInterface != m_pUnknownInterface)
{
if (m_pUnknownInterface) m_pUnknownInterface->Release();
if (m_pDispatchInterface) m_pDispatchInterface->Release();
if (i_showError)
MessageBox(0,"COM Server has been unloaded.","Automation
Error",MB_OK);
return false;
}
return true;
Quote:
}
When ::isServerLoaded is called from main thread everuthing is ok, but when
it
is called from thread GetActiveObject returns failed HRESULT, even if
server is loaded.
Any advice gratefully accepted. Thanks...