[TRUCO DELPHI] Registrar y Desinstalar un ActiveX en Delphi.
Declaración de Tipos.
delphi
type TDllRegisterServer = function: HResult; stdcall;
Función para registrar. [MÉTODO 1]
delphi
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;
Des Instalar o No Registrar.
delphi
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;
Registrar [MÉTODO 2]
delphi
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;
Saludos! @Sir.Dev.A.Lot "Ya he comenzado."