unit Unit1;

interface

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

type 
  TForm1 =class (TForm)
    Button1: TButton;
    procedure Button1Click (Sender: TObject);
  private
     {Private declarations}
  public
     {Public declarations}
  end ;

var
  Form1: TForm1;

// MB function declaration:
function MB (hWnd: HWND; lpText, lpCaption: PChar; uType: UINT): Integer;stdcall ;

implementation

{$ R * .dfm}
{Call a function in an external DLL, such as calling MessageBoxA in the system user32.dll}
// function MB (hWnd: HWND; lpText, lpCaption: PChar; uType: UINT): Integer;
// stdcall; external user32 name 'MessageBoxA';

{Where user32 is the constant 'user32.dll' defined by Delphi, which can be written directly:}
// function MB (hWnd: HWND; lpText, lpCaption: PChar; uType: UINT): Integer;
// stdcall; external 'user32.dll' name 'MessageBoxA';

{name indicates the real name of the function}
{external clause indicates that the function is loaded when the unit is loaded, that is, early binding; if late binding requires LoadLibrary}
{stdcall instruction indicates that the parameter is passed from right to left (the opposite is true for Pascal), not passed through the CPU register

{4 parameter data types can use the corresponding Delphi data types, such as:}
// function MB (hWnd: LongWord; lpText, lpCaption: PChar; uType: LongWord): Integer;
// stdcall; external 'user32.dll' name 'MessageBoxA';

{or it could be:}
// function MB (hWnd: Cardinal; lpText, lpCaption: PChar; uType: Cardinal): Integer;
// stdcall; external 'user32.dll' name 'MessageBoxA';

{If the function is declared in this unit and needs to be called by other units, it needs to be declared in the interface area first:}
// function MB (hWnd: Cardinal; lpText, lpCaption: PChar; uType: Cardinal): Integer;
// stdcall;
{This example has already done this, if you want to test several other cases, you need to comment it out first}
{Then explain the source of the function in the implementation area:}
function MB;external 'user32.dll' name 'MessageBoxA';

// Call test:
procedure TForm1.Button1Click (Sender: TObject);
var
  t, b: PChar;
begin 
  t: ='title';
  b: = 'content';
  MB (0, b, t,0);
end ;

end .