Results 1 to 16 of 16

Thread: [RESOLVED] Determine if ocx is registered

  1. #1

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Resolved [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 ?
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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).

  3. #3

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: Determine if ocx is registered

    Quote Originally Posted by si_the_geek View Post
    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 ?
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  4. #4
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    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}
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Determine if ocx is registered

    Quote Originally Posted by isnoend07 View Post
    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.

  6. #6

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: Determine if ocx is registered

    Quote Originally Posted by koolsid View Post
    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
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  7. #7
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    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

  8. #8

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: Determine if ocx is registered

    Quote Originally Posted by Edgemeal View Post
    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
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  9. #9
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: Determine if ocx is registered

    Quote Originally Posted by isnoend07 View Post
    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.

  10. #10

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: Determine if ocx is registered

    Quote Originally Posted by Edgemeal View Post
    Oh well that sucks, sorry if i wasted your time.
    No problem. thanks for adding that
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  11. #11
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    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
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  12. #12

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    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.
    Last edited by isnoend07; Feb 26th, 2010 at 05:51 PM. Reason: more to add
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  13. #13
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Determine if ocx is registered

    Quote Originally Posted by isnoend07 View Post
    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.

  14. #14

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: Determine if ocx is registered

    Quote Originally Posted by si_the_geek View Post
    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
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  15. #15
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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.

  16. #16
    Frenzied Member
    Join Date
    Jan 2010
    Posts
    1,103

    Re: Determine if ocx is registered

    Quote Originally Posted by isnoend07 View Post
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width