This procedure describes how to pass messages between Windows 2000 computers where the Messenger service is installed on a local area network.
Add two Tlabel components, two tedit components, and a TButton component to the form, as shown in Figure 1 of the finished design.
Figure 1 Main interface
First, declare the Netmessagebuffersend function, which is in the Netapi32.dll library:
type
NET_API_STATUS = LongInt;
function NetMessageBufferSend(servername: LPCWSTR; msgname: LPCWSTR;
fromname: LPCWSTR; buf: Pointer;
buflen: DWORD): NET_API_STATUS;
stdcall;external 'netapi32.dll';
When the program is running, clicking the Send button sends the message entered in the Content text box to the computer specified in the Computer text box with the following response code:
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;
The program code is as follows:
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.