Solved

Dynamically registering DLLs

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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…

777 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