[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Dynamically registering DLLs

Posted on 2004-09-03
5
Medium Priority
?
237 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 18

Accepted Solution

by:
JR2003 earned 1000 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses

656 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