Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Programmatically register an ActiveX control or DLL

Total Hit ( 4972)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


All ActiveX DLL or OCX export two functions: DllRegisterServer and DllUnregisterServer. They are used to register and unregister the ActiveX in the Windows registry, and are usually invoked from regsvr32.exe at registration time.

However, you can register and unregister these files programmatically whenever you want to, provided that you know the name of the DLL or OCX at compile time. All you have to do is prepare two aliased functions, as in the following example, that shows how to register and unregister the COMCTL32.OCX file:

Click here to copy the following block
'function to call to register the ActiveX
Private Declare Function RegComCtl32 Lib "COMCTL32.OCX" Alias _
  "DllRegisterServer" () As Long

' function to call to unregister the ActiveX
Private Declare Function UnRegComCtl32 Lib "COMCTL32.OCX" Alias _
  "DllUnregisterServer" () As Long
Const ERROR_SUCCESS = &H0

Note that the two functions work only if the DLL is in the system path or in the current directory. Therefore, if you want to register a DLL located elsewhere on your hard disk, you must use ChDrive and ChDir commands to make that directory the current one. For example, say that the you have a Test.DLL file in the C:\MyApp directory. Here's the code you need to register it:

Click here to copy the following block
Private Declare Function RegisterTestDLL Lib "Test.Dll" Alias _
  "DllRegisterServer" () As Long
Dim retCode As Long

On Error Resume Next

' move to the DLL's directory
ChDrive "C:"
ChDir "C:\MyApp"
' register the DLL
retCode = RegisterTestDLL()

If Err <> 0 Then
  ' probably the DLL isn't there
  MsgBox "Unable to find the Test.Dll file"
ElseIf retCode <> ERROR_SUCCESS Then
  ' the registration run and failed
  MsgBox "Registration failed"
End If


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.