Solved

How to check if OCX registered and if not regsiter it

Posted on 2006-06-15
2
1,459 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 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
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…

696 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