本程序介紹如何在局域網(wǎng)內(nèi)安裝了信使服務(wù)的Windows 2000計(jì)算機(jī)之間傳遞消息。
向窗體上添加兩個(gè)TLabel組件、兩個(gè)TEdit組件和一個(gè)TButton組件
首先聲明NetMessageBufferSend函數(shù),該函數(shù)在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’;
在程序運(yùn)行過程中,單擊Send按鈕,就會(huì)向Computer文本框指定的計(jì)算機(jī)發(fā)送Content文本框中輸入的消息,響應(yīng)代碼如下:
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.
    
   
              
              向窗體上添加兩個(gè)TLabel組件、兩個(gè)TEdit組件和一個(gè)TButton組件
首先聲明NetMessageBufferSend函數(shù),該函數(shù)在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’;
在程序運(yùn)行過程中,單擊Send按鈕,就會(huì)向Computer文本框指定的計(jì)算機(jī)發(fā)送Content文本框中輸入的消息,響應(yīng)代碼如下:
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.

