ActiveX controls are typically implemented in .dll or .ocx files. They self-register through their DllRegisterServer
function. Which is what your code does.
The way you test the return value of DllRegisterServer
is a little off. And there are a couple of other areas which could be improved. I would have the code like this:
var
hMod: HMODULE;
....
hMod := LoadLibrary(PChar(OCXFl));
if hMod = 0 then
begin
WriteLn('Error registering OCX! Press Enter to continue..');
Readln;
exit;
end;
try
RegFunc := GetProcAddress(hMod, 'DllRegisterServer');
if not Assigned(RegFunc) then
begin
WriteLn('Error registering OCX! Press Enter to continue..');
Readln;
exit;
end;
if not Succeeded(RegFunc()) then
begin
WriteLn('Error registering OCX! Press Enter to continue..');
Readln;
exit;
end;
finally
FreeLibrary(hMod);
end;
Although I might prefer a slightly different error reporting mechanism, I have stuck with your approach.