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 Const DllRegisterServer = 1 Public Const DllUnRegisterServer = 2 Public Function Register(tFile As String) As String If Dir(tFile) = "" Then Register = "File not found" Exit Function End If Register = RegisterComponent(tFile, DllRegisterServer) End Function Public Function DeRegister(tFile As String) As String If Dir(tFile) = "" Then DeRegister = "File not found" Exit Function End If DeRegister = RegisterComponent(tFile, DllUnRegisterServer) End Function Public Function RegisterComponent(ByVal FileName$, ByVal RegFunction As Integer) As String 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 DllRegisterServer lngProcAddress = GetProcAddressRegister(lngLib, "DllRegisterServer") Case 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) 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 = "" 'Success. OK ElseIf RegFunction = DllUnRegisterServer Then RegisterComponent = "" 'Success. OK End If End If Call CloseHandle(hThread) If lngLib Then Call FreeLibraryRegister(lngLib) End If End If End Function