Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Microsoft: FoxPro FAQ

COM and Automation

Do I have to "RUN RegSvr32.exe" to register an ActiveX OCX file? by wgcs
Posted: 27 Nov 02 (Edited 23 Jan 03)

No, you don't.

Part of the definition of an OCX file (which is really just a renamed .DLL file) is that the self registering / unregistering functions be included in the DLL, so all you have to do is:

1) Load the library
2) Find the entry point for DllRegisterServer or DllUnregisterServer
3) Call the appropriate function.

This is easy to do, but to make it easier, just use the RegSvr function below:

cResult = RegSvr('MyOcx.ocx')     && Register
cResult = RegSvr('MyOcx.ocx',.t.) && Register
cResult = RegSvr('MyOcx.ocx',.f.) && Unregister

* Author.....: William GC Steinford
* Date.......: Jan 23, 2003
* Abstract...: Programmatically Register, Unregister an OCX control
llReg = iif( PCount()>1, plReg, .T. ) && Default to register

DECLARE INTEGER LoadLibrary IN kernel32 As "LoadLibraryA";
    STRING lpLibFileName

lhLib = LoadLibraryA( pcOCX )

if (lhLib < 32) && HINSTANCE_ERROR
  RETURN "ERROR: Could not Load Library "+pcOCX

*// Find the entry point.
DECLARE INTEGER GetProcAddress IN kernel32;  
    INTEGER hModule,;  
    STRING lpProcName

if llReg
  lpRegProc = GetProcAddress(lhLib, 'DllRegisterServer')
  if lpRegProc>0 && Procedure exists!
    DECLARE INTEGER DllRegisterServer IN &pcOCX AS OcxReg
    lnRes = OcxReg()
    if lnRes=0
      RETURN "ERROR: DllRegisterServer returned "+Tran(lnRes)
    * //unable to locate entry point
    RETURN "ERROR: Library "+pcOCX+" has no entry point for DllRegisterServer"
ELSE && Unregister
  lpRegProc = GetProcAddress(lhLib, 'DllUnregisterServer')
  if lpRegProc>0 && Procedure exists!
    DECLARE INTEGER DllUnregisterServer IN &pcOCX AS OcxUnReg
    lnRes = OcxUnReg()
    if lnRes=0
      RETURN "ERROR: DllUnregisterServer returned "+Tran(lnRes)
    * //unable to locate entry point
    RETURN "ERROR: Library "+pcOCX+" has no entry point for DllUnregisterServer"

Back to Microsoft: FoxPro FAQ Index
Back to Microsoft: FoxPro Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close