• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 176
  • Last Modified:

Sending Message

how do i passing a additional parameter to my message handler ? let say i write my own message and send my additional parameter to my message handler instead of using the LParam and WParam.
0
qwertyuiopasdfghjkl
Asked:
qwertyuiopasdfghjkl
1 Solution
 
viktornetCommented:
If your additional data is a record then you use a pointer and send it with the lparam or wparam..

SendMessage(Handle, Message, lparam, longint(@data));
0
 
viktornetCommented:
oh, I forgot, then when you receive it you typecast it like this...

var
  myrec : TMYREC;
begin
  myRec := TMYREC(msg.lparam^);
 //Then use your record here... It can work for any variable or type or whatever..You just send a pointer with the message...
end;

-Viktor
--Ivanov
0
 
viktornetCommented:
is this what you needed??
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
scrapdogCommented:
Vik's method is a good idea...however, don't you have to pass the pointer thru the LParam?  [If I remember correctly, WParam is a word, and a pointer is a double-word]
0
 
viktornetCommented:
Oppps... Scrappy :) is right... Actualy that's exactly what I've done, but I have a typo that makes it look if I've exchanged the parameters...

This line

SendMessage(Handle, Message, lparam, longint(@data));

should be

SendMessage(Handle, Message, wparam, longint(@data));

sorry for da typo... :))

Does it help now? Am I allowed to answer the q'n?
0
 
rwilson032697Commented:
Scrappy is only half right (sorry to be picky). Yes you should use LParam, but, Wparam in Win32 is a DWORD!

Cheers,

Raymond.

0
 
MadshiCommented:
Yes, Raymond is right. In win16, wParam is 16 bit long, in win32 it is 32 bit long.

However, if you send messages from one application to another, you can't just give in a pointer to a data block, since the pointer will definitely be invalid in the other application's memory context.
So if you're sending this message from one of your applications to another one of your applications, you'll have to look at the WM_COPYDATA message, which is thought for this purpose.
Otherwise (that means if the message is sent and received from the same application) Viktor's solution is right.
0
 
qwertyuiopasdfghjklAuthor Commented:
ok..Viktor ...you can post it as answer now...
0
 
viktornetCommented:
10Q

btw- Madshi is right about the WM_COPYDATA.

Happy New Year (Well almost)

-Viktor
--Ivanov
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now