Solved

How to check if OCX registered and if not regsiter it

Posted on 2006-06-15
2
1,455 Views
Last Modified: 2008-01-09
Hi,

I have several very simple utils that i have written in VB6 that require mscomct2.ocx to be registered.

I don't want to create an installer for this I just want it to work on the fly.  I need the EXE to check if the OCX was already registered and if not silently register it before continuing to load the form.

The OCX sits next to the exe on the shared drive on our network.  

Can anyone provide me with some sample code how to do this?

Cheers

Chris
0
Comment
Question by:Sailo100
2 Comments
 
LVL 13

Expert Comment

by:Mark_FreeSoftware
ID: 16911586
0
 
LVL 29

Accepted Solution

by:
nffvrxqgrcfqvvc earned 500 total points
ID: 16917214
'Another approach


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
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now