unit SendMsgUnit;
interface
uses SysUtils, Classes;
function ToUnicode(str:string;dest
WideChar):integer;
function SendMsg(Toh,From,Msg:string):integer;
function NetMessageBufferSend(servername
WideChar;
MsgName
WideChar;
FromName
WideChar;
Buf: PWideChar;
var BufLen:integer):integer;cdecl;
implementation
function ToUnicode(str:string;dest
WideChar):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()