Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

RegisterWindowMessage, HWND_BROADCAST between exe and dll issue

238 views
Skip to first unread message

nei...@gmail.com

unread,
Apr 27, 2007, 2:56:59 PM4/27/07
to
i have the following problem, that i've been looking at and googling
about for past 4 days to no avail.

i have an exe, let's call it exe1, that is ours, that runs as some
user, "Administrator" in this particular case, on a given machine,
that does following:

UINT uiStringA = RegisterWindowMessage("StringA")

and then has

ON_REGISTERED_MESSAGE(uiStringA, stringAHandler);

then i have a vendor's exe, that runs as a service under "System" user
and that loads 1 standard c dll, which in turn loads 2nd dll, let's
call it dll2, which is also ours and mfc, that also does:

UINT uiStringA = RegisterWindowMessage("StringA")

and then
PostMessage (HWND_BROADCAST, uiStringA...)

this is what happens:

1. the RegisterWindowMessage functions that are called in exe1 and
dll2 return different UINT values. also they are consistent for each
process.

2. the stringAHandler is never triggered by broadcast. not sure why,
either because #1 above, or for another reason.

am quite at a loss at what it could be. all the reading that i have
done in the past few days seems to point to the fact that this
scenario should work. i've checked the strings and yes they are
identical and no there is no unicode on either side.

thanks,
Inna

Igor Tandetnik

unread,
Apr 27, 2007, 3:19:47 PM4/27/07
to
nei...@gmail.com wrote:
> i have an exe, let's call it exe1, that is ours, that runs as some
> user, "Administrator" in this particular case, on a given machine,
> that does following:
>
> UINT uiStringA = RegisterWindowMessage("StringA")
>
> and then has
>
> ON_REGISTERED_MESSAGE(uiStringA, stringAHandler);
>
> then i have a vendor's exe, that runs as a service under "System" user
> and that loads 1 standard c dll, which in turn loads 2nd dll, let's
> call it dll2, which is also ours and mfc, that also does:
>
> UINT uiStringA = RegisterWindowMessage("StringA")
>
> and then
> PostMessage (HWND_BROADCAST, uiStringA...)

Services run in a separate window station, and have their own desktop.
Window messages can only be sent between windows on the same desktop.
You won't be able to use window messages for communication between a
regular process and a service. Choose a different IPC mechanism.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


David Ching

unread,
Apr 27, 2007, 4:57:31 PM4/27/07
to
"Igor Tandetnik" <itand...@mvps.org> wrote in message
news:ehi8FEQ...@TK2MSFTNGP06.phx.gbl...

> Services run in a separate window station, and have their own desktop.
> Window messages can only be sent between windows on the same desktop. You
> won't be able to use window messages for communication between a regular
> process and a service. Choose a different IPC mechanism.
> --

I agree a different IPC mechanism is preferable, however
BroadcastSystemMessage() with BSM_ALLDESKTOPS will work.

-- David

Alexander Grigoriev

unread,
Apr 27, 2007, 10:54:08 PM4/27/07
to
Bur RegisterWindowMessage won't give the same result.

"David Ching" <d...@remove-this.dcsoft.com> wrote in message
news:1334ov4...@news.supernews.com...

David Ching

unread,
Apr 28, 2007, 2:21:40 AM4/28/07
to
"Alexander Grigoriev" <al...@earthlink.net> wrote in message
news:eNXr%23BUiH...@TK2MSFTNGP06.phx.gbl...

> Bur RegisterWindowMessage won't give the same result.
>

Yes, I was refuting the common belief that it is impossible to send Windows
messages to a different desktop. It is possible.

-- David


Alexander Grigoriev

unread,
Apr 28, 2007, 10:28:33 AM4/28/07
to
If you have SE_TCB_NAME privilege (LOCAL_SYSTEM account ONLY).

"David Ching" <d...@remove-this.dcsoft.com> wrote in message

news:UJBYh.1628$tp5...@newssvr23.news.prodigy.net...

David Ching

unread,
Apr 28, 2007, 9:04:49 PM4/28/07
to
"Alexander Grigoriev" <al...@earthlink.net> wrote in message
news:O4w3Jmfi...@TK2MSFTNGP02.phx.gbl...

> If you have SE_TCB_NAME privilege (LOCAL_SYSTEM account ONLY).
>

I don't know enough about permissions or really even the architecture of
what is in LOCAL_SYSTEM and what is not. I have used
BroadcastSystemMessage() in the past, and was glad it was there.

-- David


Alexander Grigoriev

unread,
Apr 29, 2007, 10:18:59 AM4/29/07
to
You can broadcast messages to your current desktop, no problem.
You can only broadcast messages to all desktops if you have the said
privilege (which means a member of Trusted Computer Base). This privilege is
only given to SYSTEM and kernel mode threads. It means all access checks can
be bypassed. Even Administrators don't have it.

"David Ching" <d...@remove-this.dcsoft.com> wrote in message

news:RaSYh.3239$uJ6...@newssvr17.news.prodigy.net...

David Ching

unread,
Apr 29, 2007, 6:31:33 PM4/29/07
to
"Alexander Grigoriev" <al...@earthlink.net> wrote in message
news:OLH1evmi...@TK2MSFTNGP03.phx.gbl...

> You can broadcast messages to your current desktop, no problem.
> You can only broadcast messages to all desktops if you have the said
> privilege (which means a member of Trusted Computer Base). This privilege
> is only given to SYSTEM and kernel mode threads. It means all access
> checks can be bypassed. Even Administrators don't have it.
>

Interesting... it's been a year since I've had to use this API, but I
believe a service needed to broadcast a message to all desktops that the
service was closing. This worked; the necessary priviledge was had.

-- David


0 new messages