Solved

Dynamically registering DLLs

Posted on 2004-09-03
5
230 Views
Last Modified: 2010-05-02
I can't remember where I got the code below from, but it's my only example of how to programmatically register a dll.  However, if the name of the dll is to be passed to the function at runtime, how do I get it to register without declaring the dll as a function?



'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:
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
0
Comment
Question by:kinton
  • 2
  • 2
5 Comments
 
LVL 18

Accepted Solution

by:
JR2003 earned 250 total points
ID: 11970950
0
 
LVL 8

Expert Comment

by:mladenovicz
ID: 11970951
0
 
LVL 8

Expert Comment

by:mladenovicz
ID: 11970954
JR2003 was faster
;)
0
 
LVL 2

Author Comment

by:kinton
ID: 11971545
Cool, thanks guys - just testing it with my program....
0
 
LVL 2

Author Comment

by:kinton
ID: 12224995
Well it works on my machine!  Sending it out to about 40 reps should be the ultimate test though!

Thanks for the link.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

697 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question