[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How to check if OCX registered and if not regsiter it

Posted on 2006-06-15
2
Medium Priority
?
1,465 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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 Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

650 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