I have a COM+ application which I instantiate with
CoCreateInstance(CLSID_TheComponent, NULL, CLSCTX_ALL, IID_ITheComponent, &m_TheComponent);
This is followed by event initialization
CoCreateInstance(CLSID_TransientSubscription,NULL,CLSCTX_ALL,IID_ITransinetSubscription,&Trans);
...some more code that eventually registers some CLSID_Events, IID__IEvents.
I have an MFC application with following:
OnBtn1Clicked()
{
m_TheComponent->DoSomething();
}
also in the Dialog class there is
class CMFCMyDialog : public CDialogEx, _IEvents
{
...
virtual HRESULT STDMETHODCALLTYPE OnSomething(); // abstract in _IEvents
When running, after clicking Btn1 two things happen: 1.OnSomething()
is fired, and 2. the COM+ does a bunch of other stuff it should do. So far so good.
The interesting thing is that 1 & 2 happen only after OnBtn1Clicked()
is exited. Even if i put a sleep()
after DoSomething()
or if I attempt to call DoSomething()
within a different thread, 1 + 2 don't happen only after OnBtn1Clicked()
is cleared.
From The COM component log I see it reaches and enters it's OnSomething()
call but does not exist it (and of course does not reach the client side sink) until OnBtn1Clicked()
is cleared. Once cleared, the sink is reached and the COM component continues execution.
All this would not be a problem since I can wait for after the button is clicked, but I need to implement this in a console application client. When implementing in a console application I was not able to make 1 and/or 2 happen. Only after I kill the client process (!) 2 happens (the COM+ continues processing) but of course client side OnSomething()
does not since the process is dead.
Any idea what happens when OnBtn1Clicked()
is cleared that affects the COM+?
MyConsoleClass::MyConsoleClass()
{
new thread(&MyConsoleClass::Run, this);
}
void MyConsoleClass::Run()
{
m_ThreadId = GetCurrentThreadId();
m_IsActive = true;
MSG msg;
BOOL bRet;
while (m_IsActive)
{
if (bRet = GetMessage(&msg, NULL, 0, 0) != 0)
{
if (bRet == -1)
// error
else if (msg.message == WM_QUIT)
m_IsActive = false;
else if (msg.message == DO_SOMETHING)
DoSomething(msg.wParam);
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
}
void MyConsoleClass::Invoke(const actionEnum action, const void *params)
{
PostThreadMessage(m_ThreadId, action, (WPARAM)params, NULL);
}