830
社区成员
发帖
与我相关
我的任务
分享unit DLLMain;
interface
uses
windows,sysutils;
(*注册*)
function DLLReg(const FileName:PChar):Boolean;export;stdcall;
(*反注册*)
function DLLUnReg(const FileName:PChar):Boolean;export;stdcall;
type
DLLRegProc=function :HResult;
implementation
(*注册*)
function DLLReg(const FileName:PChar):Boolean;export;stdcall;
var
lib: THandle;
func:TFarProc;
DLLRegProcL:DLLRegProc;
begin
Result:=false;
if not FileExists(FileName) then exit;
lib := LoadLibrary(PChar(FileName));
if(lib=0) then exit;
try
func:=GetProcAddress(lib,'DllRegisterServer');
if not Assigned(func) then exit;
DLLRegProcL:=DLLRegProc(func);
Result:=DLLRegProcL=S_OK;
finally
FreeLibrary(lib);
end;
end;
(*反注册*)
function DLLUnReg(const FileName:PChar):Boolean;stdcall;
var
lib: THandle;
func:TFarProc;
DLLRegProcL:DLLRegProc;
begin
Result:=false;
if not FileExists(FileName) then exit;
lib := LoadLibrary(PChar(FileName));
if(lib=0) then exit;
try
func:=GetProcAddress(lib,'DllUnregisterServer');
if not Assigned(func) then exit;
DLLRegProcL:=DLLRegProc(func);
Result:=DLLRegProcL=S_OK;
finally
FreeLibrary(lib);
end;
end;
end.