Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 220
Default Check if DLL is registered

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default Check if DLL is registered

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

--
Regards

Juan Pablo González

"R Avery" wrote in message
...
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 220
Default Check if DLL is registered

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.


Juan Pablo González wrote:
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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Class not registered DavidH Excel Discussion (Misc queries) 0 April 16th 06 10:40 PM
i cannot register the key while i registered it before and it wor. annie New Users to Excel 1 November 8th 05 02:50 PM
(R) = Registered Trademark?? J Streger Excel Discussion (Misc queries) 2 September 29th 05 06:18 PM
MsComm32.ocx not registered Eric Excel Programming 1 May 28th 04 10:52 PM
Add-In - Component not correctly registered pietje bell Excel Programming 0 January 29th 04 02:39 PM


All times are GMT +1. The time now is 11:04 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"