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
> SendMessage(HWND_BROADCAST, WM_COPYDATA, 0, LParam(@ADataLeft));
holy god, pal! you NEVER broadcast WM_COPYDATA, only messages registered
with RegisterWindowMessage.
> 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?
>> 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.
> 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
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...
> 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 ...