当前位置:首页 > 网络编程 > 软件语言 > DELPHI > 如何用Delphi实现局域网内消息传递

如何用Delphi实现局域网内消息传递

点击次数:57 次 发布日期:2008-11-09 08:45:55 作者:源代码网
源代码网推荐
广告载入中
本程序介绍如何在局域网内安装了信使服务的Windows 2000计算机之间传递消息。

软件开发网 www.mscto.com

向窗体上添加两个TLabel组件、两个TEdit组件和一个TButton组件

首先声明NetMessageBufferSend函数,该函数在netapi32.dll库中:

type

             NET_API_STATUS = LongInt;

             function NetMessageBufferSend(servername: LPCWSTR; msgname: LPCWSTR;

             fromname: LPCWSTR; buf: Pointer;

             buflen: DWORD): NET_API_STATUS;

             stdcall;external ’netapi32.dll’; 

在程序运行过程中,单击Send按钮,就会向Computer文本框指定的计算机发送Content文本框中输入的消息,响应代码如下:

procedure TForm1.Button1Click(Sender: TObject);

            var

             WideMsg:PWideChar;

             DestName:PWideChar;

            begin

             DestName:=PWideChar(WideString(Edit1.Text));

             WideMsg:=PWideChar(WideString(Edit2.Text));

             NetMessageBufferSend(nil,DestName,nil,WideMsg,Length(Edit2.Text)*2);

            end; 

程序代码如下:

unit Unit1;

            interface

            uses

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

            Dialogs, StdCtrls;

            type

             NET_API_STATUS = LongInt;

             function NetMessageBufferSend(servername: LPCWSTR; msgname: LPCWSTR;

             fromname: LPCWSTR; buf: Pointer;

             buflen: DWORD): NET_API_STATUS;

             stdcall;external ’netapi32.dll’;

            type

             TForm1 = class(TForm)

             Edit1: TEdit;

             Label1: TLabel;

             Label2: TLabel;

             Edit2: TEdit;

             Button1: TButton;

             procedure Button1Click(Sender: TObject);

            private

             { Private declarations }

            public

             { Public declarations }

            end;

            var

             Form1: TForm1;

             implementation

             {$R *.dfm}

             procedure TForm1.Button1Click(Sender: TObject);

            var

             WideMsg:PWideChar;

             DestName:PWideChar;

            begin

             DestName:=PWideChar(WideString(Edit1.Text));

             WideMsg:=PWideChar(WideString(Edit2.Text));

             NetMessageBufferSend(nil,DestName,nil,WideMsg,Length(Edit2.Text)*2);

            end;

            end.  

源代码网推荐

源代码网供稿.
网友评论 (0)
会员中心
网络编程
本站推荐
网络编程之精华