Check if DLL is registered

R

R Avery

Is there any way to check whether or not a particular DLL is registered?
The problem I have is that some of my .xla's require certain network
DLL's to be registered, but I do not want to have to re-register these
DLL's every time i load the .xla, since registering a DLL takes about
0.1 second each on my 3 Ghz comp.

I thought perhaps instead I could much more quickly check to see if a
particular DLL is registered, and then if not, register it. Is this
possible?




The code I use to register DLL's is below:



Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As
Long) As Long
Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA"
(ByVal lpLibFileName As String) As Long
Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As
Long, ByVal lpProcName As String) As Long
Private Declare Function CallWindowProc Lib "user32" Alias
"CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long,
ByVal Msg As Any, ByVal wParam As Any, ByVal lParam As Any) As Long
Private Const ERROR_SUCCESS = &H0
Private Const ERROR_AHHHHHH = &HF

Public Function RegisterServer(hwnd As Long, DllServerPath As String,
bRegister As Boolean) As Boolean
On Error Resume Next

Dim lb As Long, pa As Long

lb = LoadLibrary(DllServerPath)
If bRegister Then
pa = GetProcAddress(lb, "DllRegisterServer")
Else
pa = GetProcAddress(lb, "DllUnregisterServer")
End If

If CallWindowProc(pa, hwnd, ByVal 0&, ByVal 0&, ByVal 0&) =
ERROR_SUCCESS Then
RegisterServer = True
Else
RegisterServer = False
End If
FreeLibrary lb
End Function
 
J

Juan Pablo González

I just use a simple 'On Error Resume Next' routine for the dlls that I write
in conjunction with the vba code:

On Error Resume Next
Set Obj = CreateObject("MyDll.MyClass")
On Error Goto 0

If Obj Is Nothing Then
MsgBox "MyDll is not correctly installed"
End If
 
R

R Avery

I have tested this for speed and it is about 33-100 times faster than
registering the DLL every time. So is the best idea to always include
some lightweight test class in every DLL object library I create whose
sole purpose is testing whether or not the DLL is registered?

This approach is definitely far superior to my old approach, but I still
feel as though there should be some (elegant) way to test for the
registration directly. For example, using the TLI.TLIApplication object
to test this? I have scanned through the objects functions and
properties, but I do not see an obvious way how to do this.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top