变
变成浪子
Unregistered / Unconfirmed
GUEST, unregistred user!
我的环境是win2000加D6。
我用了两个单元。
unit main;
interface
uses Unit2, //使用vUnit2.pas
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ExtCtrls;
type
TfrmMain = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
Label1: TLabel;
AddrBox: TComboBox;
BitBtn1: TBitBtn;
Panel3: TPanel;
Panel4: TPanel;
BitBtn2: TBitBtn;
BitBtn3: TBitBtn;
Panel5: TPanel;
MesText: TMemo;
StatusLabel: TLabel;
procedure BitBtn1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure MesTextChange(Sender: TObject);
procedure AddrBoxChange(Sender: TObject);
private
UserName:string;
MessageHeader:TStringList;
{ Private declarations }
public
{ Public declarations }
end;
var
frmMain: TfrmMain;
implementation
uses about;
{$R *.dfm}
procedure TfrmMain.BitBtn1Click(Sender: TObject);
var
i,res:integer;
begin
if AddrBox.Text<>'' then
begin
StatusLabel.Font.Color:=clBlack;
StatusLabel.Caption:='Wait...';
Update;
if AddrBox.Items.IndexOf(AddrBox.Text)=-1 then
AddrBox.Items.Add(Addrbox.Text);
res:=SendMsg(AddrBox.Text,'',MessageHeader.Text+mesText.text);
if res=0 then
frmMain.StatusLabel.Font.Color:=clBlue
else
frmMain.StatusLabel.Font.Color:=clRed;
case res of
0 :frmMain.StatusLabel.Caption:='The message is sent';
87 :frmMain.StatusLabel.Caption:='The parameter is incorrect';
123 :frmMain.StatusLabel.Caption:='Sintax is incorrect';
2273 :frmMain.StatusLabel.Caption:='Can not find'+frmMain.addrBox.Text;
else
frmMain.StatusLabel.Caption:='Error:'+IntToStr(res);
end;
end;
end;
procedure TfrmMain.FormCreate(Sender: TObject);
var
strUserChar;
strSizeWord;
begin
MesText.Lines.Clear; //清空
struser:=StrAlloc(100); //为strUser分配内存
strSize:=100;
GetUserName(strUser,strSize); //获得当前登入的用户名
UserName:=strUser;
StrDispose(strUser); //释放内存
MessageHeader:=TStringList.Create;
Messageheader.Add('-------------------');
Messageheader.Add(' from'+UserName);
Messageheader.Add('-------------------');
end;
procedure TfrmMain.MesTextChange(Sender: TObject);
begin
StatusLabel.Caption:='';
end;
procedure TfrmMain.AddrBoxChange(Sender: TObject);
begin
StatusLabel.Caption:='';
end;
end.
第二单元
unit Unit2;
interface
uses SysUtils,Classes;
function ToUnicode(str:string;destWideChar):integer;
function SendMsg(Toh,From,Msg:string):integer;
function NetMessageBufferSend(servernameWideChar;
MsgNameWideChar;
BufWideChar;
var BufLen:integer):integer;cdecl;
implementation
function ToUnicode(str:string;destWideChar):integer;
var
len:integer;
begin
StringToWideChar(str,dest,len);
Result:=len;
end;
function NetMessageBufferSend; external'netapi32.dll' name 'NetmessageBufferSend';
function SendMsg(Toh,From,Msg:string):integer;
var
ToName:array[0..64] of WideChar;
WMsgText:array[0..1000] of WideChar;
MsgLen,i:integer;
begin
for i:=0 to 64 do ToName:=#0;
ToUnicode(Toh,ToName);
for i:=0 to 1000 do WMsgText:=#0;
ToUnicode(Msg,WMsgText);
Result:=NetMessageBufferSend(nil,ToName,nil,@WMsgText,MsgLen);
end;
end.
编译时说Result:=NetMessageBufferSend(nil,ToName,nil,@WMsgText,MsgLen);变量不符合。
我用了两个单元。
unit main;
interface
uses Unit2, //使用vUnit2.pas
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ExtCtrls;
type
TfrmMain = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
Label1: TLabel;
AddrBox: TComboBox;
BitBtn1: TBitBtn;
Panel3: TPanel;
Panel4: TPanel;
BitBtn2: TBitBtn;
BitBtn3: TBitBtn;
Panel5: TPanel;
MesText: TMemo;
StatusLabel: TLabel;
procedure BitBtn1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure MesTextChange(Sender: TObject);
procedure AddrBoxChange(Sender: TObject);
private
UserName:string;
MessageHeader:TStringList;
{ Private declarations }
public
{ Public declarations }
end;
var
frmMain: TfrmMain;
implementation
uses about;
{$R *.dfm}
procedure TfrmMain.BitBtn1Click(Sender: TObject);
var
i,res:integer;
begin
if AddrBox.Text<>'' then
begin
StatusLabel.Font.Color:=clBlack;
StatusLabel.Caption:='Wait...';
Update;
if AddrBox.Items.IndexOf(AddrBox.Text)=-1 then
AddrBox.Items.Add(Addrbox.Text);
res:=SendMsg(AddrBox.Text,'',MessageHeader.Text+mesText.text);
if res=0 then
frmMain.StatusLabel.Font.Color:=clBlue
else
frmMain.StatusLabel.Font.Color:=clRed;
case res of
0 :frmMain.StatusLabel.Caption:='The message is sent';
87 :frmMain.StatusLabel.Caption:='The parameter is incorrect';
123 :frmMain.StatusLabel.Caption:='Sintax is incorrect';
2273 :frmMain.StatusLabel.Caption:='Can not find'+frmMain.addrBox.Text;
else
frmMain.StatusLabel.Caption:='Error:'+IntToStr(res);
end;
end;
end;
procedure TfrmMain.FormCreate(Sender: TObject);
var
strUserChar;
strSizeWord;
begin
MesText.Lines.Clear; //清空
struser:=StrAlloc(100); //为strUser分配内存
strSize:=100;
GetUserName(strUser,strSize); //获得当前登入的用户名
UserName:=strUser;
StrDispose(strUser); //释放内存
MessageHeader:=TStringList.Create;
Messageheader.Add('-------------------');
Messageheader.Add(' from'+UserName);
Messageheader.Add('-------------------');
end;
procedure TfrmMain.MesTextChange(Sender: TObject);
begin
StatusLabel.Caption:='';
end;
procedure TfrmMain.AddrBoxChange(Sender: TObject);
begin
StatusLabel.Caption:='';
end;
end.
第二单元
unit Unit2;
interface
uses SysUtils,Classes;
function ToUnicode(str:string;destWideChar):integer;
function SendMsg(Toh,From,Msg:string):integer;
function NetMessageBufferSend(servernameWideChar;
MsgNameWideChar;
BufWideChar;
var BufLen:integer):integer;cdecl;
implementation
function ToUnicode(str:string;destWideChar):integer;
var
len:integer;
begin
StringToWideChar(str,dest,len);
Result:=len;
end;
function NetMessageBufferSend; external'netapi32.dll' name 'NetmessageBufferSend';
function SendMsg(Toh,From,Msg:string):integer;
var
ToName:array[0..64] of WideChar;
WMsgText:array[0..1000] of WideChar;
MsgLen,i:integer;
begin
for i:=0 to 64 do ToName:=#0;
ToUnicode(Toh,ToName);
for i:=0 to 1000 do WMsgText:=#0;
ToUnicode(Msg,WMsgText);
Result:=NetMessageBufferSend(nil,ToName,nil,@WMsgText,MsgLen);
end;
end.
编译时说Result:=NetMessageBufferSend(nil,ToName,nil,@WMsgText,MsgLen);变量不符合。
代码: