Results 1 to 4 of 4

Thread: how do you register and unregister an .ocx

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2000
    Posts
    18
    how do you register and unregister an .ocx?

    I heard that to register it you have to
    shell C:\WINDOWS\SYSTEM\Regsvr32.exe
    or something, but how do you specify the .ocx file you want to register.

    and how do you unregister an .ocx

  2. #2
    Hyperactive Member
    Join Date
    Feb 2000
    Posts
    284
    If you choose the 'Run' option from the start menu and browse to the .ocx file you want to register when you select it, it'w path should then appear in the run text box enclosed in quotes. Move the cursor to the beginning of the path name before the first set of quotes and type
    REGSVR32 and then a space then click ok. You should get a message telling you that registering has succeeded.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2000
    Posts
    18
    sorry I didn't explain that very well, what I actually want is to know how to register and unregister .ocx files in visual basic.

  4. #4
    Lively Member
    Join Date
    Nov 1999
    Posts
    98
    put this in a module:

    Code:
    Option Explicit
    
    'All required Win32 SDK functions to register/unregister any ActiveX component
    Private Declare Function LoadLibraryRegister Lib "kernel32" _
     Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
    Private Declare Function FreeLibraryRegister Lib "kernel32" _
     Alias "FreeLibrary" (ByVal hLibModule As Long) As Long
    Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
    Private Declare Function GetProcAddressRegister Lib "kernel32" Alias "GetProcAddress" _
     (ByVal hModule As Long, ByVal lpProcName As String) As Long
    Private Declare Function CreateThreadForRegister Lib "kernel32" Alias "CreateThread" _
     (lpThreadAttributes As Any, ByVal dwStackSize As Long, _
     ByVal lpStartAddress As Long, ByVal lpparameter As Long, _
     ByVal dwCreationFlags As Long, lpThreadID As Long) As Long
    Private Declare Function WaitForSingleObject Lib "kernel32" _
     (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
    Private Declare Function GetExitCodeThread Lib "kernel32" _
     (ByVal hThread As Long, lpExitCode As Long) As Long
    Private Declare Sub ExitThread Lib "kernel32" (ByVal dwExitCode As Long)
    
    Private Const STATUS_WAIT_0 = &H0
    Private Const WAIT_OBJECT_0 = ((STATUS_WAIT_0) + 0)
    
    Public Enum REGISTER_FUNCTIONS
        DllRegisterServer = 1
        DllUnRegisterServer = 2
    End Enum
    
    Public Enum STATUS
         [File Could Not Be Loaded Into Memory Space] = 1
         [Not A Valid ActiveX Component] = 2
         [ActiveX Component Registration Failed] = 3
         [ActiveX Component Registered Successfully] = 4
         [ActiveX Component UnRegistered Successfully] = 5
    End Enum
    
    Public Function RegisterComponent(ByVal FileName$, ByVal RegFunction As REGISTER_FUNCTIONS) As STATUS
        Dim lngLib&, lngProcAddress&, lpThreadID&, fSuccess&, dwExitCode&, hThread&
    
        If FileName = "" Then Exit Function
    
        lngLib = LoadLibraryRegister(FileName)
        If lngLib = 0 Then
            RegisterComponent = [File Could Not Be Loaded Into Memory Space]    'Couldn't load component
            Exit Function
        End If
    
        Select Case RegFunction
            Case REGISTER_FUNCTIONS.DllRegisterServer
                lngProcAddress = GetProcAddressRegister(lngLib, "DllRegisterServer")
            Case REGISTER_FUNCTIONS.DllUnRegisterServer
                lngProcAddress = GetProcAddressRegister(lngLib, "DllUnregisterServer")
            Case Else
        End Select
    
        If lngProcAddress = 0 Then
            RegisterComponent = [Not A Valid ActiveX Component]               'Not a Valid ActiveX Component
            If lngLib Then Call FreeLibraryRegister(lngLib)
            Exit Function
        Else
            hThread = CreateThreadForRegister(ByVal 0&, 0&, ByVal lngProcAddress, ByVal 0&, 0&, lpThreadID)
        End If
        
        If hThread Then
            fSuccess = (WaitForSingleObject(hThread, 10000) = WAIT_OBJECT_0)
            If Not fSuccess Then
                Call GetExitCodeThread(hThread, dwExitCode)
                Call ExitThread(dwExitCode)
                RegisterComponent = [ActiveX Component Registration Failed]        'Couldn't Register.
                If lngLib Then
                    Call FreeLibraryRegister(lngLib)
                    Exit Function
                Else
                    If RegFunction = DllRegisterServer Then
                        RegisterComponent = [ActiveX Component Registered Successfully]         'Success. OK
                    ElseIf RegFunction = DllUnRegisterServer Then
                        RegisterComponent = [ActiveX Component UnRegistered Successfully]         'Success. OK
                    End If
                End If
                Call CloseHandle(hThread)
                If lngLib Then Call FreeLibraryRegister(lngLib)
            End If
        End If
    End Function
    then use this in your form:

    Code:
    'to REGISTER a file
    RegisterComponent "filename", DllRegisterServer
    
    'to UNREGISTER a file
    RegisterComponent "filename", DllUnRegisterServer
    that should do the trick. i use it and it works fine. but be careful...the CreateThread function can be dangerous. i take no responsibility for anything that might happen to your computer through misuse. all you have to do is cut and paste. as long as you leave it at that and don't go trying to change any code, you should be fine. if you have any questions please e-mail me. i would be glad to help.

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