注册dll
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
type
TDllRegisterServer = function:HResult; stdcall;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function RegisterServer(const aDllFileName: string; aRegister: Boolean): Boolean;
type
TRegProc = function: HResult;
stdcall;
const
cRegFuncNameArr: array [Boolean] of PChar =
('DllUnregisterServer', 'DllRegisterServer');
var
vLibHandle: THandle;
vRegProc: TRegProc;
begin
Result := False;
vLibHandle := LoadLibrary(PChar(aDllFileName));
if vLibHandle = 0 then Exit;
@vRegProc := GetProcAddress(vLibHandle, cRegFuncNameArr[aRegister]);
if @vRegProc <> nil then
Result := vRegProc = S_OK;
FreeLibrary(vLibHandle);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
RegisterServer('EASendMailObj.dll',true);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
RegisterServer('EASendMailObj.dll',FALSE);
end;
end.