?
Solved

How to check if OCX registered and if not regsiter it

Posted on 2006-06-15
2
Medium Priority
?
1,463 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 13

Expert Comment

by:Mark_FreeSoftware
ID: 16911586
0
 
LVL 29

Accepted Solution

by:
nffvrxqgrcfqvvc earned 2000 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

801 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