//宣告部分,寫入及讀取端程式都要有
const
_SMWithXMonitorPolicy = 'XFortMonitorPolicy';
type
TCmdDataWithMonitorPolicy = record // policy
btData1: Byte; //壓縮率
btData2: Byte; //縮放率
btData3: Byte; //
boolData1: Boolean; //是否抓完整圖 ?
boolData2: Boolean;
boolData3: Boolean;
dwData1: DWORD; //錄影間隔時間(秒) ?
dwData2: DWORD; //影像長度(pixel) ?
dwData3: DWORD; //影像寬度(pixel) ?
dwData4: DWORD;
dwData5: DWORD;
dwData6: DWORD;
intData1: Integer; //sessionid
intData2: Integer; //usrid
intData3: Integer; //port
intData4: Integer;
intData5: Integer;
int64Data1: Int64;
int64Data2: Int64;
dtDateTimeData1: TDateTime; // Double(8 bytes)
dtDateTimeData2: TDateTime;
ptData1: Pointer;
ptData2: Pointer;
strData1: array [0..511] of Char; //IP
strData2: array [0..511] of Char; //擷取端電腦名稱
strData3: array [0..511] of Char;
strData4: array [0..511] of Char;
strData5: array [0..511] of Char;
end;
PCmdDataWithMonitorPolicy = ^TCmdDataWithMonitorPolicy;
public
g_hShareMemPolicy :Thandle;
g_pShareMemPolicy :Pointer;
//一端的create須先建立起sharememory
create
g_hShareMemPolicy := CreateFileMapping(
$FFFFFFFF, // Shared memory File,Handle 傳入 $FFFFFFFF
nil, // 不設定安全屬性
PAGE_READWRITE, // 存取模式設定為可讀寫以便行程交換資料
0, // 使用 paging file 時一般將之設為零
SizeOf(TCmdDataWithMonitorPolicy), // 共享記憶體的大小 2048bytes
_SMWithXMonitorPolicy); // 其他的行程將以此名稱參考到選擇共享記憶體
//MapViewOfFile函數返回一個指向共用記憶體塊的在該程式記憶體空間中有效的指標
g_pShareMemPolicy :=MapViewOfFile(
g_hShareMemPolicy , // File-mapping object 的 Handle 值
FILE_MAP_ALL_ACCESS, //設為 FILE_MAP_ALL_ACCESS 開放存取
0,
0,
//0); // 映射回來的 byte 數
SizeOf(TCmdDataWithMonitorPolicy));
//將資料寫入sharememory中
procedure TFormMain.Button1Click(Sender: TObject);
begin
PCmdDataWithMonitorPolicy(g_pShareMemPolicy)^.btData1 := 100; //壓縮率
PCmdDataWithMonitorPolicy(g_pShareMemPolicy)^.btData2 := 90; //縮放率
PCmdDataWithMonitorPolicy(g_pShareMemPolicy)^.intData1 := 5; //sessionid
PCmdDataWithMonitorPolicy(g_pShareMemPolicy)^.intData2 := 33; //usrid
PCmdDataWithMonitorPolicy(g_pShareMemPolicy)^.intData3 := 24137; //port
//IP
FillChar(PCmdDataWithMonitorPolicy(g_pShareMemPolicy)^.strData1,SizeOf(PCmdDataWithMonitorPolicy(g_pShareMemPolicy)^.strData1),0);
StrCopy(PCmdDataWithMonitorPolicy(g_pShareMemPolicy).strData1, PCHAR('10.1.0.3'));
//擷取端電腦名稱
FillChar(PCmdDataWithMonitorPolicy(g_pShareMemPolicy)^.strData2,SizeOf(PCmdDataWithMonitorPolicy(g_pShareMemPolicy)^.strData2),0);
StrCopy(PCmdDataWithMonitorPolicy(g_pShareMemPolicy).strData2, PCHAR('Yivon'));
end;
//讀取sharememory資料
procedure TForm1.Button2Click(Sender: TObject);
var
piRes :^Integer;
sTmpFileName : string;
begin
g_hShareMemPolicy := OpenFileMapping(
FILE_MAP_ALL_ACCESS, // Shared memory File,Handle 傳入 $FFFFFFFF
true,
_SMWithXMonitorPolicy); // 其他的行程將以此名稱參考到選擇共享記憶體
if g_hShareMemPolicy <> 0 then //判斷這一塊SHAREMEMORY有無配置
begin
g_pShareMemPolicy:=MapViewOfFile(
g_hShareMemPolicy, // File-mapping object 的 Handle 值
FILE_MAP_ALL_ACCESS, //設為 FILE_MAP_ALL_ACCESS 開放存取
0,
0,
//0); // 映射回來的 byte 數
SizeOf(TCmdDataWithMonitorPolicy));
Memo1.Lines.add('壓縮率:'+inttostr(PCmdDataWithMonitorPolicy(g_pShareMemPolicy)^.btData1));
Memo1.Lines.add('縮放率:'+inttostr(PCmdDataWithMonitorPolicy(g_pShareMemPolicy)^.btData2));
Memo1.Lines.add('SessionID:'+inttostr(PCmdDataWithMonitorPolicy(g_pShareMemPolicy)^.intData1));
Memo1.Lines.add('usrid:'+inttostr(PCmdDataWithMonitorPolicy(g_pShareMemPolicy)^.intData2));
Memo1.Lines.add('Port:'+inttostr(PCmdDataWithMonitorPolicy(g_pShareMemPolicy)^.intData3));
Memo1.Lines.add('IP:'+String(PCmdDataWithMonitorPolicy(g_pShareMemPolicy).strData1));
Memo1.Lines.add('CapComputerName:'+String(PCmdDataWithMonitorPolicy(g_pShareMemPolicy).strData2));
end;
end;
沒有留言:
張貼留言