All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
SQL Server的空值处理策略_[SQL Server教程]
如何在ASP.Net中实现RSA加密_[Asp.Net教程]
Sql,server动态和静态内存分配_[SQL,Server教程]
利用C#来做ASP.NET的登陆页面_[Asp.Net教程]
总结SQL Server与Access语法小差异_[SQL Server教程]
C#减少图片文件大小和尺寸_[Asp.Net教程]
asp.net2.0服务器控件之Label控件
从数据库导出数据到word、excel、.txt_.net资料_编程技术
加速PHP动态网站,MySQL索引分析和优化_php资料_编程技术
数据库2005,日志收缩简便方法_mssql学习_编程技术
Reading number is top 10 pictures
9.3阅兵全景图4-陸海空现代化兵种方阵梯队
西游日记1
鸡蛋的新玩法
大年初五接财神
Photographed the passion of the clients and prostitutes in the sex trade picture2
狗狗与主人神同步1
黑社会大哥相亲
The money of more than 100 countries and regions15
yy365网站上的美女1
The money of more than 100 countries and regions2
Download software ranking
Tram sex maniac 2 (H) rar bag9
Unix video tutorial18
Visual C++界面编程技术
asp.net技术内幕
Unix video tutorial20
JSP+Ajax Web development typical examples
Twenty piece of palm leaf
Sora aoi, the maid, students' uniforms
matrix1
圣殿祭司的ASP.NET.2.0.开发详解-使用C#
aaa published in(发表于) 2014/7/19 0:11:47 Edit(编辑)
delphi映像内存发送端

delphi映像内存发送端

delphi映像内存发送端

映像内存发送端

发送端利用CreateFileMapping 函数建立内存映像文件,并用MapViewOfFile 函数将映像文件映射到本进行中,并利用PostMessage 发送信息,具体步骤及方法如下。

(1)新建一个项目。将窗体的Caption 设置为“映像内存发送端”。在窗体上添加一个Caption 属性为“发送数据”的Button 组件。

(2)程序源代码如下:

unit Unit1;

interface

Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,

StdCtrls;

const

WM_DATA = WM_USER + 1024;

type

PShareMem = ^TShareMem;

TShareMem = record

Data: array[0..255] of char;

end;

TForm1 = class(TForm)

Button1: TButton;

procedure Button1Click(Sender: TObject);

procedure FormDestroy(Sender: TObject);

procedure FormCreate(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

Form1: TForm1;

PShare: PShareMem;

implementation

{$R *.DFM}

var

HMapping: THandle;

HMapMutex: THandle;

const

MAPFILESIZE = 1000;

REQUEST_TIMEOUT = 1000;

procedure OpenMap; //打开建立共享内存

begin

{创建一个文件映射内核对象}

HMapping := CreateFileMapping(

$FFFFFFFF,

nil,

PAGE_READWRITE,

0,

SizeOf(TShareMem),

pchar(’Map Name’) {映像文件的名字是’Map Name’}

);

if (hMapping = 0) then

begin

ShowMessage(’不能创建内存映射文件’);

Application.Terminate;

exit;

end;

{将映像文件映射到进程的地址空间}

PShare := PShareMem(MapViewOfFile(HMapping, FILE_MAP_ALL_ACCESS, 0, 0, 0));

if PShare = nil then

begin

CloseHandle(HMapping);

ShowMessage(’Can’’t View Memory Map’);

Application.Terminate;

exit;

end;

end;

procedure CloseMap; //关闭共享内存

begin

if PShare <> nil then

{从进程的地址空间中撤消文件数据的映像}

UnMapViewOfFile(PShare);

if HMapping <> 0 then

CloseHandle(HMapping); //关闭映像文件

end;

function LockMap: Boolean; //建立互斥对象

begin

Result := true;

{创建互斥对象}

HMapMutex := CreateMutex(nil, false,

pchar(’MY MUTEX NAME GOES HERE’));

if HMapMutex = 0 then

begin

ShowMessage(’不能创建互斥对象’);

Result := false;

end else begin

if WaitForSingleObject(HMapMutex, REQUEST_TIMEOUT)

= WAIT_FAILED then

begin

ShowMessage(’不能对互斥对象加锁!’);

Result := false;

end;

end;

end;

procedure UnlockMap; //释放互斥对象

begin

ReleaseMutex(HMapMutex);

CloseHandle(HMapMutex);

end;

procedure TForm1.Button1Click(Sender: TObject);

var

str: pchar;

begin

str := pchar(’简单的共享内存的例子’);

CopyMemory(@(pShare^.data), Str, Length(str));

{发送消息表明有数据}

PostMessage(FindWindow(nil, ’映像内存接收端’), WM_DATA, 1, 1)

end;

procedure TForm1.FormDestroy(Sender: TObject);

begin

UnlockMap;

CloseMap;

end;

procedure TForm1.FormCreate(Sender: TObject);

begin

OpenMap;

LockMap;

end;

end.

(3)保存工程为“SendDemo.dpr”。




添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.