type TDllRegisterServer = function: HResult; stdcall;
function RegisterOCX(FileName: string): Boolean; var OCXHand: THandle;
RegFunc: TDllRegisterServer; begin OCXHand := LoadLibrary(PChar(FileName));
RegFunc := GetProcAddress(OCXHand, 'DllRegisterServer'); if @RegFunc <> nil then Result := RegFunc = S_OK else Result := False;
FreeLibrary(OCXHand); end;
function UnRegisterOCX(FileName: string): Boolean; var OCXHand: THandle;
RegFunc: TDllRegisterServer; begin OCXHand := LoadLibrary(PChar(FileName));
RegFunc := GetProcAddress(OCXHand, 'DllUnregisterServer'); if @RegFunc <> nil then Result := RegFunc = S_OK else Result := False;
FreeLibrary(OCXHand); end;
{**********}
{2.}
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;