delphi中用代码实现注册Ocx和Dll
2021-01-03 03:28
标签:address call 代码实现 oca ide var cad windows系统 win 在windows系统中,可以通过Regsvr32来实现注册ocx或者dl, 编程时,调用Regsvr32来注册,却不能正常执行。尤其是在Win7系统中,需要管理员身份才能运行。 使用下面的代码则能正常注册。 delphi中用代码实现注册Ocx和Dll 标签:address call 代码实现 oca ide var cad windows系统 win 原文地址:https://www.cnblogs.com/yclizq/p/13212069.html//注册
function RegisterDllServer(FileName: string): boolean;
var
nDllAddr: integer;
bstr: string;
ProcAddr: Pointer;
str: PAnsiChar;
begin
Result := False;
if not FileExists(FileName) then
exit;
nDllAddr:=LoadLibrary(PWideChar(FileName));
if nDllAddr 0 then
begin
bstr:=‘DllRegisterServer‘+chr(0);
str := PAnsiChar(AnsiString(bstr));
ProcAddr := GetProcAddress(nDllAddr,str);
if ProcAddrnil then
begin
CallWindowProc(ProcAddr,nDllAddr,0,0,0);
Result := True;
end;
FreeLibrary(nDllAddr);
end;
end;
//反注册
function UnRegisterDllServer(FileName: string): boolean;
var
nDllAddr: integer;
bstr: string;
ProcAddr: Pointer;
str: PAnsiChar;
begin
Result := False;
if not FileExists(FileName) then
exit;
nDllAddr:=LoadLibrary(PWideChar(FileName));
if nDllAddr 0 then
begin
bstr:=‘DllUnregisterServer‘+chr(0);
str := PAnsiChar(AnsiString(bstr));
ProcAddr := GetProcAddress(nDllAddr,str);
if ProcAddrnil then
begin
CallWindowProc(ProcAddr,nDllAddr,0,0,0);
Result := True;
end;
FreeLibrary(nDllAddr);
end;
end;
文章标题:delphi中用代码实现注册Ocx和Dll
文章链接:http://soscw.com/index.php/essay/39730.html