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

SendMessage(HWND_BROADCAST..) and strange behavior with Outlook

600 views
Skip to first unread message

Mike Meyer

unread,
Dec 7, 2005, 8:10:57 AM12/7/05
to
Hi,

I am using the code below to send string from one app to another, works
everything ok expect that there is strange behavior with
Outlook. When my app send message, Outlook catch my message and display
messagebox like "The command line argument is not valid. Verify the switch
you are using."

To solve this I have changed HWND_BROADCAST to FindWindow('TfrmMyForm', nil)
to send message directly to my program, but there is another problem with
it. This code does not works if listener program is minimized.

Any suggestions?


var
ADataLeft: TCopyDataStruct;
AWindow: HWND;
AMessage:String;
begin
AMessage:='My message to other module.';
ADataLeft.dwData := 0;
ADataLeft.lpData := PChar(AMessage);
ADataLeft.cbData := Length(AMessage) + 1;
SendMessage(HWND_BROADCAST, WM_COPYDATA, 0, LParam(@ADataLeft));
end;


Regards,
M


krisztian pinter

unread,
Dec 7, 2005, 8:26:48 AM12/7/05
to
On Wed, 7 Dec 2005 15:10:57 +0200, Mike Meyer <m.m...@cox.com> wrote:

> SendMessage(HWND_BROADCAST, WM_COPYDATA, 0, LParam(@ADataLeft));

holy god, pal! you NEVER broadcast WM_COPYDATA, only messages registered
with RegisterWindowMessage.

Mike Meyer

unread,
Dec 7, 2005, 8:35:56 AM12/7/05
to

"krisztian pinter" <pint...@freemail.hu> wrote in message
news:ops1e0yyauwwfehv@karwst_pint...

> SendMessage(HWND_BROADCAST, WM_COPYDATA, 0, LParam(@ADataLeft));

Krisztian, I am new in this, can you explain more detailed where is my
mistake and how to solve it?


krisztian pinter

unread,
Dec 7, 2005, 9:13:24 AM12/7/05
to
On Wed, 7 Dec 2005 15:35:56 +0200, Mike Meyer <m.m...@cox.com> wrote:

>> SendMessage(HWND_BROADCAST, WM_COPYDATA, 0, LParam(@ADataLeft));
>
>> holy god, pal! you NEVER broadcast WM_COPYDATA, only messages
>> registered
>> with RegisterWindowMessage.
>
> Krisztian, I am new in this, can you explain more detailed where is my
> mistake and how to solve it?


a broadcast is sent to many windows. it is possible that there is a program
around that uses WM_COPYDATA to receive a command, and your data is
interpreted as "format c drive without asking any questions". how do you
know?

you can only send messages to your own windows, or ones you know how will
react. or you can use the RegisterWindowMessage to make sure only you use
that number.

Anders Isaksson

unread,
Dec 7, 2005, 10:23:33 AM12/7/05
to
On Wed, 7 Dec 2005 15:10:57 +0200, "Mike Meyer" <m.m...@cox.com> wrote:

> SendMessage(HWND_BROADCAST, WM_COPYDATA, 0, LParam(@ADataLeft));

You shouldn't BROADCAST a WM_COPYDATA! Anything could happen.

Look at RegisterWindowsMessage() for info on how to get a unique message
id.

Broadcast this message, the receiving application should answer with a
window handle which you then can use in the WM_COPYDATA message to make
sure only the correct window gets the WM_COPYDATA message.
--
Anders Isaksson, Sweden
BlockCAD: http://web.telia.com/~u16122508/proglego.htm
Gallery: http://web.telia.com/~u16122508/gallery/index.htm

Mike Meyer

unread,
Dec 7, 2005, 10:19:07 AM12/7/05
to
I have changed send procedure below, but don't understand how to receive it?
Could anybody help me?

Var
WM_TESTPOST:Integer;

procedure SendMyMessage(AMessage: string);
var
ADataLeft: TCopyDataStruct;
begin


ADataLeft.dwData := 0;
ADataLeft.lpData := PChar(AMessage);
ADataLeft.cbData := Length(AMessage) + 1;

SendMessage(HWND_BROADCAST, WM_TESTPOST, 0, LParam(@ADataLeft));
end;


initialization
WM_TESTPOST := RegisterWindowMessage(PChar('MyMessage'));


"krisztian pinter" <pint...@freemail.hu> wrote in message

news:ops1e24mflwwfehv@karwst_pint...

krisztian pinter

unread,
Dec 7, 2005, 11:03:44 AM12/7/05
to
On Wed, 7 Dec 2005 17:19:07 +0200, Mike Meyer <m.m...@cox.com> wrote:

> I have changed send procedure below, but don't understand how to receive
> it?

> WM_TESTPOST := RegisterWindowMessage(PChar('MyMessage'));


well, this is tricky, because message handlers require constants.

but you can

1. override WndProc, but make sure you call inherited

2. use Application.OnException


i recommend WndProc, but i never used it before, so ...

0 new messages