Here is my answer:
VAR
DT: TYOURSTRUCT;
Procedure TXXX.WMCopyData (Var Message: TwmcopyData);
VAR
P: pchar;
Begin
P: = message.lpdata;
Move (p ^, dt.a, sizeof (integer);
inc (p, sizeof (integer);
Move (P ^, DT.B, SIZEOF (Integer);
inc (p, sizeof (integer);
getMem (DT.PFileStr, Strlen (P) 1);
Move (p ^, dt.pfilester ^, strlen (p) 1);
END;
From: Jame, Time: 2000-9-25 20:41:00, ID: 348950
public
procedure mymessage (var t: twmcopydata); message wm_copydata;
{public Declarations}
Heend;
VAR
FORM2: TFORM2;
IMPLEMENTATION
{$ R * .dfm}
{TFORM2}
Procedure TFORM2.MYMESSAGE (VAR T: TWMCopyData);
Begin
edit1.text: = strpas (t.copyDataStruct ^ .lpdata); // accepts data and display.
END;
Procedure TFORM1.SPEEDBUTTON1CLICK (Sender: TOBJECT);
VAR
ds: tcopydatastruct;
hd: thandle;
Begin
DS.CBDATA: = Length (edit1.text) 1;
GetMem (ds.lpdata, ds.cbdata); // Assign memory for the transferred data area
Strcopy (ds.lpdata, pchar (edit1.text));
hd: = findwindow (nil, 'form2'); // Get the handle of the receiving window
IF HD <> 0 THEN
sendmessage (HD, WM_CopyData, Handle,
Cardinal (@ds)) // Send WM_COPYDATA message
ELSE
SHOWMESSAGE (the 'target window is not found!');
freemem (ds.lpdata); // Release resources
END;
Here is a shared memory method
Unit CCC;
Interface
Uses
Windows, Messages, Sysutils,
Classes, Graphics, Controls, Forms,
Dialogs, shellapi, stdctrls, buttons;
Const
WM_Baricon = WM_USER 200;
Type
TFORM1 = Class (TFORM)
BTNWRITE: Tbitbtn;
BTNREAD: Tbitbtn;
EDITWRITE: TEDIT;
Editread: tedit;
Procedure formcreate (Sender: TOBJECT);
Procedure btnWriteClick (Sender: TOBJECT);
Procedure btnreadclick (sender: TOBJECT);
Private
HMAPFILE &: THANDLE;
mapfilepointer: Pointer;
PUBLIC
{public Declarations}
Wen; VAR
FORM1: TFORM1;
IMPLEMentation
{$ R * .dfm}
Procedure TFORM1.FormCreate (Sender: TOBJECT);
Begin
HMAPFILE: = CREATEFILEMAPPING
$ fffffff, // Special memory map handle
nil, Page_Readwrite, 0,10000,
'DDHDEMAPPEDFILE '); // File Name
IF HMAPFILE <> 0 THEN
mapfilepointer: = MapViewOffile
HMAPFILE, / / The handle of the image file
FILE_MAP_ALL_ACCESS,
0, 0, 0) // Access the entire image file
Else
SHOWMESSAGE ('hmapfile = 0');
IF mapfilepointer = nil dam
ShowMessage ('MapFilePointer = nil');
END;
Procedure TFORM1.BTNWRITECLICK (Sender: TOBJECT);
Begin
STRCOPY (PchapFilePointer),
Pchar (editwrite.text)); // write content into shared memory
END;
Procedure TFORM1.BTNREADCLICK (Sender: TOBJECT);
VAR
S: String;
Begin
S: = PCHAR (MapFilePointer); // read the content from the shared memory
EditRead.text: = s;
END;
End.