COPY这几个函数到你的单元中
function WriteShareData(ShareName: pchar; Data: pointer; DataSize: Cardinal): THandle;
var
tmpData: pointer;
begin
result := CreateFileMapping(DWord($FFFFFFFF), nil, PAGE_READWRITE, 0,
DataSize, ShareName);
tmpData := MapViewofFile(result, FILE_MAP_WRITE, 0, 0, 0);
move(Data^, tmpData^, DataSize);
UnMapViewofFile(tmpData);
end;
procedure ReadShareData(ShareName: pchar; Data: pointer; DataSize: Cardinal);
var
hMap: THandle;
tmpData: pointer;
begin
hMap := CreateFileMapping(DWord($FFFFFFFF), nil, PAGE_READWRITE,
0, DataSize, ShareName);
try
tmpData := MapViewofFile(hMap, FILE_MAP_READ, 0, 0, 0);
move(tmpData^, Data^, DataSize);
UnMapViewofFile(tmpData);
finally
CloseHandle(hMap);
end;
end;
function ReadShareInteger(ShareName: pchar): integer;
begin
ReadShareData(ShareName, @result, sizeof(integer));
end;
function WriteShareInteger(ShareName: pchar; h: integer): THandle;
begin
result := WriteShareData(ShareName, @h, sizeof(integer));
end;
在接受消息的窗口初始化时加入
WriteShareInteger('你自己取名字', Hanlde);
发送消息时
h := ReadShareInteger('你自己取名字');
sendmessage(h,wm_myname,integer(@str),1);