Convert 32 bit to 64 bit

tiredofit

Well-known Member
Joined
Apr 11, 2013
Messages
1,834
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
In this article:

Code:
https://www.py4u.net/discuss/1448003

it states to convert from 32 bit to 64 bit:

Code:
Manually add PtrSafe to all declarations. Manually convert all Longs in the declarations that represent pointers to LongPtrs (in the code shown, that would be only pidl).

Manually update declarations of Long variables in procedures that are passed as these parameters to LongPtr. There's no other way. You may try to look into refactoring tools/addins that may automate the replacements to a degree.

This is the code:

Code:
Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
Declare Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long

So I suppose it should be changed to:

Code:
Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As LONGPTRS, ByVal pszPath As String) As Long
Declare Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long

My question is: why does the "other" Long (at the end of the first line) not need to also change to LongPtr?

In another article:

Code:
https://stackoverflow.com/questions/42557610/how-to-convert-32-bit-vba-code-into-64-bit-vba-code

it states it must change from:

Code:
Private Declare Function GetTimeZoneInformation Lib "kernel32" ( _
           lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long

to this:

Code:
Private Declare PtrSafe Function GetTimeZoneInformation Lib "kernel32" ( _
       lpTimeZoneInformation As TIME_ZONE_INFORMATION) As LongPtr



Furthermore, other than changing APIs (and removing ActiveX objects), what else must one do to make VBA run on both 32 bit and 64 bit Excel?

Thanks
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
First, it's LongPtr not LONGPTRS

Second, as stated, you only change pointers (including window handles), not all Long variables. The SO linked answer is wrong.
 
Upvote 0
First, it's LongPtr not LONGPTRS

Second, as stated, you only change pointers (including window handles), not all Long variables. The SO linked answer is wrong.
Thanks, my typo error re LongPtr.
 
Upvote 0
You omitted the PtrSafe keyword from the 64-bit declarations:
VBA Code:
#If VBA7 Then
    Private Declare PtrSafe Function SHGetPathFromIDListA Lib "shell32.dll" (ByVal pidl As Long, ByVal pszPath As String) As Long
    Private Declare PtrSafe Function SHBrowseForFolderA Lib "shell32.dll" (lpBrowseInfo As BROWSEINFO) As Long
#Else
    Private Declare Function SHGetPathFromIDListA Lib "shell32.dll" (ByVal pidl As Long, ByVal pszPath As String) As Long
    Private Declare Function SHBrowseForFolderA Lib "shell32.dll" (lpBrowseInfo As BROWSEINFO) As Long
#End If
Window handles and pointers in the BROWSEINFO user-defined type (UDT) must also be changed to LongPtr:
VBA Code:
#If VBA7 Then
    Private Type BROWSEINFO
        hOwner As LongPtr
        pidlRoot As Long
        pszDisplayName As String
        lpszTitle As String
        ulFlags As Long
        lpfn As LongPtr
        lParam As LongPtr
        iImage As Long
    End Type
#Else
    Private Type BROWSEINFO
        hOwner As Long
        pidlRoot As Long
        pszDisplayName As String
        lpszTitle As String
        ulFlags As Long
        lpfn As Long
        lParam As Long
        iImage As Long
    End Type
#End If
 
Upvote 0
You omitted the PtrSafe keyword from the 64-bit declarations:
VBA Code:
#If VBA7 Then
    Private Declare PtrSafe Function SHGetPathFromIDListA Lib "shell32.dll" (ByVal pidl As Long, ByVal pszPath As String) As Long
    Private Declare PtrSafe Function SHBrowseForFolderA Lib "shell32.dll" (lpBrowseInfo As BROWSEINFO) As Long
#Else
    Private Declare Function SHGetPathFromIDListA Lib "shell32.dll" (ByVal pidl As Long, ByVal pszPath As String) As Long
    Private Declare Function SHBrowseForFolderA Lib "shell32.dll" (lpBrowseInfo As BROWSEINFO) As Long
#End If
Window handles and pointers in the BROWSEINFO user-defined type (UDT) must also be changed to LongPtr:
VBA Code:
#If VBA7 Then
    Private Type BROWSEINFO
        hOwner As LongPtr
        pidlRoot As Long
        pszDisplayName As String
        lpszTitle As String
        ulFlags As Long
        lpfn As LongPtr
        lParam As LongPtr
        iImage As Long
    End Type
#Else
    Private Type BROWSEINFO
        hOwner As Long
        pidlRoot As Long
        pszDisplayName As String
        lpszTitle As String
        ulFlags As Long
        lpfn As Long
        lParam As Long
        iImage As Long
    End Type
#End If
Thanks!
 
Upvote 0

Forum statistics

Threads
1,215,061
Messages
6,122,922
Members
449,094
Latest member
teemeren

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top