🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.nativeapi
6 messages
6 total messages Started by Marc Sun, 28 Oct 2007 15:58
IPC, using Application->OnMessage
#1139
Author: Marc
Date: Sun, 28 Oct 2007 15:58
73 lines
3467 bytes
Hi all

After another sleepless night here another question:

I try to implement IPC between my two processes.
For a test I implemented a simple form with one button that sends a message
     PostMessage(HWND_BROADCAST, msgTEST, 0, 0);
and a OnMessage handle that receives this message.
     if (Msg.message == msgTEST)
     {
               OutputDebugString("Message received");
               Handled=true;
     }
I use HWND_BROADCAST because in future the sender and receiver will be in 
two separate processes.

msgTEST is registered using
     msgTEST = RegisterWindowMessage("msgTest");

If I run the application like this and press the button, I receive one 
OutputDebugString. This is what I expected.

But when I create a second form, and place a TTimer component on it, I 
receive the OutputDebugString twice. If I place two TTimer component on it, 
I receive the OutputDebugString three times. The second form is not event 
referenced in my first form.
Curious enough this does not happen with a TButton component, so it depends 
on the component I place on this second form.

Does this make sense ?
Is not the "Handled=true" statement supposed to prevent the message from 
being sent to another Window ?

Rds
Marc


//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
UINT msgTest;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
     : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::AppMessage(tagMSG &Msg, bool &Handled)
{
     if (Msg.message == msgTest)
     {
               OutputDebugString("Message received");
               Handled=true;
     }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
     msgTest                  = RegisterWindowMessage("msgTest");
     Application->OnMessage   = AppMessage;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
     PostMessage(HWND_BROADCAST, msgTest, 0, 0);
}
//---------------------------------------------------------------------------
Re: IPC, using Application->OnMessage
#1140
Author: Bob Gonder
Date: Sun, 28 Oct 2007 17:26
24 lines
1739 bytes
Marc wrote:

>I try to implement IPC between my two processes.

>I use HWND_BROADCAST because in future the sender and receiver will be in 
>two separate processes.

If in the future they will be on different computers, this won't work.

>If I run the application like this and press the button, I receive one 
>OutputDebugString. This is what I expected.
>
>But when I create a second form, and place a TTimer component on it, I 
>receive the OutputDebugString twice.

Every top-level window (form) gets the message.

>Is not the "Handled=true" statement supposed to prevent the message from 
>being sent to another Window ?

No.
It is a BROADCAST just like radio or TV.
Your watching it doesn't stop others from viewing it too.
Every running (windowed) application on your machine will get your spam.
Re: IPC, using Application->OnMessage
#1141
Author: Marc
Date: Sun, 28 Oct 2007 17:36
50 lines
2602 bytes
Hi Bob

Thank you for your reply.

> If in the future they will be on different computers, this won't work.


This is OK as the two processes will run on the same computer.
If not what alternative would you recommend? Using IP messaging ?

> It is a BROADCAST just like radio or TV.
> Your watching it doesn't stop others from viewing it too.
> Every running (windowed) application on your machine will get your spam.

I see.
I helped myself right now in looking if the Msg.message + Msg.time is 
different before continuing... not very nice, but it helps.

Rds
Marc


"Bob Gonder" <notbg@notmindspring.invalid> schrieb im Newsbeitrag 
news:9ig9i3hr3qf15n249d5dllfuf2a46upfs8@4ax.com...
> Marc wrote:
>
>>I try to implement IPC between my two processes.
>
>>I use HWND_BROADCAST because in future the sender and receiver will be in
>>two separate processes.
>
> If in the future they will be on different computers, this won't work.
>
>>If I run the application like this and press the button, I receive one
>>OutputDebugString. This is what I expected.
>>
>>But when I create a second form, and place a TTimer component on it, I
>>receive the OutputDebugString twice.
>
> Every top-level window (form) gets the message.
>
>>Is not the "Handled=true" statement supposed to prevent the message from
>>being sent to another Window ?
>
> No.
> It is a BROADCAST just like radio or TV.
> Your watching it doesn't stop others from viewing it too.
> Every running (windowed) application on your machine will get your spam.
>
> 
Re: IPC, using Application->OnMessage
#1142
Author: Bob Gonder
Date: Sun, 28 Oct 2007 18:01
24 lines
1725 bytes
Marc wrote:

>This is OK as the two processes will run on the same computer.
>If not what alternative would you recommend? Using IP messaging ?

Named Pipes are good if you need to send data.
Otherwise Named Mutex or Event for simple signaling.
See:
	CreateNamedPipe

	CreateEvent
	OpenEvent

	CreateMutex
	OpenMutex

	CreateSemaphore
	OpenSemaphore

>I helped myself right now in looking if the Msg.message + Msg.time is 
>different before continuing... not very nice, but it helps.

You might have 2 different messages, one for each process.
Each process looks only for the other process' message, not it's own.
Re: IPC, using Application->OnMessage
#1144
Author: Marc
Date: Mon, 29 Oct 2007 16:57
38 lines
2100 bytes
Bob

Considering your last post about processes on different computers I started 
implementing a socket based IPC, using ICS.
Thanks again for your valuable help :-)

Rds
Marc


"Bob Gonder" <notbg@notmindspring.invalid> schrieb im Newsbeitrag 
news:bni9i351dec9fe1amoaucsqrgbnk53p3au@4ax.com...
> Marc wrote:
>
>>This is OK as the two processes will run on the same computer.
>>If not what alternative would you recommend? Using IP messaging ?
>
> Named Pipes are good if you need to send data.
> Otherwise Named Mutex or Event for simple signaling.
> See:
> CreateNamedPipe
>
> CreateEvent
> OpenEvent
>
> CreateMutex
> OpenMutex
>
> CreateSemaphore
> OpenSemaphore
>
>>I helped myself right now in looking if the Msg.message + Msg.time is
>>different before continuing... not very nice, but it helps.
>
> You might have 2 different messages, one for each process.
> Each process looks only for the other process' message, not it's own.
>
> 
Re: IPC, using Application->OnMessage
#1145
Author: Remy Lebeau (TeamB)
Date: Mon, 29 Oct 2007 17:15
28 lines
1850 bytes
"Marc" <info@mawnet.com> wrote in message 
news:4724b19d$1@newsgroups.borland.com...

> I use HWND_BROADCAST because in future the
> sender and receiver will be in two separate processes.

That does not necessarily mean that HWND_BROADCAST is the best choice.  It 
would be better if the sender knew ahead of time the HWND that the receiver 
is actually using to receive messages with.

> But when I create a second form, and place a TTimer component on it,
> I receive the OutputDebugString twice. If I place two TTimer component
> on it, I receive the OutputDebugString three times.

What is your TTimer actually doing?

> The second form is not event referenced in my first form.

It doesn't have to be.

> Curious enough this does not happen with a TButton component,
> so it depends on the component I place on this second form.

What component are you putting on the second form to reproduce the problem?


Gambit 
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads