Q
quietsky
Unregistered / Unconfirmed
GUEST, unregistred user!
小弟是菜鸟,刚学,不太会,感谢在编写过程中给我帮助的朋友 TYZhang,hotboys,lgxyy,n_y_system.大富翁真是学习的好地方,有这么多热心的朋友.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
NET_API_STATUS = LongInt;
function netmessagebuffersend(servernamewidechar;tonamewidechar;fromnamewidechar;bufwidechar;var buflen:integer):integer;stdcall; external 'netapi32.dll' name 'NetMessageBufferSend'; //声明自库文件中netapi32.dll中引入一个函数,函数的原始名是NetMessageBufferSend,但其作为netmessagebuffersend被引入.
type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
Button2: TButton;
Label3: TLabel;
Edit3: TEdit;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
edit1.Clear;
edit2.Clear;
edit3.Clear;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
string1,string2,string3:string;
pstring1,pstring2:array[0..28] of widechar;
pstring3:array[0..1024] of widechar;
i,j,length,max_length:integer;
begin
length:=28;
max_length:=1025; //发送内容长度
string1:=edit1.Text; //发送者
string2:=edit2.Text; //目的地址
string3:=edit3.Text; //发送内容
for i:=0 to 28 do
begin
pstring1:=#0; //将所有的字节都填充#0字符
stringtowidechar(string1,pstring1,length); //将string类型转换成api函数的pwidechar类型
pstring2:=#0;
stringtowidechar(string2,pstring2,length);
pstring3:=#0;
stringtowidechar(string3,pstring3,length);
end;
netmessagebuffersend(nil,pstring2,pstring1,pstring3,max_length);
j:=netmessagebuffersend(nil,pstring2,pstring1,pstring3,max_length); //用来判断是否发送成功
if j<>0 then
showmessage('send error')
else
showmessage('send success');
end;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
NET_API_STATUS = LongInt;
function netmessagebuffersend(servernamewidechar;tonamewidechar;fromnamewidechar;bufwidechar;var buflen:integer):integer;stdcall; external 'netapi32.dll' name 'NetMessageBufferSend'; //声明自库文件中netapi32.dll中引入一个函数,函数的原始名是NetMessageBufferSend,但其作为netmessagebuffersend被引入.
type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
Button2: TButton;
Label3: TLabel;
Edit3: TEdit;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
edit1.Clear;
edit2.Clear;
edit3.Clear;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
string1,string2,string3:string;
pstring1,pstring2:array[0..28] of widechar;
pstring3:array[0..1024] of widechar;
i,j,length,max_length:integer;
begin
length:=28;
max_length:=1025; //发送内容长度
string1:=edit1.Text; //发送者
string2:=edit2.Text; //目的地址
string3:=edit3.Text; //发送内容
for i:=0 to 28 do
begin
pstring1:=#0; //将所有的字节都填充#0字符
stringtowidechar(string1,pstring1,length); //将string类型转换成api函数的pwidechar类型
pstring2:=#0;
stringtowidechar(string2,pstring2,length);
pstring3:=#0;
stringtowidechar(string3,pstring3,length);
end;
netmessagebuffersend(nil,pstring2,pstring1,pstring3,max_length);
j:=netmessagebuffersend(nil,pstring2,pstring1,pstring3,max_length); //用来判断是否发送成功
if j<>0 then
showmessage('send error')
else
showmessage('send success');
end;
end.