2006. szeptember 6., szerda

How to register an OCX


Problem/Question/Abstract:

How to register an OCX

Answer:

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


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.

Nincsenek megjegyzések:

Megjegyzés küldése