In the last few years, I built a good number of applications using MSAccess and all the useful tools it has.
Ok, the title of this post may be a little strange because sincerely, who are still using an old 32-bit version? We are in 2020! In my case, I have some small clients that have for example old warehouse machinery that they need to integrate into the management system linking them to a server. So what happens is that we can have a system with, for example, 10 pc with a 64-bit version and 1 with a 32-bit version. This is a problem especially if you have built an auto-update system. So, I searched for a solution that could help me to fix this issue. The problem for me was that the declaration statement of a function in a module is different for the 2 versions, or rather in the 64-bit version, you have to add the keyword PtrSafe to the declaration statement. Microsoft ensures that adding the PtrSafe keyword, the declaration statement will work in both versions but at some conditions. So, when I built the first version in 32-bit, I had this declaration statement:
Declare Function aht_apiGetOpenFileName Lib "comdlg32.dll" _
Alias "GetOpenFileNameA" (OFN As tagOPENFILENAME) As Boolean
And now I must change it with:
Declare PtrSafe Function aht_apiGetOpenFileName Lib "comdlg32.dll" _
Alias "GetOpenFileNameA" (OFN As tagOPENFILENAME) As Boolean
Pretty simple. But as Microsoft said in this article, if I want to continue to use the rest of the 32-bit code, it has to respect some conditions. So I decide to use the If statement of the Microsoft Article as I haven't a large number of Functions declared in that way. This is the final result:
#If VBA7 Then
Declare PtrSafe Function aht_apiGetOpenFileName Lib "comdlg32.dll" _
Alias "GetOpenFileNameA" (OFN As tagOPENFILENAME) As Boolean
#Else
Declare Function aht_apiGetOpenFileName Lib "comdlg32.dll" _
Alias "GetOpenFileNameA" (OFN As tagOPENFILENAME) As Boolean
#End If
Thank you for reading.
Top comments (0)