Linux equivalent of Windows SendMessage

B

B Rubble

I am trying to port some apps from Windows to Linux.

In Windows I can define a custom message and register it with the OS and by
using SendMessage(HWND_BROADCAST,...) I can send messages to multiple
applications.

How to do the same thing in Linux ? ie How to define a custom message,
register it and broadcast that message to multiple applications?

================================================================
// Following code is copied from a demo program written in Borland C++
Builder Ver 6
const AnsiString PrivateMessageID =
"{7395314D-3A02-4887-A60F-BD029D1FF009}";
int N =0;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
PrivateMessage = RegisterWindowMessage(PrivateMessageID.c_str());
}

//---------------------------------------------------------------------------
void __fastcall TForm1::WndProc(Messages::TMessage& Message)
{
if (Message.Msg == PrivateMessage) {
if (Message.WParam ==0){ // Display only the first message
AnsiString S;
S.sprintf("%d - WParam: %.05d LParam: %.05d at %s",
N, Message.WParam,
Message.LParam, AnsiString(Now()).c_str()
);
Memo1->Lines->Add(S);
}
N++;
}
TForm::WndProc(Message);
}

//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TDateTime T0, T1;
T0 = Now();
for (int i=0; i<100; i++)
SendMessage(HWND_BROADCAST,PrivateMessage,i,i*10);
T1 = Now();
AnsiString S;
DateTimeToString(S, "ss:zzz",T1-T0);
Caption = S; // <--- It display around 02.804 sec on 2GHz notebook PC
}

================================================================
 
A

Antoninus Twink

How to do the same thing in Linux ? ie How to define a custom message,
register it and broadcast that message to multiple applications?

There are several ways of doing inter-process communications in *nix,
e.g. sockets, message queues, shared memory, ...

You might want to read up on this on the web or in a book, and post
again if you have any specific questions about what you read.

Good luck.
 
I

Ian Collins

B said:
I am trying to port some apps from Windows to Linux.

In Windows I can define a custom message and register it with the OS and by
using SendMessage(HWND_BROADCAST,...) I can send messages to multiple
applications.

How to do the same thing in Linux ? ie How to define a custom message,
register it and broadcast that message to multiple applications?
One of the Linux groups or comp.unix.programmer would be the best places
to ask this.
 
G

Guest

B Rubble said:
How to do the same thing in Linux ? ie How to define a custom message,
register it and broadcast that message to multiple applications?

You can use pipes, fifos, sockets, shared pseudo-memory (via mmap), or
just simple signals. You only have to choice the best way in according
to your purpose.

--
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS/CM/CC/E/IT/LS/M d-(--) C++++$ UBL++++$ P++++ L+++++$ E--- W+++ w--
PS+++ PE-- Y++ PGP+++ R++ tv-- b++>+++ D+ G>+++ e++>+++++ h* r++ z+++
------END GEEK CODE BLOCK------
 
M

Mark Wooding

B Rubble said:
In Windows I can define a custom message and register it with the OS and by
using SendMessage(HWND_BROADCAST,...) I can send messages to multiple
applications.

How to do the same thing in Linux ? ie How to define a custom message,
register it and broadcast that message to multiple applications?

This doesn't seem like a question best dealt with in this newsgroup; I
suspect that comp.os.linux.development.apps is more appropriate. I've
set followups accordingly.

There are many mechanisms for interprocess communication available in
Linux.

The closest direct equivalent to SendMessage is probably the XSendEvent
function in Xlib, but that doesn't have a broadcast facility; working
out the `toplevel' windows is nontrivial, since the direct children of
the root window are mostly owned by the window manager (to contain title
bars and suchlike).

A more appropriate mechanism, still at the Xlib layer (and therefore
coping properly with X's client-server nature) would be to set a
property on a relevant window (maybe the root window, if there's no
better choice); name the property with an atom which identifies your
application. Interested applications can select PropertyNotify events
on this window, compare the atom in the event when it arrives, and fetch
the property value to find out what happened if they're interested.

I believe that the opendesktop.org Dbus system does the sort of thing
you're after, but I don't know much about it.

Finally, you could listen on a socket, and interested applications could
connect to it to receive your notifications.

[snip C++ -- not C -- code]

-- [mdw]
 
C

CBFalconer

You can use pipes, fifos, sockets, shared pseudo-memory (via
mmap), or just simple signals. You only have to choice the best
way in according to your purpose.

Please don't answer off-topic queries in c.l.c, apart from advising
them of suitable newsgroups, and the fact that they are off-topic.
c.l.c is limited to the portable C language, as defined in the
various ISO C standards, and K&R (for C before the ISO standards).
Things that are system or hardware specific are off-topic.

The OP should use a newsgroup that deals with his Linux, or with
comp.unix.programmer.
 
R

Richard

CBFalconer said:
Please don't answer off-topic queries in c.l.c, apart from advising
them of suitable newsgroups, and the fact that they are off-topic.
c.l.c is limited to the portable C language, as defined in the
various ISO C standards, and K&R (for C before the ISO standards).
Things that are system or hardware specific are off-topic.

No they are not. Not if they are related to the C Language.
The OP should use a newsgroup that deals with his Linux, or with
comp.unix.programmer.

Or here which deals with C with a high population of real world C
programmers who can offer valuable, practical advice to the help seeker.
 
K

Kaz Kylheku

Please don't answer off-topic queries in c.l.c, apart from advising
them of suitable newsgroups, and the fact that they are off-topic.

Go chuck yourself, Fucky!
 
K

Kaz Kylheku


Hooray, no more boorish, inane followups from an imbecile who isn't worth a
curly hair ripped out of my programming ass.

His embarassing name will no longer appear near mine in Usenet threads.

But wait, is this piece of ``news'' software up to the plonking job?

X-Mailer: Mozilla 4.75 [en] (Win98; U)

Or am I merely in the /mental/ killfile? The mental killfile can't hold more
than three or four names before Chucky gets all confused. I will be
disappointed if Chucky slips up and follows up.

That will be a sad day, when once again I see something I wrote, re-entering my
news server, quoted in its entirety, with one line of some insipid drivel
appended to it.
 
R

Richard

Kaz Kylheku said:

Hooray, no more boorish, inane followups from an imbecile who isn't worth a
curly hair ripped out of my programming ass.

His embarassing name will no longer appear near mine in Usenet threads.

But wait, is this piece of ``news'' software up to the plonking job?

X-Mailer: Mozilla 4.75 [en] (Win98; U)

Or am I merely in the /mental/ killfile? The mental killfile can't hold more
than three or four names before Chucky gets all confused. I will be
disappointed if Chucky slips up and follows up.

That will be a sad day, when once again I see something I wrote, re-entering my
news server, quoted in its entirety, with one line of some insipid drivel
appended to it.

The amusing thing is that he frequently criticises Windows and Windows
users.
 
S

Spiros Bousbouras

Please don't answer off-topic queries in c.l.c, apart from advising
them of suitable newsgroups, and the fact that they are off-topic.
c.l.c is limited to the portable C language, as defined in the
various ISO C standards, and K&R (for C before the ISO standards).
Things that are system or hardware specific are off-topic.

I agree on principle but if we take this 100% literally then
even redirections to other newsgroups should be frowned upon
because after all the question of what is the appropriate
newsgroup for discussing some issue which is off-topic here is
also off-topic. So strictly speaking people should only mention
that a question is off-topic and nothing more.

However I feel we should strike a balance between, on one hand
not diluting the topicality of this group which would only limit
its usefulness but also being helpful on the other. With these
goals in mind I consider it acceptable that people who ask an
off-topic question should be informed that it's off-topic and
also get a pointer to the right direction. This pointer could be
a mention of an appropriate newsgroup, or a piece of documen-
tation or the information they're asking for. As long as
everyone is disciplined enough not to allow it to evolve into
off-topic discussion, I don't see why newsgroup referrals should
be allowed but other referrals not.

The argument that someone might provide mistaken information and
there won't be experts to correct it applies just as much to a
newsgroup redirection as to any other piece of information. But
if we feel that there is enough knowledge here to lead to
appropriate newsgroup redirections then any off-topic and
incorrect information posted here will be corrected when the
issue is pursued further in the correct newsgroup.

To put it otherwise, imagine that someone here feels confident
that a programming problem mentioned here cannot be solved
using standard C but can be solved using function foobar which
is mentioned in the PUSIX standard which is topical on comp.pusix
Then, according to your logic, he should mention comp.pusix
but should not mention foobar. I don't see the point in this.
 
M

Martin Ambuhl

Go chuck yourself, Fucky!

This _can't_ be the same Kaz that was here some years ago. Not only did
that Kaz understand topicality, he was not a rude boor.
 
C

CBFalconer

Spiros said:
.... snip ...

.... snip ...

However I feel we should strike a balance between, on one hand
not diluting the topicality of this group which would only limit
its usefulness but also being helpful on the other. With these
goals in mind I consider it acceptable that people who ask an
off-topic question should be informed that it's off-topic and
also get a pointer to the right direction. This pointer could be
a mention of an appropriate newsgroup, or a piece of documen-
tation or the information they're asking for. As long as
everyone is disciplined enough not to allow it to evolve into
off-topic discussion, I don't see why newsgroup referrals should
be allowed but other referrals not.

The argument that someone might provide mistaken information and
there won't be experts to correct it applies just as much to a
newsgroup redirection as to any other piece of information. But
if we feel that there is enough knowledge here to lead to
appropriate newsgroup redirections then any off-topic and
incorrect information posted here will be corrected when the
issue is pursued further in the correct newsgroup.

But a mistaken newsgroup redirection will rapidly get corrected in
that other newsgroup. The problem isn't so much the extra answers,
it is those mistaken answers. The answerer may be convinced s/he
is completely accurate, and wrong. Also, the answerer can be one
of the ugly trolls we have been plagued with recently, who post
much misinformation.

Adhering to topicality takes advantage of the separation of
newsgroups in Usenet. Ignoring it discards that advantage, to no
net purpose.
 
R

Richard

CBFalconer said:
But a mistaken newsgroup redirection will rapidly get corrected in
that other newsgroup. The problem isn't so much the extra answers,
it is those mistaken answers. The answerer may be convinced s/he
is completely accurate, and wrong. Also, the answerer can be one
of the ugly trolls we have been plagued with recently, who post
much misinformation.

Yet you are wrong all the time in this group. Does this mean the posts
YOU reply to are Off Topic?
Adhering to topicality takes advantage of the separation of
newsgroups in Usenet. Ignoring it discards that advantage, to no
net purpose.

Nonsense. Redirect by all means but answer too. No one should EVER
accept answers blindly as your posts prove time and time again.
 
K

Keith Thompson

Golden California Girls said:
I see the point is to make it someone else's problem. Right good Christian
thing you do.

The point is to *solve* the problem.
 
K

Kenny McCormack

The point is to *solve* the problem.

Indeed. Quite.

Note that making something someone else's problem *is* solving the problem.

(From at least one POV - in fact, the only POV that matters to a CLC reg)
 
B

Bruce Cook

Kenny said:
Indeed. Quite.

Note that making something someone else's problem *is* solving the
problem.

(From at least one POV - in fact, the only POV that matters to a CLC reg)

Actually as someone who works in a service industry I can tell you that
making it someone else problem may satisfy you, but hardly ever satisfies
the customer (or in this case the OP).

I imagine that those trying to learn and getting redirected through a
multitude of uninterested newsgroups would give up in frustration with the
conclusion that everyone on usenet are a bunch of wankers. Probably a not
to inaccurate assessment on the whole.

Bruce
 
K

Keith Thompson

Bruce Cook said:
CBFalconer wrote:
But a mistaken newsgroup redirection will rapidly get corrected in
that other newsgroup. [...]
The point is to *solve* the problem.
[...]
Actually as someone who works in a service industry I can tell you that
making it someone else problem may satisfy you, but hardly ever satisfies
the customer (or in this case the OP).

I imagine that those trying to learn and getting redirected through a
multitude of uninterested newsgroups would give up in frustration with the
conclusion that everyone on usenet are a bunch of wankers. Probably a not
to inaccurate assessment on the whole.

The point of redirecting questions to other newsgroups is to let the
original poster know that there are other places where their questions
can get *better answers*.
 
C

CBFalconer

Richard said:
CBFalconer said:

Articles posted in this newsgroup recently under the name of "Kaz
Kylheku" have been detectably different in tone from those he used
to post here before wandering off to newsgroups new. It is not
impossible that this one is actually an impostor, in which case
whether you plonk him or not is of no interest to anyone. And if he
/isn't/ an impostor, plonking Kaz is about the stupidest thing you
could possibly do.

This one has shown up here for at least a month or so, and has no
resemblance to the original. I suspect the name is a coincidence.
Probably fairly common in his native land. At any rate, I have no
use for this one.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top