Results 1 to 12 of 12

Thread: How to register a 64bit DLL on a 64bit windows with my vb app?

  1. #1

    Thread Starter
    Fanatic Member Mith's Avatar
    Join Date
    Jul 2017
    Location
    Thailand
    Posts
    540

    Question How to register a 64bit DLL on a 64bit windows with my vb app?

    I use the LoadLibrary API to register 32bit-DLL but it doenst work with 64bit DLLs.
    I get the error code 193 if i try to register a 64bit DLL.

    Does anyone know how to register a 64bit DLL on a 64bit windows with my vb app?

    I cant do this with the app installer, because the installer runs as admin and the DLL is only registered for the admin account. So i need a solution to register the DLL for a non-admin account too.

  2. #2
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    7,653

    Re: How to register a 64bit DLL on a 64bit windows with my vb app?

    You would need to use the regsvr32 in System32; turn off automatic redirection to SysWOW64 with Wow64DisableWow64FsRedirection.

  3. #3

    Thread Starter
    Fanatic Member Mith's Avatar
    Join Date
    Jul 2017
    Location
    Thailand
    Posts
    540

    Re: How to register a 64bit DLL on a 64bit windows with my vb app?

    like this for example?

    Code:
    Call Wow64DisableWow64FsRedirection(0)
    shell("regsvr32 test.dll")
    Call Wow64RevertWow64FsRedirection(0)

  4. #4
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,958

    Re: How to register a 64bit DLL on a 64bit windows with my vb app?

    https://support.microsoft.com/en-gb/...a-3f4e0cb543e5 might be useful. also if the dll is one of your own you might be better off keeping it with your application and not putting it in a System folder.

  5. #5
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    7,653

    Re: How to register a 64bit DLL on a 64bit windows with my vb app?

    Quote Originally Posted by Mith View Post
    like this for example?

    Code:
    Call Wow64DisableWow64FsRedirection(0)
    shell("regsvr32 test.dll")
    Call Wow64RevertWow64FsRedirection(0)
    Probably still have to actually specify the one in System32.

  6. #6

    Thread Starter
    Fanatic Member Mith's Avatar
    Join Date
    Jul 2017
    Location
    Thailand
    Posts
    540

    Re: How to register a 64bit DLL on a 64bit windows with my vb app?

    I use the full paths of the regsvr32.exe and the DLL. Works very well on a x64 system!

  7. #7
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,909

    Re: How to register a 64bit DLL on a 64bit windows with my vb app?

    It's my understanding he's looking to register a 64bit DLL (and, of course, on 64bit Windows).

    We certainly can't call 64bit API calls from VB6. We can call 64bit APIs from Office (LongPtr, etc.), but not from VB6.

    Therefore, I'd think it's highly unlikely this can be done with any API from VB6.

    However, if a shell command can be worked out, it can probably be done that way. I've got no experience registering 64bit DLLs, so I don't even know if there's a RegSvr64.exe. Actually, I just looked, and there doesn't appear to be. So I've got no idea how to register these things.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  8. #8
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,538

    Re: How to register a 64bit DLL on a 64bit windows with my vb app?

    These two codes are used to register DLLs, supporting 64 bit and 32-bit, and are registered in administrator mode

    regsvr for 64 bit com dll:
    Code:
    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
        ByVal hWnd As Long, _
        ByVal lpOperation As String, _
        ByVal lpFile As String, _
        ByVal lpParameters As String, _
        ByVal lpDirectory As String, _
        ByVal nShowCmd As Long) As Long
    
    Const SW_SHOWNORMAL = 1
    
    Sub Main()
      ShellExecute 0, "runas", "C:\Windows\SYSTEM32\regsvr32.exe", DLL, vbNullString, SW_SHOWNORMAL
    End Sub
    x86 ,32 bit com dll regsvr

    Code:
    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
        ByVal hWnd As Long, _
        ByVal lpOperation As String, _
        ByVal lpFile As String, _
        ByVal lpParameters As String, _
        ByVal lpDirectory As String, _
        ByVal nShowCmd As Long) As Long
    
    Const SW_SHOWNORMAL = 1
    
    Sub Main()
      ShellExecute 0, "runas", "C:\Windows\SysWOW64\regsvr32.exe", Command, vbNullString, SW_SHOWNORMAL
    End Sub
    Last edited by xiaoyao; Apr 7th, 2023 at 10:31 PM.

  9. #9
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    7,653

    Re: How to register a 64bit DLL on a 64bit windows with my vb app?

    Quote Originally Posted by Elroy View Post
    It's my understanding he's looking to register a 64bit DLL (and, of course, on 64bit Windows).

    We certainly can't call 64bit API calls from VB6. We can call 64bit APIs from Office (LongPtr, etc.), but not from VB6.

    Therefore, I'd think it's highly unlikely this can be done with any API from VB6.

    However, if a shell command can be worked out, it can probably be done that way. I've got no experience registering 64bit DLLs, so I don't even know if there's a RegSvr64.exe. Actually, I just looked, and there doesn't appear to be. So I've got no idea how to register these things.
    It's still called regsvr32, but the one in System32 is 64bit and registers 64bit DLLs. The only issue is 32bit apps have all their calls to files in System32 redirected to SysWOW64, unless you disable that redirection with the api I mentioned. (An alternative is to use the 'SysNative' folder alias, but registration is finicky at the best of times so though a little simpler I didn't think it a good idea here).

  10. #10
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,909

    Re: How to register a 64bit DLL on a 64bit windows with my vb app?

    Quote Originally Posted by fafalone View Post
    It's still called regsvr32, but the one in System32 is 64bit and registers 64bit DLLs. The only issue is 32bit apps have all their calls to files in System32 redirected to SysWOW64, unless you disable that redirection with the api I mentioned. (An alternative is to use the 'SysNative' folder alias, but registration is finicky at the best of times so though a little simpler I didn't think it a good idea here).
    Yeah, I actually studied it a bit. That seems quite stupid to me to continue calling it regsvr32.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  11. #11
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,538

    Re: How to register a 64bit DLL on a 64bit windows with my vb app?

    Code:
    Function RegsvrComDll(DllFile As String, Optional For32BitDll As Boolean = True)
        Dim Path1 As String
        Path1 = "system32"
        If Is64bit And For32BitDll Then Path1 = "SysWOW64"
        ShellExecute 0, "runas", "C:\Windows\" & Path1 & "\regsvr32.exe", DllFile, vbNullString, SW_SHOWNORMAL
    End Function
    
    Function RegComDll(DllFile As String, Optional For32Bit As Boolean = True)
        ShellExecute 0, "runas", "C:\Windows\" & IIf(Is64bit And For32Bit, "SysWOW64", "system32") & "\regsvr32.exe", DllFile, vbNullString, SW_SHOWNORMAL
    End Function


    Code:
    Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As Long
    Private Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Long
    Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
    Private Declare Function IsWow64Process Lib "kernel32" (ByVal hProc As Long, bWow64Process As Boolean) As Long
    
    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
        ByVal hWnd As Long, _
        ByVal lpOperation As String, _
        ByVal lpFile As String, _
        ByVal lpParameters As String, _
        ByVal lpDirectory As String, _
        ByVal nShowCmd As Long) As Long
    
    Const SW_SHOWNORMAL = 1
    
    
    Public Function Is64bit() As Boolean
        Dim handle As Long, bolFunc As Boolean
        bolFunc = False
        handle = GetProcAddress(GetModuleHandle("kernel32"), "IsWow64Process")
        If handle > 0 Then
        IsWow64Process GetCurrentProcess(), bolFunc
        End If
        Is64bit = bolFunc
    End Function

  12. #12
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,538

    Re: How to register a 64bit DLL on a 64bit windows with my vb app?

    Try to use the solution of loading COM DLLs without registration as much as possible, which eliminates the need for administrator privileges and registry writing. It's like loading a regular standard DLL or an image directly.

    Code:
    RegComDll App.Path & "\32_MFCActiveXControl1.ocx"
    
    'reg x64 com dll
    RegComDll App.Path & "\64_MFCActiveXControl1.ocx", False
    
    'DllUnregisterServer
    RegComDll App.Path & "\32_MFCActiveXControl1.ocx", , True
    Code:
    Function RegComDll(DllFile As String, Optional For32Bit As Boolean = True, Optional UnRegComDLL As Boolean)
        ShellExecute 0, "runas", "C:\Windows\" & IIf(Is64bit And For32Bit, "SysWOW64", "system32") & "\regsvr32.exe", Chr(34) & DllFile & Chr(34) & IIf(UnRegComDLL, " /U", ""), vbNullString, SW_SHOWNORMAL
    End Function
    
    
    Function RegsvrComDll(DllFile As String, Optional For32BitDll As Boolean = True, Optional UnRegComDLL As Boolean)
        Dim Path1 As String
        Path1 = "system32"
        If Is64bit And For32BitDll Then Path1 = "SysWOW64"
        ShellExecute 0, "runas", "C:\Windows\" & Path1 & "\regsvr32.exe", Chr(34) & DllFile & Chr(34) & IIf(UnRegComDLL, " /U", ""), vbNullString, SW_SHOWNORMAL
    End Function
    Last edited by xiaoyao; Apr 7th, 2023 at 11:08 PM.

Tags for this Thread

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