Link to home
Start Free TrialLog in
Avatar of lgallion
lgallion

asked on

How to detect if a OCX is registered before app generates an error because it is not

I have a Delphi app and I have integrated a 3rd party PDF reader OCX, however the problem is I can't check to see if the OCX is registered (and fix the problem by registering it) before the app crashes with a Kernal32 error (because the OCX is embedded in the main form).  I know I could fix this with an installer (which registers the OCX) but it would be alot more elegant if the program could check for the proper registration and then register it before finishing initialization.  Is there any way to do this?

First thing in my main form's OnCreate I am calling this code (but unfortunately it never gets called):

procedure RegisterOCX;
var
  OCXHand: THandle;
begin
  OCXHand:=LoadLibrary('L:\APPS\Family Services\FSWorkflow\VSPDFViewerX.ocx');

  // If OCX didn't load (OCXHand = 0) then attempt to register it
  if OCXHand = 0 then
  begin
    if (GetProcAddress(OCXHand,'DllRegisterServer')<> nil) then
    begin
      StandardEurekaError('Error Registering OCX VSPDFViewerX');
    end;
  end;
  FreeLibrary(OCXHand);
end;
SOLUTION
Avatar of mokule
mokule
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Russell Libby
You need to perform that logic in the project source BEFORE the Application creates an instance of the main form, otherwise its too late and the error will occur.

Regards,
Russell
Too slow on this one ;-)

Russell
Run regsvr32 YourOCX.ocx to register it (it the file exists)
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lgallion
lgallion

ASKER

Thanks guys excellent feedback!  Kudos to mokule for a quick reply, nods to atul_parmar for pointing me in a better direction and a big thanks to rllibby for a super indepth answer.