Re: fire asynchronous event from COM by Milos
Milos
Tue Sep 09 04:38:17 CDT 2003
Hmmm, in this case I have no idea, why it doesn't work. I use it
MULTITHREADED model without any problem, everything works and I can fire
events from any threads...
Yes, every thread may have message queue. It is sufficient to call
GetMessage or PeekMessage one time and this thread may receive the
messages...
So, here is small example, how you can manage posting/receiving of own
messages (I hope this will help you):
DWORD g_dwThread1, g_dwThread2;
LRESULT Thread_1(void *)
{
//TODO something
.
.
.
::PostThreadMessage(dwThread2, WM_USER, 0, 0);
//TODO something
.
.
.
//stop the Thread_2
::PostThreadMessage(dwThread2, WM_QUIT, 0, 0);
return 0;
}
LRESULT Thread_2(void *)
{
MSG msg;
while(::PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
{
if (msg.message == WM_USER)
{
TODO: your operations
}
::TranslateMessage(&msg);
::DispatchMessage(&msg);
//here you can put anything, but don't forget to not block this loop
}
return 0;
}
void main(void)
{
HANDLE hHandles[2];
hHandles[0] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Thread_2,
NULL, 0, &g_Thread2);
hHandles[1] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Thread_1,
NULL, 0, &g_Thread1);
::WaitForMultipleObjects(2, hHandles, TRUE, INFINITE);
CloseHandle(hHandles[0]);
CloseHandle(hHandles[1]);
}
Milos
"vittorio manzone" <vittorio.manzone@tiscali.it> wrote in message
news:48a101c3761e$e2659370$a601280a@phx.gbl...
> unfortunately, that would not help me...
> my problem is to marshal the interface, i have no idea how
> to do this!
> Alternatively, i want to put a message in the queue of the
> primary thread (does the thread has a message queue??),
> but i don't know how and what message to put!
> thanks, vittorio
>
> >-----Original Message-----
> >I think Windows CE OS is using Apartment model as default
> COM model. That
> >would cause the problem you wrote below and you would
> have to marshal each
> >interface, from where you wanted to fire any event...
> >
> >Try to call CoInitializeEx(NULL, COINIT_MULTITHREADED);
> from every threads
> >(main and worked) first. This should help you...
> >
> >
> >Milos
> >
> >"vittorio manzone" <vittorio.manzone@tiscali.it> wrote in
> message
> >news:2cfa01c373c7$81b31830$a501280a@phx.gbl...
> >> hi, i'm developing a COM object which has to fire
> >> asynchronous events to Internet Explorer.
> >> It seems that only main thread can fire events: how to
> >> tell from a worker thread to main thread to do this?
> >> I found something about firing events from a worker
> >> thread, passing him a marshaled interface, but the
> >> function needed to do this
> >> (CoMarshalInterThreadInterfaceInStream) seems to be not
> >> supported in WINCE.
> >> Can anyone help me?
> >> many thanks in advance, vittorio
> >
> >
> >.
> >