Board index » cppbuilder » Message Loop

Message Loop


2006-03-28 11:36:51 PM
cppbuilder55
Hi,
I need to know when windows message loop will be processed.
Main Thread
=========
HWND gHandle ;
void __fastcall TForm1::TForm1 ()
{
gHandle = AllocateHWND(MyWndProc) ;
}
void __fastcall TForm1::OnButtonClick (TSender *Sender)
{
IMyComObjectPtr lObj ; //..COM Object
CoMyComObject::Create (&lObj) ;
lObj->Object1->Member1 = TVariant(2) ;
lObj->Object1->Member2 = TVariant(2) ;
lObj->Object2->Member1 = TVariant(2) ;
lObj->Object2->Member2 = TVariant(2) ;
lObj->Member1 = 5
}
void MyWndProc (TMessage &Message)
{
switch (Message.Msg) {
case 7001 : Operation1() ; break ;
}
}
Seperate Thread
============
Message will be posted to Allocate Handle when ever new data received from
.NET component
PostMessage ( gHandle, 7001, 0,0 ) ;
When a button is clicked, OnButtonClick is fired. Sometime even before
method gets completed, MyWndProc is called with Message.Msg value 7001. I
am not invoking any Processmessages in those COM calls.
Which is causing MyWndProc message to process before completing that
onButtonClick?
Regards,
Saravanan A
 
 

Re:Message Loop

"Saravanan" < XXXX@XXXXX.COM >wrote in message
Quote
I need to know when windows message loop will be processed.
It is processed inside of the project's WinMain() function.
Quote
When a button is clicked, OnButtonClick is fired. Sometime even before
method gets completed, MyWndProc is called with Message.Msg value
7001.
The only way that can happen is if the OnClick event handler to doing
something that causes the main thread to process new messages from the queue
immediately, either directly or indirectly.
Quote
Which is causing MyWndProc message to process before completing
that onButtonClick?
If the code you shows is all of the code that you have, then something
inside the COM object is pumping the queue for new messages. That is the
only way it can be happening.
Gambit
 

Re:Message Loop

Hi,
Thanx for your reply.
Quote
>If the code you shows is all of the code that you have, then something
>inside the COM object is pumping the queue for new messages. That is the
>only way it can be happening.
COM object is not pumping messages. That is for sure.
I am accessing the COM object using imported type library interface. Is
there any case that on error conditions, it (TComInterface) forces main
thread to process the messaging queue.
Additional information is whenever this message queue is processed before
that method completion, it throws a COM exception(Unspecified error).
Regards,
Saravanan A
 

{smallsort}

Re:Message Loop

"Saravanan" < XXXX@XXXXX.COM >wrote in message
Quote
COM object is not pumping messages. That is for sure.
How do you know that?
Quote
I am accessing the COM object using imported type library interface.
So? It is still an object nontheless, and COM does require the message
queue for apartment-threaded objects.
Quote
Is there any case that on error conditions, it (TComInterface) forces
main thread to process the messaging queue.
TComInterface does not do anything with messages at all. But the COM object
itself might be.
Gambit
 

Re:Message Loop

Hi,
Quote
COM object is not pumping messages. That is for sure.
>How do you know that?
I have implemented that COM object in VC
Quote
Is there any case that on error conditions, it (TComInterface) forces
main thread to process the messaging queue.
>TComInterface does not do anything with messages at all. But the COM
>object
>itself might be.
How do i make sure or verify that COM forces main thread to process the
message queue if COM forces to process the message
Regards,
Saravanan A
 

Re:Message Loop

"Saravanan" < XXXX@XXXXX.COM >wrote in message
Quote
I have implemented that COM object in VC
COM itself could be pumping the queue while instantiating the object. You
did say that it is a .NET object, right? Hosting .NET objects in non-.NET
environments takes more work.
Quote
How do i make sure or verify that COM forces main thread to process the
message queue if COM forces to process the message
I think the issue is self-evident, by the fact that your code is running
message-based operations while a message-based event handler is already
running. If you comment the code from the event handler, and the behavior
goes away, then the COM object is definately at fault.
Gambit