Mega Code Archive

 
Categories / Delphi / Examples
 

How to register an ocx

Your installation program needs to register an OCX, but doesn't support this? Or you want to register it by your program yourself? Suppose the OCX you want to use is called Test.ocx program RegisterMyOCX; uses OLECtl, Windows, Dialogs; var OCXHand: THandle; RegFunc: TDllRegisterServer; //add to the uses clause begin OCXHand:= LoadLibrary('c:\windows\system\test.ocx'); RegFunc:= GetProcAddress(OCXHand, 'DllRegisterServer'); //case sensitive if RegFunc <> 0 then RegFunc else ShowMessage('Error!') FreeLibrary(OCXHand); // You can the same way unregister the OCX: // replace 'DllRegisterServer' by 'DllUnregisterServer' end.