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

COPYDATASTRUCT in Delphi?

666 views
Skip to first unread message

Jyri Leino

unread,
Jan 18, 2001, 12:33:40 PM1/18/01
to
Hi!
I've been playing with Delphi and Winamp Api's just out of curiosity. Most
of
of the messages sent are simple, but this time i'm going to need your
help. => I need to receive information back ...

here's a snipplet from winamp's dev.pages + the url.

The Question is:
How would I define the below declared cds structure in Delphi?

WM_COPYDATA messages are sent using
SendMessage() and a COPYDATASTRUCT structure. In C/C++, you can send
these messages by using:


COPYDATASTRUCT cds;
cds.dwData = id;
cds.lpData = (void*)data;
cds.cbData = data_length;

SendMessage(hwndWinamp,WM_COPYDATA,(WPARAM)NULL,(LPARAM)&cds);


can be found at
http://www.winamp.com/nsdn/winamp2x/dev/sdk/api.jhtml

Howard Moon

unread,
Jan 18, 2001, 12:44:08 PM1/18/01
to
No need to define it yourself. Like most Windows structures, this is
defined in Windows.pas as TCopyDataStruct.
-Howard

Jyri Leino

unread,
Jan 18, 2001, 1:08:39 PM1/18/01
to

Thanks, Howard
Would you have snipplet of using it -> i'm
new to this, so a 10-liner would be a great help.

Thanks in advance, Jyri


Howard Moon

unread,
Jan 19, 2001, 9:23:55 AM1/19/01
to
Here's some code for sending and receiving a string via WM_COPYDATA:

Sender:

procedure TFormSource.Button1Click(Sender: TObject);
var
h : HWND;
s : string;
r : TCopyDataStruct;
begin
h := FindWindow( 'TFormDestination', 'Destination Form' );
if (h <> 0) then
begin
s := Edit1.Text;
r.dwData := 0;
r.cbData := Length( s );
r.lpData := PChar( s );
SendMessage( h, WM_COPYDATA, Handle, Integer(@r) );
end
else
ShowMessage('Window not found');
end;


Receiver:

// in the class declaration
procedure WMCopyData( var Message: TMessage ); message WM_COPYDATA;

// in the implementation
procedure TFormDestination.WMCopyData(var Message: TMessage);
var
p : PCopyDataStruct;
l : Integer;
s : string;
begin
p := PCopyDataStruct( Message.lParam );
if (p <> nil) then
begin
l := p^.cbData;
SetLength( s, (l+1) );
StrLCopy( PChar(s), PChar(p^.lpData), l );
Edit1.Text := s;
end
else
Edit1.Text := 'ERROR';
end;

Hope this helps...
-Howard

Jyri Leino

unread,
Jan 19, 2001, 11:45:13 AM1/19/01
to

Thanks again Howard, I'll give it shot during the weekend,
I wish you nice weekend also, Jyri

0 new messages