DLL的数据共享

  • 主题发起人 主题发起人 import
  • 开始时间 开始时间
I

import

Unregistered / Unconfirmed
GUEST, unregistred user!
library DllPrj;
uses
SysUtils,Windows;
const
CMapFileName='Kingron';
var
// GlobalData: Integer = 100;
PGlobalData:^integer=@GlobalData;
MapHandle:THandle;
function GetData: integer; stdcall;
begin
Result := PGlobalData^;
end;
function SetData(const i: integer):integer; stdcall;
begin
Result:=PGlobalData^;
if PGlobalData^ <> i then
PGlobalData^ := i;
end;
procedure OpenShareData;
var
size:integer;
begin
size:=SizeOf(PGlobalData^);
MapHandle:=CreateFileMapping(Dword(-1),nil,PAGE_READWRITE,0,Size,CMapFileName);
if MapHandle<>0 then
begin
PGlobalData:=MapViewOfFile(MapHandle,FILE_MAP_ALL_ACCESS,0,0,Size);
if PGlobalData=nil then
CloseHandle(MapHandle);
end;
end;
procedure CloseShareData;
begin
UnmapViewOfFile(Pointer(MapHandle));
end;
procedure DllEntryPoint(dwReason:Dword);
begin
case dwReason of
DLL_PROCESS_ATTACH:OpenShareData
DLL_PROCESS_DETACH:CloseShareData
end;
end;
exports
GetData,
SetData;
begin
DllProc:=@DllEntryPoint;
DllEntryPoint(DLL_PROCESS_ATTACH);
end.
 

Similar threads

S
回复
0
查看
589
SUNSTONE的Delphi笔记
S
S
回复
0
查看
686
SUNSTONE的Delphi笔记
S
S
回复
0
查看
906
SUNSTONE的Delphi笔记
S
S
回复
0
查看
884
SUNSTONE的Delphi笔记
S
后退
顶部