Results 1 to 3 of 3

Thread: Registering an ActiveX component with an API call?

  1. #1

    Thread Starter
    Fanatic Member simonm's Avatar
    Join Date
    Sep 2000
    Location
    Devon, England
    Posts
    796

    Registering an ActiveX component with an API call?

    Is it possible? Of couse I can always shell the regsvr32.exe command to register a DLL or OCX but the problem is that I have no way of knowing whether it suceeded or not.

    Perhaps an API call would return a success flag?
    Everything I say is either loose interpretation of dubious facts or idle speculation rooted in irrational sentiment.

  2. #2
    Fanatic Member namrekka's Avatar
    Join Date
    Feb 2005
    Location
    Netherlands
    Posts
    639

    Re: Registering an ActiveX component with an API call?


  3. #3
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    UK
    Posts
    417

    Re: Registering an ActiveX component with an API call?

    Try this I always use this and works ok

    VB Code:
    1. Option Explicit
    2.  
    3. 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
    4. Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As Long
    5. Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
    6. Private Declare Function GetExitCodeThread Lib "kernel32" (ByVal hThread As Long, lpExitCode As Long) As Long
    7. Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
    8. Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
    9. Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
    10. Private Declare Sub ExitThread Lib "kernel32" (ByVal dwExitCode As Long)
    11.  
    12. Enum RegOp
    13.     Register = 1
    14.     UnRegister
    15. End Enum
    16.  
    17. Public Function RegisterActiveX(lzAxDll As String, mRegOption As RegOp) As Boolean
    18. Dim mLib As Long, DllProcAddress As Long
    19. Dim mThread
    20. Dim sWait As Long
    21. Dim mExitCode As Long
    22. Dim lpThreadID As Long
    23.  
    24.     mLib = LoadLibrary(lzAxDll)
    25.    
    26.     If mLib = 0 Then RegisterActiveX = False: Exit Function
    27.    
    28.     If mRegOption = Register Then
    29.         DllProcAddress = GetProcAddress(mLib, "DllRegisterServer")
    30.     Else
    31.         DllProcAddress = GetProcAddress(mLib, "DllUnregisterServer")
    32.     End If
    33.    
    34.     If DllProcAddress = 0 Then
    35.         RegisterActiveX = False
    36.         Exit Function
    37.     Else
    38.         mThread = CreateThread(ByVal 0, 0, ByVal DllProcAddress, ByVal 0, 0, lpThreadID)
    39.        
    40.         If mThread = 0 Then
    41.             FreeLibrary mLib
    42.             RegisterActiveX = False
    43.             Exit Function
    44.         Else
    45.             sWait = WaitForSingleObject(mThread, 10000)
    46.             If sWait <> 0 Then
    47.                 FreeLibrary mLib
    48.                 mExitCode = GetExitCodeThread(mThread, mExitCode)
    49.                 ExitThread mExitCode
    50.                 Exit Function
    51.             Else
    52.                 FreeLibrary mLib
    53.                 CloseHandle mThread
    54.             End If
    55.         End If
    56.     End If
    57.    
    58.     RegisterActiveX = True
    59.    
    60. End Function

    Use RegisterActiveX("C:\somefile.dll",Register)
    Returns true on if ActiveX was registered otherwise false
    When your dreams come true.
    On error resume pulling hair out.

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