Results 1 to 11 of 11

Thread: [RESOLVED] Detecting OCX Files

  1. #1

    Thread Starter
    Hyperactive Member Fedhax's Avatar
    Join Date
    Aug 2006
    Posts
    293

    Resolved [RESOLVED] Detecting OCX Files

    I'm rather weary about posting this question, but I have spent upwards of a day searching through the forums here and through Google's results. When someone asks "How can I detect what OCX files have been installed on an end user's system?", the answers usually end up along the lines of "Why care? Make an installer, register it, and forget about it." End of discussion.

    Now, this answer is fine for the initial installation, but I want to be able to check for these things every time the application is started. Instead of throwing out an error message--even if it is through my error handling routines--"429: Unable to create object", I'd like to then go through a check list and see which files are causing this 429 error. Maybe a software reinstall will fix it, but for the sake of testing--and for the sake of my testers--I'd like to give something more tangible to bite on especially since my testers are also computer programmers. Heck, if I knew exactly how the error was occuring, maybe I could do some fixes behind the scenes without the end user noticing--unless they look in the log file.

    I've seen code where you try to verify if a DLL is registered:
    VB Code:
    1. Public Function Foo() As Boolean
    2.    On Error Goto EndofFoo
    3.  
    4.    Dim lb  as Boolean
    5.    Dim lo  as Object
    6.  
    7.    Set lo = CreateObject("Dll.Class")
    8.  
    9.    lb = True
    10.    Foo = lb
    11.    Exit Function
    12.  
    13. EndofFoo:
    14.    lb = False
    15.    Foo = lb
    16.  
    17. End Function

    However, if I want to see if they have/need MSFlxGrd.OCX, what would I do to check for it, or is it even possible?
    Last edited by Fedhax; Aug 22nd, 2006 at 05:14 PM. Reason: Minor Corrections

  2. #2
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: Detecting OCX Files

    look in the registry for the key ..

    example the MsFlex thing is this ..

    {6262D3A0-531B-11CF-91F6-C2863C385E30}

  3. #3

    Thread Starter
    Hyperactive Member Fedhax's Avatar
    Join Date
    Aug 2006
    Posts
    293

    Re: Detecting OCX Files

    Quote Originally Posted by rory
    look in the registry for the key ..

    example the MsFlex thing is this ..

    {6262D3A0-531B-11CF-91F6-C2863C385E30}
    So I would need to verify that the file physically exists on the machine along side with the registry key for the OCX file? This solution is about as close as I'll get to being able to tell if a file is accessible to my program?

    Also, surely someone has written a module or has source code that would do both of these things, or am I left with hoofing it?

  4. #4
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: Detecting OCX Files

    The OCX's i work with, and some codecs, are always in the same place in the registry ... it will differ from one to the next .. as they come out with a newer version it may change ... though ones im working with for remote video have been the same across 10+ version releases ...

    So what i do, cause i include them in my program as well, i check the location, then i check the registry ... if they arent there i copy them to the location, then register them, in my case (and most all), System32.

    So simply you need Registry Query Functions to see if its registered, then if not shell to the RegSvr command ... also have to first make sure the OCX exists in the System32 folder.
    Last edited by rory; Aug 22nd, 2006 at 06:55 PM.

  5. #5
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: Detecting OCX Files

    here i threw this together for yah ...

    You will need to Copy MSFLXGRD.OCX to your App/Project folder to test
    as i didnt include it in the zip file.
    Last edited by rory; Aug 23rd, 2006 at 09:32 AM.

  6. #6

    Thread Starter
    Hyperactive Member Fedhax's Avatar
    Join Date
    Aug 2006
    Posts
    293

    Resolved Re: Detecting OCX Files

    It resolves that issue. Getting these files registered and finding their CLSID values can be rather bothersome, but once they are registered, everything in you sent seems to work like a charm. There is some kind of bugginess--not in your code --if you register the file in one directory and move it to another directory and try again. That arrangement will cause it to fail until you unregister the files originally registered and run these program again (Sloppy sentence).

    I'm marking this issue as resolved. Thanks for your help.

  7. #7
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: [RESOLVED] Detecting OCX Files

    Yes once you register the OCX in a particular folder, if you move it, it wont work. However when you reregister it, other programs that use it should automatically use that new folder location, as that info is what is in the registry.

    You really want to keep the default location though.

  8. #8
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: [RESOLVED] Detecting OCX Files

    to register it no matter whether there is a path value in the registry or not ...

    VB Code:
    1. '// CHECK OCX AND REGISTER IF NOT
    2. Public Function Register(ByVal CLSID As String, _
    3.     ByVal FILEX As String) As Boolean
    4.     Dim RegVer As String
    5.     Dim RegOcx As String
    6.     Dim TmpOcx As String
    7. On Error GoTo Error_Handler:
    8.     'CHECK CLSID & FILE VALUES
    9.     If Right(LCase(FILEX), 4) = ".ocx" And LenB(CLSID) > 0 Then
    10.         RegOcx = SystemDirectory & "\" & FILEX
    11.         TmpOcx = App.Path & "\" & FILEX
    12.         'IF NOT IN SYSTEM DIRECTORY COPY
    13.         If LenB(Dir$(RegOcx)) = 0 Then
    14.             'IF TMP OCX EXISTS
    15.             If LenB(Dir$(TmpOcx)) > 0 Then
    16.                 FileCopy TmpOcx, RegOcx
    17.             Else
    18.             'CANT COPY SO EXIT
    19.                 Exit Function
    20.             End If
    21.         End If
    22.         'IF IN SYSTEM DIRECTORY NOW
    23.         If LenB(Dir$(RegOcx)) > 0 Then
    24.             Shell "regsvr32 -s " & RegOcx
    25.         Else
    26.         'CANT REG SO EXIT
    27.             Exit Function
    28.         End If
    29.         'CHECK THAT IT IS REGISTERED
    30.         RegVer = Query_Value(HKEY_CLASSES_ROOT, "CLSID\{" & CLSID & "}\InprocServer32", "")
    31.         If InStr(1, RegVer, RegOcx, 3) And LenB(Dir$(RegOcx)) > 0 Then
    32.             Register = True
    33.         End If
    34.     End If
    35.     Exit Function
    36. Error_Handler:
    37.     Register = False
    38. End Function

  9. #9
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: [RESOLVED] Detecting OCX Files

    and if you dont even need to see if it is in the registry first ..
    just check the system directory, if not there copy the ocx,
    then register it with regsvr.

    VB Code:
    1. '// TEST BUTTON
    2. Private Sub Command1_Click()
    3.     If Register("Msflxgrd.ocx") Then
    4.         Debug.Print "Registered Successfully"
    5.     Else
    6.         Debug.Print "Error Registering"
    7.     End If
    8. End Sub
    9.  
    10. '// REGISTER OCX FILE
    11. Public Function Register(ByVal FILEX As String) As Boolean
    12.     Dim RegOcx As String
    13.     Dim TmpOcx As String
    14. On Error GoTo Error_Handler:
    15.     'CHECK CLSID & FILE VALUES
    16.     If Right(LCase(FILEX), 4) = ".ocx" Then
    17.         RegOcx = SystemDirectory & "\" & FILEX
    18.         TmpOcx = App.Path & "\" & FILEX
    19.         'IF NOT IN SYSTEM DIRECTORY COPY
    20.         If LenB(Dir$(RegOcx)) = 0 Then
    21.             'IF TMP OCX EXISTS
    22.             If LenB(Dir$(TmpOcx)) > 0 Then
    23.                 FileCopy TmpOcx, RegOcx
    24.             Else
    25.             'CANT COPY SO EXIT
    26.                 Exit Function
    27.             End If
    28.         End If
    29.         'IF IN SYSTEM DIRECTORY NOW
    30.         If LenB(Dir$(RegOcx)) > 0 Then
    31.             Shell "regsvr32 -s " & RegOcx
    32.         Else
    33.         'CANT REG SO EXIT
    34.             Exit Function
    35.         End If
    36.         Register = True
    37.     End If
    38.     Exit Function
    39. Error_Handler:
    40.     Register = False
    41. End Function
    42.  
    43. '// GET WINDOWS SYSTEM DIRECTORY
    44. Private Function SystemDirectory()
    45.     Dim objFso As Object
    46.     Set objFso = CreateObject("scripting.filesystemobject")
    47.     SystemDirectory = objFso.GetSpecialFolder(1)
    48. End Function

  10. #10

    Thread Starter
    Hyperactive Member Fedhax's Avatar
    Join Date
    Aug 2006
    Posts
    293
    Quote Originally Posted by rory
    Yes once you register the OCX in a particular folder, if you move it, it wont work. However when you reregister it, other programs that use it should automatically use that new folder location, as that info is what is in the registry.

    You really want to keep the default location though.
    You raise an interesting question, and I figured that I'd throw it out there.

    I want to keep all of my program's DLLs within the application's folder ( e.g. App.Path & "\DLLs" ) to ensure that everything is kept in a tidy location and should be simple to uninstall/remove. I know that programmers through the annuals of history have debated between Shared Libraries and Isolated Libraries where everything is self-contained. Where does that debate currently stand? I can't imagine the save space/save memory issue is a problem with 50+ GB HDs and default RAM builds going 512+ MB, but I could be wrong/out of touch here.

  11. #11
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: [RESOLVED] Detecting OCX Files

    Are they your own Custom Made DLLs or others?

    If they are your own then sure ... GeoVision's (popular PC DVR Card) software keeps all their own DLLs in their folder ... they keep the setting's Ini files in the windows directory .. so the settings arent uninstalled unless manually deleted or windows reloaded ..

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