Results 1 to 4 of 4

Thread: Register OCX at runtime??

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2000
    Posts
    20
    Hi!!
    Can I register or un-register a OCX control at runtime?
    I mean for example if I use an especific OCX control how can i register ir while I have got a splash screen ? Can I do that? and can I un-register the OCX while the program is finishing with an splash screen too?
    I need an example please and THANKS!!

  2. #2
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    regsvr32 /u C:\Path\Filename.ocx
    un-registers a dll or ocx file.

    regsvr32 C:\Path\Filename.ocx
    registers the file.

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  3. #3
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    you can do this at any time. There is also a silent option to do this behind the scenes, but you don't get the warning message if the register / un-register fails.

    This is :
    regsvr32 /u /s C:\Path\Filename.ocx

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  4. #4
    Guest
    Here's an alternative that doesn't require regsvr32 to be on the machine and in the system path.

    I didn't write it, although I have made some mods. Who wroteit, well, that has been lost in the mists of time. My apologies to those concerned.

    Code:
    Public Enum RegUnreg
        Register = 0
        UnRegister = 1
    End Enum
    
    Public Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" _
            (ByVal lpLibFileName As String) As Long
    Public Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, _
            ByVal lpProcName As String) As Long
    Public Declare Function CreateThread Lib "kernel32" (lpThreadAttributes As Any, _
            ByVal dwStackSize As Long, ByVal lpStartAddress As Long, ByVal lParameter As Long, _
            ByVal dwCreationFlags As Long, lpThreadID As Long) As Long
    Public Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, _
            ByVal dwMilliseconds As Long) As Long
    Public Declare Function GetExitCodeThread Lib "kernel32" (ByVal hThread As Long, _
            lpExitCode As Long) As Long
    Public Declare Sub ExitThread Lib "kernel32" (ByVal dwExitCode As Long)
    Public Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
    Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
    
    
    
    'The actual codey bit.
    
    Public Function RegisterDLLOROCX(File As String, _
                                     Optional Process As RegUnreg = Register, _
                                     Optional PromptOnError As Boolean = False) As Boolean
    
        Dim LoadedLib As Long
        Dim EntryPoint As Long
        Dim ExitCode As Long
        Dim newThread As Long
        Dim newThreadID As Long
        
        On Error Resume Next
    
        '// Check file exists
        If Dir(File, vbNormal) = "" Then
            If PromptOnError Then MsgBox "The file " & File & " doesn't exist", vbCritical, "DLL/OCX Register"
            RegisterDLLOROCX = False
            Exit Function
        End If
    
        LoadedLib = LoadLibrary(File)                          '// Load file
    
        If LoadedLib = 0 Then
            If PromptOnError Then MsgBox "An error occured while loading the file " & File, vbCritical, "DLL/OCX Register"
            RegisterDLLOROCX = False
            Exit Function
        End If
    
        '// Find right entery point
        If Process = Register Then
            EntryPoint = GetProcAddress(LoadedLib, "DllRegisterServer")
        ElseIf Process = UnRegister Then
            EntryPoint = GetProcAddress(LoadedLib, "DllUnregisterServer")
        Else
            If PromptOnError Then MsgBox "An error occured while loading the file " & File, vbCritical, "DLL/OCX Register"
            RegisterDLLOROCX = False
            Exit Function
        End If
    
    
        If EntryPoint = vbNull Then
            If PromptOnError Then MsgBox "An error occured while locating the entery point for the file : " & vbNewLine & File, vbCritical, "DLL/OCX Register"
            FreeLibrary (LoadedLib)                            '// Unload libarary
            RegisterDLLOROCX = False
            Exit Function
        End If
    
        Screen.Mousepointer = vbHourglass
    
        newThread = CreateThread(ByVal 0, 0, ByVal EntryPoint, ByVal 0, 0, newThreadID)    '// Create a new thread.
    
        If newThread = 0 Then
            Screen.Mousepointer = vbDefault
            If PromptOnError Then
                MsgBox "An error occured while attempting to create a new thread.", vbCritical, "DLL/OCX Register"
            End If
            FreeLibrary (LoadedLib)                            '// Unload libarary
            Exit Function
        End If
    
        If WaitForSingleObject(newThread, 10000) <> 0 Then
            Screen.Mousepointer = vbDefault
            If PromptOnError Then MsgBox "An error occured while attempting to register/unregister the file : " & vbNewLine & File, vbCritical, "DLL/OCX Register"
            ExitCode = GetExitCodeThread(newThread, ExitCode)
            ExitThread (ExitCode)
            FreeLibrary (LoadedLib)
            RegisterDLLOROCX = False
            Exit Function
        End If
    
    
        CloseHandle (newThread)                                '// Close thread
        FreeLibrary (LoadedLib)                                '// Unload libarary
        Screen.Mousepointer = vbDefault                        '// Reset cursor
        RegisterDLLOROCX = True
    
    End Function
    Hope that helps

    - gaffa

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width