unit DLLMain;interfaceuses
windows,sysutils;(*注册*)functionDLLReg(const FileName:PChar):Boolean;export;stdcall;(*反注册*)functionDLLUnReg(const FileName:PChar):Boolean;export;stdcall;
type
DLLRegProc=function:HResult;implementation(*注册*)functionDLLReg(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;finallyFreeLibrary(lib);
end;
end;(*反注册*)functionDLLUnReg(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;finallyFreeLibrary(lib);
end;
end;
end.