• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 304
  • Last Modified:

Registering an ActiveX Dll in VB..

I want write a code to register an ActiveX Dll file, I know I can use shellexecute to run the regsvr32.exe and register the file, but is there any other methods or API to do this?
0
LCP
Asked:
LCP
1 Solution
 
watyCommented:
' #VBIDEUtils#************************************************************
' * Programmer Name  : Pranay Uppuluri
' * Web Site         : www.geocities.com/ResearchTriangle/6311/
' * E-Mail           : PRUppL@aol.com
' * Date             : 23/04/99
' * Time             : 14:40
' **********************************************************************
' * Comments         : Register Active X and DLL by code
' *
' *
' **********************************************************************

Option Explicit

'********************************************************************************************
' MODULE  : modMain.BAS
'
' Original function written by Brad Martinez, edited by Pranay Uppuluri.
' Pranay Uppuluri: PRUppL@aol.com
'                  www.geocities.com/ResearchTriangle/6311/
'
' You can freely distribute this example provided you agree
' with this following 2 lines:
'       NO WARRANTY EXPRESS OR IMPLIED PROVIDED WITH THIS EXAMPLE.
'       USE IT AT YOUR OWN RISK!
' Special thanks to: Brad Martinez
'********************************************************************************************

Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" _
   (ByVal lpLibFileName As String) As Long
Private Declare Function FreeLibrary Lib "kernel32" _
   (ByVal hLibModule As Long) As Long
Private Declare Function GetProcAddress Lib "kernel32" _
   (ByVal hModule As Long, _
   ByVal lpProcName As String) As Long
Private Declare Function CreateThread Lib "kernel32" _
   (lpThreadAttributes As Any, _
   ByVal dwStackSize As Long, _
   lpStartAddress As Long, _
   lpParameter As Any, _
   ByVal dwCreationFlags As Long, _
   lpThreadID As Long) As Long
'                            (lpThreadAttributes As SECURITY_ATTRIBUTES, _


' dwCreationFlags param, call ResumeThread to
' wake the thread up, specify 0 for an alive thread
Private Const CREATE_SUSPENDED = &H4

Private Declare Function WaitForSingleObject Lib "kernel32" _
   (ByVal hHandle As Long, _
   ByVal dwMilliseconds As Long) As Long
' dwMilliseconds param, specify 0 for immediate return.
Private Const INFINITE = &HFFFFFFFF   ' Infinite timeout
' WaitForSingleObject rtn vals
Private Const STATUS_WAIT_0 = &H0
Private Const STATUS_ABANDONED_WAIT_0 = &H80
Private Const STATUS_TIMEOUT = &H102

Private Const WAIT_FAILED = &HFFFFFFFF
' The state of the specified object is signaled (success)
Private Const WAIT_OBJECT_0 = ((STATUS_WAIT_0) + 0)

' Thread went away before the mutex got signaled
Private Const WAIT_ABANDONED = ((STATUS_ABANDONED_WAIT_0) + 0)

' dwMilliseconds timed out
Private Const WAIT_TIMEOUT = STATUS_TIMEOUT

Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Sub ExitThread Lib "kernel32" (ByVal dwExitCode As Long)
Private Declare Function ResumeThread Lib "kernel32" (ByVal hThread As Long) As Long
Private Declare Function GetExitCodeThread Lib "kernel32" _
   (ByVal hThread As Long, _
   lpExitCode As Long) As Long
Private Const STATUS_PENDING = &H103
Private Const STILL_ACTIVE = STATUS_PENDING

'********************************************************************************************
' Example:
'         Dim retVal As Boolean
'             retVal = VBRegServer32("comctl32.ocx", False)
'
' Registers or unregisters the specified COM server.
'   sServerPath  - server's path, either explicit, or relative if the system can find it
'   fRegister    - optional flag indicating what operation to perform:
'                  True (defualt) registers the server, False unregisters it.
'
' Returns True on success, False otherwise.
'********************************************************************************************
Public Function VBRegServer32(ByVal sServerPath As String, Optional fRegister = True) As Boolean
   Dim hMod As Long            ' module handle
   Dim lpfn As Long            ' reg/unreg function address
   Dim lpThreadID As Long      ' dummy var that get's filled
   Dim hThread As Long         ' thread handle
   Dim fSuccess As Boolean     ' if things worked
   Dim dwExitCode As Long      ' thread's exit code if it doesn't finish
   
   ' Load the server into memeory
   hMod = LoadLibrary(sServerPath)
   
   ' Get the specified function's address and our msgbox string.
   If fRegister Then
      lpfn = GetProcAddress(hMod, "DllRegisterServer")
   Else
      lpfn = GetProcAddress(hMod, "DllUnregisterServer")
   End If
   
   ' If we got a function address...
   If lpfn Then
      ' Create an alive thread and execute the function.
      hThread = CreateThread(ByVal 0, 0, ByVal lpfn, ByVal 0, 0, lpThreadID)
     
      ' If we got the thread handle...
      If hThread Then
         ' Wait 10 secs for the thread to finish (the function may take a while...)
         fSuccess = (WaitForSingleObject(hThread, 10000) = WAIT_OBJECT_0)
         
         ' If it didn't finish in 5 seconds...
         If Not fSuccess Then
            ' Something unlikely happened, lose the thread.
            Call GetExitCodeThread(hThread, dwExitCode)
            Call ExitThread(dwExitCode)
         End If
         
         ' Lose the thread handle
         Call CloseHandle(hThread)
      End If   ' hThread
   End If   ' lpfn
   
   ' Free server if we loaded it.
   If hMod Then Call FreeLibrary(hMod)
   
   If fSuccess Then
      VBRegServer32 = True
   Else
      VBRegServer32 = False
   End If
End Function
0
 
LCPAuthor Commented:
Thank you very much! It work fine for me! :>
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now