Results 1 to 5 of 5

Thread: [RESOLVED] How to check registered ocx

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2008
    Posts
    17

    Resolved [RESOLVED] How to check registered ocx

    Haii
    I want to check ocx that has already registered.
    pls advice.

    thanks.

  2. #2
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: How to check registered ocx

    Don't know, but, you can try unregistering and registering it:
    Code:
    Shell "regsvr32 ""C:\Path\To\Lib.ocx"" /u /s"
    Shell "regsvr32 ""C:\Path\To\Lib.ocx"" /s"
    Now it's registered for sure (if it exists of course). You can check if it exists before those Shell() calls:
    Code:
    If Dir$("C:\Path\To\Lib.ocx") <> vbNullString Then
      'do your thing...
    End If
    Anyway, i'm sure there's a better way to do it...

  3. #3
    Junior Member
    Join Date
    Dec 2006
    Posts
    29

    Re: How to check registered ocx

    Hi,

    I found following code from from the web. Check if it works for you.


    Code:
    Option Explicit
    
    Private Declare Function SetDllDirectoryA Lib "kernel32" ( _
        ByVal lpPathName As String) As Long
       
    Private Declare Function LoadLibraryA Lib "kernel32" ( _
        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 CallWindowProcA Lib "user32" ( _
        ByVal lpPrevWndFunc As Long, _
        ByVal hWnd As Long, _
        ByVal Msg As Long, _
        ByVal wParam As Long, _
        ByVal lParam As Long) As Long
    
    Private Declare Function FreeLibrary Lib "kernel32" ( _
        ByVal hLibModule As Long) As Long
    
    Private Const Reg       As String = "DllRegisterServer"
    Private Const UnReg     As String = "DllUnregisterServer"
    
    Public Enum Register_Params
        Register = 80000
        unRegister = 80001
    End Enum
    
    Public Function Invokes( _
        ByVal FileName As String, _
        ByVal PathName As String, _
        ByVal Action As Register_Params) As Boolean
       
        Dim hModule As Long
        Dim Address As Long
        '// Add extra path to default search paths for component
        If SetDllDirectoryA(PathName) Then
            '// Get a handle to the module
            hModule = LoadLibraryA(FileName)
            If hModule Then
            '// If the handle is valid, try to get the function address.
            Select Case Action
                Case Register
                Address = GetProcAddress(hModule, Reg)
                Case unRegister
                Address = GetProcAddress(hModule, UnReg)
            End Select
            '// If the address is valid call the function
                If Address Then
                    CallWindowProcA Address, 0&, ByVal 0&, ByVal 0&, ByVal 0&
                    FreeLibrary hModule
                    Invokes = True
                End If
            End If
        End If
    
    End Function
    
    Private Sub Command1_Click()
    
        If Invokes("myolecmp.ocx", "c:\", Register) Then
            MsgBox "Success"
            Else
            MsgBox "Failed"
        End If
    
    End Sub
    Please comment and let others know if it works.

    Cheers
    Last edited by MartinLiss; Oct 24th, 2008 at 05:55 AM.

  4. #4
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: How to check registered ocx

    Do not use the self-registration entrypoints in this way.

    Both of these methods risk trashing the component's registration. Proper registration is seldom done by running regsvr32 (which just calls these entrypoints like the code above is doing). It may be safe for older components like those VB6 creates and those dating to that era (1998) but the process is actually considerably more complex than that today.

    A proper installer may set many other keys and values in the registry. This approach risks wiping those out.

    See the Remarks at SelfReg Table for some of the cautions.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    May 2008
    Posts
    17

    Resolved Re: How to check registered ocx

    it's work, but I just want checking that Ocx has already registered, not register or unregister the ocx. That is possible in vb?

    thks.
    Last edited by Fazar; Oct 26th, 2008 at 10:25 PM.

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