Board index » cppbuilder » Question on SendMessage()

Question on SendMessage()


2006-02-16 10:11:01 PM
cppbuilder16
I just have a question which will help me in understanding the SendMessage()
to another running application.
I have two applications running and I would like to have some basic
communication between the two. So I choose the SendMessage() using the
WM_COPYDATA. Now application A will send a message to application B, when
application B receives the message a procedure is executed and may send a
message back to application A. In the meantime application A may send
another message to application B while application B is still processing the
first message.
Now it seems at times that the second message from application A is not
received in application B, and at times the message sent from application B
to application A may not be received.
So my question is, is there something else I should be doing or performing
that would ensure all the messages between the two apps are received.
I hope someone can help me in this issue.
Thanks for any information which may help me.
Mike
 
 

Re:Question on SendMessage()

"mike" < XXXX@XXXXX.COM >wrote in message
Quote
I just have a question which will help me in understanding the
SendMessage() to another running application.
And you should have posted it in the nativeapi group :^)
Quote
I have two applications running and I would like to have some basic
communication between the two. So I choose the SendMessage() using
the WM_COPYDATA. Now application A will send a message to
application B, when application B receives the message a procedure
is executed and may send a message back to application A. In the
meantime application A may send another message to application B
while application B is still processing the first message.

Now it seems at times that the second message from application A is
not received in application B, and at times the message sent from
application B to application A may not be received.
Do you use multiple threads in your applications? If not, then A is
blocked while B is processing the SendMessage call. How does A send a
second message while waiting for the first one to be processed?
--
Bruce
 

Re:Question on SendMessage()

"mike" < XXXX@XXXXX.COM >wrote:
Quote

[...] it seems at times that the second message from
application A is not received in application B, and at
times the message sent from application B to application A
may not be received.
SendMessage is just like calling a function in that execution
of the code that immediately follows the SendMessage is blocked
until SendMessage returns.
Quote
So my question is, is there something else I should be doing
or performing that would ensure all the messages between the
two apps are received.
What you have described, that A sends to B and B sends back to
A, is completely possible. In fact, you could put it into an
endless loop and the applications would still continue to
process the messages.
If one or the other of the application isn't getting a message
it's because it's not being sent (logic error) or it's being
sent to the wrong HWND.
~ JD
 

{smallsort}

Re:Question on SendMessage()

Paul wrote:
Quote
I've used PostMessage, which I believe puts the message on a queue
and it gets processed when the other thread is ready to do so,
allowing the caller to continue. I've not had much problem with
this. However I've only used this to post messages from threads to
the main VCL thread, not between applications.

I do remember a team at my place wanting to use copy data to send
messages between a number of applications (#6), but they backed out
of it for some reason. Not sure why now its too long ago, but they
went to IPC.
The WM_COPYDATA (if I remember the name correctly) is a form of IPC,
but it is an expensive way to copy data from one application to
another. To achieve that, it must allocate resources from the system
(i.e. global to all applications) temporarily. To allow releasing of
those resources, it must know when the receiving application has
received a copy of the data, so the originating application can clean
up the resources it allocated. A consequence of all that is that
WM_COPYDATA can only be sent to one window (no broadcast or multicast)
and the originating application must use SendMessage() so things are
done synchronously. Which makes it rather expensive to use if you're
trying to send data to a number of recipients: other means of IPC use
less resources (eg memory, handles) and give better performance.
In practice, WM_COPYDATA is suitable for sending a small amount of data
to a small number of applications.
Quote

Paul

"JD" < XXXX@XXXXX.COM >wrote in message
news:43f531d7$ XXXX@XXXXX.COM ...
>
>"mike" < XXXX@XXXXX.COM >wrote:
>SendMessage is just like calling a function in that execution
>of the code that immediately follows the SendMessage is blocked
>until SendMessage returns.
I suppose that's one way to describe it.
SendMessage() sends a message a window, and waits until the receiver
acknowledges it has processed the message.
 

Re:Question on SendMessage()

I've used PostMessage, which I believe puts the message on a queue and it
gets processed when the other thread is ready to do so, allowing the caller
to continue. I've not had much problem with this. However I've only used
this to post messages from threads to the main VCL thread, not between
applications.
I do remember a team at my place wanting to use copy data to send messages
between a number of applications (#6), but they backed out of it for some
reason. Not sure why now its too long ago, but they went to IPC.
Paul
"JD" < XXXX@XXXXX.COM >wrote in message
Quote

"mike" < XXXX@XXXXX.COM >wrote:
SendMessage is just like calling a function in that execution
of the code that immediately follows the SendMessage is blocked
until SendMessage returns.
 

Re:Question on SendMessage()

That sounds familiar.
"Rob" < XXXX@XXXXX.COM >wrote in message
Quote
Paul wrote:

up the resources it allocated. A consequence of all that is that
WM_COPYDATA can only be sent to one window (no broadcast or multicast)
and the originating application must use SendMessage() so things are
done synchronously. Which makes it rather expensive to use if you're
trying to send data to a number of recipients: other means of IPC use
less resources (eg memory, handles) and give better performance.