Solved

How to check if OCX registered and if not regsiter it

Posted on 2006-06-15
2
1,454 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
Comment Utility
0
 
LVL 29

Accepted Solution

by:
nffvrxqgrcfqvvc earned 500 total points
Comment Utility
'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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

772 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

12 Experts available now in Live!

Get 1:1 Help Now