Solved

Dynamically registering DLLs

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…

708 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

18 Experts available now in Live!

Get 1:1 Help Now