Upgrading from 32 bit to 64 (1 Viewer)

Dreamweaver

Well-known member
Local time
Today, 14:11
Joined
Nov 28, 2005
Messages
2,466
This is the 32 bit API call


Code:
Declare Function adh_apiSendMessage Lib "user32" Alias "SendMessageA" _
 (ByVal Hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long


The 64 bit version edits in blue


Code:
Declare [COLOR=navy]PtrSafe[/COLOR] Function adh_apiSendMessage Lib "user32" Alias "SendMessageA" _
 (ByVal Hwnd As [COLOR=navy]LongPtr[/COLOR], ByVal wMsg As [COLOR=navy]LongPtr[/COLOR], ByVal wParam As [COLOR=navy]LongPtr[/COLOR], lParam As Any) As [COLOR=navy]LongPtr[/COLOR]


This compiles and works without issue and may be a little faster but I'm on a 32 bit system so haven't been able to test for 64
 

Dreamweaver

Well-known member
Local time
Today, 14:11
Joined
Nov 28, 2005
Messages
2,466
Does it matter if you use a longPtr instead of long as noticed a few API call still include Long datatype?
 

isladogs

MVP / VIP
Local time
Today, 14:11
Joined
Jan 14, 2017
Messages
18,186
Only the pointers need LongPtr e.g. hWnd

Code:
#If VBA7 Then
     Declare PtrSafe Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As LongPtr, ByVal wMsg As Long, ByVal wParam As LongPtr, lParam As Any) As LongPtr
#Else
     Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
#End If

Useful links:
Windows API Viewer utility
https://www.rondebruin.nl/win/dennis/windowsapiviewer.htm

https://codekabinett.com/rdumps.php?Lang=2&targetDoc=windows-api-declaration-vba-64-bit

https://docs.microsoft.com/en-gb/office/vba/Language/Concepts/Getting-Started/64-bit-visual-basic-for-applications-overview
 

Dreamweaver

Well-known member
Local time
Today, 14:11
Joined
Nov 28, 2005
Messages
2,466
this may be a silly question but I think I read that if we are using access 2010 onwards we will be using vba7 same for an accdb file format and that format wont onen in enything less that 2010 so do we need all that extra code??
 

isladogs

MVP / VIP
Local time
Today, 14:11
Joined
Jan 14, 2017
Messages
18,186
If users are only using Access 2010 or later, MOST conditional compilation code isn't needed. Just use the VBA7 version with PtrSafe and LongPtr for pointers and it will work in both bitnesses

BUT
a) some code is specific to 32-bit or 64-bit e.g GetTickCount/GetTickCount64 and some code will not work in 64-bit a all.
b) those using A2007 or earlier will not be able to open your database if you omit conditional compilation.

I still use conditional compilation so my apps can (mostly) be run in A2007 but I no longer use a 3 part version of CC
 

Dreamweaver

Well-known member
Local time
Today, 14:11
Joined
Nov 28, 2005
Messages
2,466
I have been thinking of converting all my projects to accdb file formats 2010+ so won't have to worry about it mdb's are starting to show there age lol
 

Dreamweaver

Well-known member
Local time
Today, 14:11
Joined
Nov 28, 2005
Messages
2,466
Think I got them all in one module except one in red I'm not sure about


Code:
#If VBA7 Then

    Private Declare PtrSafe Function SHGetSpecialFolderLocation Lib "shell32.dll" (ByVal hWndOwner As Long, ByVal Folder As LongPtr, ByRef idl As LongPtr) As LongPtr
    Private Declare PtrSafe Function SHBrowseForFolder Lib "shell32.dll" (ByRef bi As BROWSEINFO) As LongPtr
    [COLOR=Red]Private Declare PtrSafe Sub CoTaskMemFree Lib "ole32.dll" (ByVal pv As LongPtr)[/COLOR]
[COLOR=Red]  'Checked this but not sure it says it's A pointer to the memory block to be freed. If this parameter is [B]NULL[/B], the function has no effect[/COLOR]
    Private Declare PtrSafe Function SHGetPathFromIDList Lib "shell32.dll" (ByVal idl As LongPtr, ByVal Path As String) As Boolean
    Private Declare PtrSafe Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal Hwnd As LongPtr, ByVal wMsg As Long, ByVal wParam As LongPtr, ByVal lParam As Any) As LongPtr

    Private Type BROWSEINFO
        hWndOwner As Long           ' Owner
        pidlRoot As LongPtr            ' Can be null
        strDisplayName As String    ' Recieves display name of folder
        StrTitle As String          ' title/instructions for user
        ulFlags As Long             ' 0 or BIF constants
        lpfn As LongPtr                ' Address for callback
        lParam As Long              ' Passes to callback
        iImage As Long              ' index to the system image list
    End Type

#Else

    Private Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" (ByVal hWndOwner As Long, ByVal Folder As Long, ByRef idl As Long) As Long
    Private Declare Function SHBrowseForFolder Lib "shell32.dll" (ByRef bi As BROWSEINFO) As Long
    Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal pv As Long)
    Private Declare Function SHGetPathFromIDList Lib "shell32.dll" (ByVal idl As Long, ByVal Path As String) As Boolean 'Long
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal Hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Any) As Long

    Private Type BROWSEINFO
        hWndOwner As Long           ' Owner
        pidlRoot As Long            ' Can be null
        strDisplayName As String    ' Recieves display name of folder
        StrTitle As String          ' title/instructions for user
        ulFlags As Long             ' 0 or BIF constants
        lpfn As Long                ' Address for callback
        lParam As Long              ' Passes to callback
        iImage As Long              ' index to the system image list
    End Type

#End If
Also found a long that should have been a boolean


Been looking at http://allapi.mentalis.org/apilist/apilist.php but they havent updated for 64 yet
 
Last edited:

isladogs

MVP / VIP
Local time
Today, 14:11
Joined
Jan 14, 2017
Messages
18,186
Sorry Mick but I don't have time to check each of your conversions.
Perhaps someone else will however.

Suggest you download the Windows API utility from Ron de Bruin's site that I mentioned in an earlier reply as that includes almost all the APIs you are likely to use in both 32 & 64-bit versions. Ignore the fact that its described as for Excel.

However in the end, to be certain that a conversion works you will need to test it in a 64-bit environment. Suggest you create a VM to do that
 

Dreamweaver

Well-known member
Local time
Today, 14:11
Joined
Nov 28, 2005
Messages
2,466
Sorry missed that utility downloading now thanks the project I'm working on will be free to use so will see if I can find somebody to test it for me as my me and my laptops not really that good with vms and all that just do this because it keeps my brain active thanks
 

Users who are viewing this thread

Top Bottom