局域网之间如何发送消息(50分)

  • 主题发起人 主题发起人 lhy2008
  • 开始时间 开始时间
L

lhy2008

Unregistered / Unconfirmed
GUEST, unregistred user!
打“运行”输入"net send 192.168.0.1 message"可以给192.168.0.1发送信息,这种功能如何用
delphi 编程实现!
 
unit SendMsgUnit;
interface
uses SysUtils, Classes;

function ToUnicode(str:string;dest:PWideChar):integer;
function SendMsg(Toh,From,Msg:string):integer;
function NetMessageBufferSend(servername:PWideChar;
MsgName:PWideChar;
FromName:PWideChar;
Buf: PWideChar;
var BufLen:integer):integer;cdecl;
implementation

function ToUnicode(str:string;dest:PWideChar):integer;
var
len:integer;
begin
//len:=0;
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;
FromName :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 64 do FromName := #0;
ToUnicode(From,FromName);

for i := 0 to 1000 do WMsgText := #0;
ToUnicode(Msg,WMsgText);

Result:=NetMessageBufferSend(nil,ToName,nil,@WMsgText,MsgLen);
end;

end.

===============================================================
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls,SendMsgUnit;

type
TForm1 = class(TForm)
btnButton1: TButton;
edtEdit1: TEdit;
procedure btnButton1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation
//uses SendMsgUnit;
{$R *.DFM}

procedure TForm1.btnButton1Click(Sender: TObject);
begin
if SendMsg(edtedit1.text,'hello','hello')<0 then caption:=caption+'~';
end;

end.

==============================================================
另一个办法是用WinExec()
 
winexec怎么用?
 
WinExec('net send 192.168.0.1 message',SW_HIDE);
 
如何向局域网内所有计算机发信息啊!
 
接受答案了.
 
后退
顶部