Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Registering a DLL or OCX from VB
Message
From
07/06/2001 22:24:00
 
 
To
06/06/2001 16:44:32
General information
Forum:
Visual Basic
Category:
Other
Miscellaneous
Thread ID:
00516044
Message ID:
00516741
Views:
6677
This message has been marked as a message which has helped to the initial question of the thread.
>Can anyone tell me what is wrong with this? Or is there a better way?
>
>Private Sub Command2_Click()
> Dim ret As Long
> Dim myfile, myexe, fullpath As String
> myexe = "regsvr32.exe /s "
> myfile = """" & App.Path & "\ScrRun.Dll" & """"
> fullpath = myexe & myfile
> ret = ShellExecute(App.hInstance, "Open", fullpath, "", "", 1)
> MsgBox ret
>End Sub
>
>My ret value is a '2' which, I think, means 'ERROR_PATH_NOT_FOUND', but when I cut and paste my "fullpath" value into the Start->Run it works fine and registers my dll.
>
>Help please.
>Thanking you in advance for your help.
>~brad

Brad I have an entire application whose job it is to this type of thing. Here she is. I hope it helps you. Add this to a module and take advantage of the wrappers I have made for doing an entire directory or a single file. Unfortunately I see ScrRun.dll in my badFiles list. These are files that will gpf if reg'd using this method...
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
Global intRegistered As Integer
Global intClickCount As Integer
Global strclipstuff As String
Global JHRegServer As Boolean
Global RegServer As Boolean


Private 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)
   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


Private Sub RegisterDir(Optional strPath As String, Optional bolDontClear As Boolean)
Dim strControlFilename, menum, strExt As String

If strPath = "" Then strPath = App.Path ' Handle no path passed
If Right(strPath, 1) <> "\" Then strPath = strPath & "\" ' Handle trailing backslash.

strControlFilename = Dir(strPath & "*.*", vbNormal)   ' Retrieve the first entry.



Do While strControlFilename <> ""   ' Start the loop.
    frmMsg.Refresh ' Update our message
    intClickCount = intClickCount + 1
    DoEvents
    ' Ignore NON ActiveX controls
    strExt = UCase(Right(strControlFilename, 4))
    If (strExt = ".DLL" Or strExt = ".OCX" Or strExt = ".EXE") And BadFile(strControlFilename) = False Then
    
         UnReg (Trim$(strPath & strControlFilename)) ' Unregister first
         Reg (Trim$(strPath & strControlFilename))
    Else
        If RegServer Then
            Shell ("C:\WINDOWS\SYSTEM\REGSVR32.EXE " & strPath & strControlFilename & " /U /S")
            Shell ("C:\WINDOWS\SYSTEM\REGSVR32.EXE " & strPath & strControlFilename & " /s")
        ElseIf JHRegServer Then
            Shell ("c:\jhsystem\exe\JHRegSvr.exe /S" & strPath)
            intClickCount = intClickCount - 1
        End If
    End If
    strControlFilename = Dir    ' Get next entry.
    DoEvents
Loop

'Me.Caption = Str(lstResults.ListCount * 3) & " Clicks Saved!" & "  *** FINISHED ***"
End Sub

Private Function BadFile(strFilename) As Boolean
    BadFile = False
    'This dll causes a BIG error
    If UCase(strFilename) = "STI.DLL" Or _
       UCase(strFilename) = "NV3DD32.DLL" Or _
       UCase(strFilename) = "SHDOC401.DLL" Or _
       UCase(strFilename) = "C:\WINDOWS\SYSTEM\OC30.DLL" Or _
       UCase(strFilename) = "C:\WINDOWS\SYSTEM\DUZOCX32.OCX" Or _
       UCase(strFilename) = "C:\WINDOWS\SYSTEM\DZSTAT32.OCX" Or _
       UCase(strFilename) = "C:\WINDOWS\SYSTEM\DZOCX32.OCX" Or _
       UCase(strFilename) = "SCRRUN.DLL" Or _
       UCase(strFilename) = "ODBCCU32.DLL" Or _
       UCase(strFilename) = "PRINTFED.EXE" Or _
       Left(UCase(strFilename), 4) = "ODBC" Or _
       Left(UCase(strFilename), 3) = "MFC" Then
       BadFile = True
    End If
End Function

Public Function Reg(strFile As String)
Dim menum As STATUS
On Error Resume Next ' added for expedience
    frmMsg.Refresh
    DoEvents
         strclipstuff = strclipstuff + strFile & Chr(13)
         Clipboard.Clear ' Establish a nice purdy clipboard
         Clipboard.SetText strclipstuff
            Debug.Print strFile
        frmMsg.Caption = "Registering " & strFile
    If Not BadFile(strFile) Then
        UnReg (strFile) ' Unregit first
        menum = RegisterComponent(Trim$(strFile), DllRegisterServer)
            If RegServer And menum <> 5 Then ' If for some reason the reg failed try it the other way
                Shell ("C:\WINDOWS\SYSTEM\REGSVR32.EXE " & strFile & " /U /S")
                Shell ("C:\WINDOWS\SYSTEM\REGSVR32.EXE " & strFile & " /s")
                intClickCount = intClickCount + 1 ' No click needed
            End If
    Else
        If RegServer Then ' avoid errors
            Shell ("C:\WINDOWS\SYSTEM\REGSVR32.EXE " & strFile & " /U /S")
            Shell ("C:\WINDOWS\SYSTEM\REGSVR32.EXE " & strFile & " /s")
        ElseIf JHRegServer Then
            Shell ("c:\jhsystem\exe\JHRegSvr.exe /S" & strFile)
            intClickCount = intClickCount - 1 ' jhregsvr needs a click no matter what
        End If
    End If
                
    Select Case menum
            Case [File Could Not Be Loaded Into Memory Space]
               Debug.Print strFile & " [File Could Not Be Loaded Into Memory Space]"
                intClickCount = intClickCount - 3
            Case [Not A Valid ActiveX Component]
               Debug.Print strFile & " [Not A Valid ActiveX Component] "
                intClickCount = intClickCount - 3
            Case [ActiveX Component Registration Failed]
               Debug.Print strFile & " [ActiveX Component Registration Failed]"
                intClickCount = intClickCount - 2
            Case [ActiveX Component Registered Successfully]
               'Debug.Print strFile & " [ActiveX Component Registered Successfully]"
                intRegistered = intRegistered + 1
    End Select
End Function
        
Private Function UnReg(strFile As String)
Dim menum As STATUS
'intClickCount = intClickCount + 1

menum = RegisterComponent(Trim$(strFile), DllUnRegisterServer)
    Select Case menum
        Case [File Could Not Be Loaded Into Memory Space]
           Debug.Print strFile & " [File Could Not Be Loaded Into Memory Space]"
        Case [Not A Valid ActiveX Component]
           Debug.Print strFile & " [Not A Valid ActiveX Component] "
        Case [ActiveX Component Registration Failed]
           Debug.Print strFile & " ActiveX Component UnRegistration Failed]"
        Case [ActiveX Component UnRegistered Successfully]
           'Debug.Print strFile & " [ActiveX Component UnRegistered Successfully]"
    End Select
End Function
~Joe Johnston USA

"If ye love wealth better than liberty, the tranquility of servitude better than the animated contest of freedom, go home from us in peace. We ask not your counsel or arms. Crouch down and lick the hands which feed you. May your chains set lightly upon you, and may posterity forget that ye were our countrymen."
~Samuel Adams

Previous
Reply
Map
View

Click here to load this message in the networking platform