HOWTO: Programmatically Register and UnRegister .OCX FilesID: Q173091
|
This article describes how to programmatically register and unregister
ActiveX controls (.OCXs).
Microsoft Visual Basic ships with several ActiveX controls (.OCX files).
These files are automatically registered by the Visual Basic setup program
during installation. Developers often desire to register or unregister
these and/or their own controls at will. This can be accomplished by using
a tool such as RegSvr32.EXE or it can be done programmatically through
Visual Basic code.
The ActiveX control framework supports the DllRegisterServer and
DllUnregisterServer entry points. These entry points can be declared as
functions in your Visual Basic code and then called to register and
unregister the ActiveX control.
The following example demonstrates how to write a code module that can be
used to register and unregister an ActiveX control, specifically the
Microsoft Windows Common Controls found in ComCtl32.OCX.
Public Declare Function RegComCtl32 Lib "ComCtl32.OCX" _
Alias "DllRegisterServer" () As Long
Public Declare Function UnRegComCtl32 Lib "ComCtl32.OCX" _
Alias "DllUnregisterServer" () As Long
Public Const S_OK = &H0
Sub RegisterComCtl32()
On Error GoTo Err_Registration_Failed
If RegComCtl32 = S_OK Then
MsgBox "Registered Successfully"
Else
MsgBox "Not Registered"
End If
Exit Sub
Err_Registration_Failed:
MsgBox "Error: " & Err.Number & " " & Err.Description
End Sub
Sub UnRegisterComCtl32()
On Error GoTo Err_Unregistration_Failed
If UnRegComCtl32 = S_OK Then
MsgBox "Unregistered Successfully"
Else
MsgBox "Not Unregistered"
End If
Exit Sub
Err_Unregistration_Failed:
MsgBox "Error: " & Err.Number & " " & Err.Description
End Sub
UnRegisterComCtl32
Press the ENTER key to unregister ComCtl32.OCX, and then type:
RegisterComCtl32
and press the ENTER key to register the control.
Keywords : kbnokeyword kbVBp500 kbVBp600
Version :
Platform :
Issue type : kbhowto
Last Reviewed: May 11, 1999