拷一段代码给你参考procedure TFormTstSrvr2.OpenMappedFile(); begin in_out_file := OpenFileMapping(FILE_MAP_WRITE,FALSE,'DLPH2WR_IO_PARAM') ; if (in_out_file = 0 ) then exit ; pInOut := MapViewOfFile(in_out_file, FILE_MAP_WRITE, 0, 0, 0); if (pInOut = nil) then CloseHandle(in_out_file);end;procedure TFormTstSrvr2.CloseMappedFile(); begin if (pInOut <> nil) then UnmapViewOfFile(pInOut); if (in_out_file <> 0 ) then CloseHandle(in_out_file); in_out_file:=0; end;procedure TFormTstSrvr2.MappedFilePutString(str:AnsiString); begin OpenMappedFile(); if (pInOut<>Nil) then if (Length(str)>0) then StrCopy(Pchar(pInOut), Pchar(str)) else Pchar(pInOut)^:=#0; CloseMappedFile(); end;function TFormTstSrvr2.MappedFileGetString():String; begin Result := ''; OpenMappedFile(); if (pInOut<>Nil) then Result:=Pchar(pInOut); CloseMappedFile(); end;在另一边创建一个文件映射CreateFileMapping... 传入lpName参数为'DLPH2WR_IO_PARAM'
To wanna2003(wanna2003): 下面是思路示意图,仅供参考: IF 是无界面的业务逻辑代码共享 THEN BEGIN IF 是过程与函数共享 THEN BEGIN 用DLL封装,用Exports导出即可 END IF 是对象共享 THEN BEGIN 用VC创建一个COM对象,在系统中注册,最后在Delphi中Import Type Library即可 END END ELSE 使用ActiveX控件
begin in_out_file := OpenFileMapping(FILE_MAP_WRITE,FALSE,'DLPH2WR_IO_PARAM') ;
if (in_out_file = 0 ) then exit ; pInOut := MapViewOfFile(in_out_file, FILE_MAP_WRITE, 0, 0, 0);
if (pInOut = nil) then
CloseHandle(in_out_file);end;procedure TFormTstSrvr2.CloseMappedFile();
begin
if (pInOut <> nil) then UnmapViewOfFile(pInOut);
if (in_out_file <> 0 ) then
CloseHandle(in_out_file);
in_out_file:=0;
end;procedure TFormTstSrvr2.MappedFilePutString(str:AnsiString);
begin
OpenMappedFile();
if (pInOut<>Nil) then
if (Length(str)>0) then
StrCopy(Pchar(pInOut), Pchar(str))
else
Pchar(pInOut)^:=#0; CloseMappedFile();
end;function TFormTstSrvr2.MappedFileGetString():String;
begin
Result := '';
OpenMappedFile();
if (pInOut<>Nil) then
Result:=Pchar(pInOut);
CloseMappedFile();
end;在另一边创建一个文件映射CreateFileMapping...
传入lpName参数为'DLPH2WR_IO_PARAM'
下面是思路示意图,仅供参考:
IF 是无界面的业务逻辑代码共享 THEN
BEGIN
IF 是过程与函数共享 THEN
BEGIN
用DLL封装,用Exports导出即可
END
IF 是对象共享 THEN
BEGIN
用VC创建一个COM对象,在系统中注册,最后在Delphi中Import Type Library即可
END
END
ELSE
使用ActiveX控件