[RESOLVED] Determine if ocx is registered
I have very through error checking in my app., but sometimes i get reports
that my app will not run, with an error message:
"missing components after deployment'". So my does not even start. my plan is to create a exe that will check for all the files my app installs and will tell me if the ocx's are registered. How to determine if an ocx is registered ?
Re: Determine if ocx is registered
Use Createobject to create an instance of it (with an error handler), if there is no error then it is installed (so destroy your instance).
Re: Determine if ocx is registered
Quote:
Originally Posted by
si_the_geek
Use Createobject to create an instance of it (with an error handler), if there is no error then it is installed (so destroy your instance).
Would i not have to try to use it to determine if registered ?
Re: Determine if ocx is registered
One more way...
When you open the OCX with OleView.exe, you will see a UUID. Check in registry if this exists
HKCR\CLSID\{uuid}
Re: Determine if ocx is registered
Quote:
Originally Posted by
isnoend07
Would i not have to try to use it to determine if registered ?
No, if the class you requested is not available (ie: it is not registered) then CreateObject will fail.
Re: Determine if ocx is registered
Quote:
Originally Posted by
koolsid
One more way...
When you open the OCX with OleView.exe, you will see a UUID. Check in registry if this exists
HKCR\CLSID\{uuid}
what is OleView.exe ? Don't want to add another exe
Re: Determine if ocx is registered
Not sure how well this works but seen it used to determine if a DLL is registered, seems to work for OCX as well...
Code:
Option Explicit
Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
Private Sub Form_Click()
If IsDLLAvailable("TABCTL32.OCX") Then
MsgBox "DLL or OCX passed!"
Else
MsgBox "DLL or OCX Failed!"
' MsgBox ApiErrorText(Err.LastDllError)
' for ApiErrorText, see: http://www.mvps.org/vb/index2.html?tips/formatmessage.htm
End If
End Sub
Function IsDLLAvailable(ByVal DllFilename As String) As Boolean
Dim hModule As Long
' attempt to load the module
hModule = LoadLibrary(DllFilename)
If hModule > 32 Then
FreeLibrary hModule ' decrement the DLL usage counter
IsDLLAvailable = True
End If
End Function
Re: Determine if ocx is registered
Quote:
Originally Posted by
Edgemeal
Not sure how well this works but seen it used to determine if a DLL is registered, seems to work for OCX as well...
Code:
Option Explicit
Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
Private Sub Form_Click()
If IsDLLAvailable("TABCTL32.OCX") Then
MsgBox "DLL or OCX passed!"
Else
MsgBox "DLL or OCX Failed!"
' MsgBox ApiErrorText(Err.LastDllError)
' for ApiErrorText, see: http://www.mvps.org/vb/index2.html?tips/formatmessage.htm
End If
End Sub
Function IsDLLAvailable(ByVal DllFilename As String) As Boolean
Dim hModule As Long
' attempt to load the module
hModule = LoadLibrary(DllFilename)
If hModule > 32 Then
FreeLibrary hModule ' decrement the DLL usage counter
IsDLLAvailable = True
End If
End Function
thanks for adding that, upon testing a ocx i have it reports: MsgBox "DLL or OCX passed!" even after i unregister it
Re: Determine if ocx is registered
Quote:
Originally Posted by
isnoend07
thanks for adding that, upon testing a ocx i have it reports: MsgBox "DLL or OCX passed!" even after i unregister it
Oh well that sucks, sorry if i wasted your time.
Re: Determine if ocx is registered
Quote:
Originally Posted by
Edgemeal
Oh well that sucks, sorry if i wasted your time.
No problem. thanks for adding that
Re: Determine if ocx is registered
OleView.exe is used to find the uuid. It's not to be integrated... anyways
See if this helps you...
http://www.vbforums.com/showthread.php?t=544424
or this
http://www.foxite.com/archives/find-...0000078365.htm
Re: Determine if ocx is registered
most of the examples i have found want to register the ocx which i do not want as this would require admin privileges. looks like the best way is to check if it exists and do as si_the_geek suggested and try to use one of it's methods or properties and trap the error. I have a suspicion that the error is so seldom that it occurs because the user has copied the exe to another PC without running the setup.
Re: Determine if ocx is registered
Quote:
Originally Posted by
isnoend07
as si_the_geek suggested and try to use one of it's methods or properties and trap the error.
That is not what I suggested, in fact I explicitly said you do not need to do that - all you need to do is try to create an instance.
If it isn't registered, that part is guaranteed to fail.
Adding more to the process just adds room for mistakes in your code, and takes more time to do so.
Re: Determine if ocx is registered
Quote:
Originally Posted by
si_the_geek
That is not what I suggested, in fact I explicitly said you do not need to do that - all you need to do is try to create an instance.
If it isn't registered, that part is guaranteed to fail.
Adding more to the process just adds room for mistakes in your code, and takes more time to do so.
thanks for adding that, never realized it was so difficult to declare some objects. eg; 'get object's class name.
Code:
Private Sub Form_Load()
'include a reference to "TypeLib Information" (Project -> References...")
Dim t As TypeLibInfo
Set t = TLI.TypeLibInfoFromFile("CommComponent.OCX")
MsgBox t.Guid & vbCrLf & t.Name
Dim s As SearchItem
For Each s In t.GetTypes
MsgBox t.Name & "." & s.Name
Next
End Sub
Re: [RESOLVED] Determine if ocx is registered
You can easily find the class name in your original project, by using the full data type name for one of the creatable objects.
For example, with ADO code you have Recordset objects, and a declaration with the full data type name is like this:
Code:
Dim objRS as ADODB.Recordset
The library (the ADODB part) is listed at the top of the Object Browser.
..so for your program doing the testing, you would use something like this:
Code:
Set objTest = CreateObject("ADODB.Recordset")
You almost certainly only need to check one object per library.
Re: Determine if ocx is registered
Quote:
Originally Posted by
isnoend07
thanks for adding that, never realized it was so difficult to declare some objects. eg; 'get object's class name.
Code:
Private Sub Form_Load()
'include a reference to "TypeLib Information" (Project -> References...")
Dim t As TypeLibInfo
Set t = TLI.TypeLibInfoFromFile("CommComponent.OCX")
MsgBox t.Guid & vbCrLf & t.Name
Debug.Print t.Guid
End Sub
This trick is useful when compatibility of ocx was broken during ActiveX development time. Once we know the GUID then we can modify the vbp file to supply right GUID.