Solved

Dynamically registering DLLs

Posted on 2004-09-03
5
226 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

948 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now