Delphi implementation in the LAN transfer message program

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.