Compile error: The code in this project must be updated for use on 64-bit systems.

Zak14

Registered User.
Local time
Today, 10:09
Joined
Jun 27, 2014
Messages
166
Compile error:

The code in this project must be updated for use on 64-bit systems.
Please review and update Declare statements and then mark them with the PtrSafe attribute.

I get the above error when using code to centre a popup form.

I am using 64-bit Windows with 64-bit MS Office, but I want this code to work on both 32-bit and 64-bit (Windows / MS Office) and if it matters at all, on all versions of Windows above XP.

How do I get it to do just that?
Sorry for my apparent ignorance on the subject.
I looked around for a solution, but didn't really understood much of what the internet has to offer regarding this.

Here is the code that errs (specifically lines 2-5):
Code:
' API declarations:
Private Declare Function apiGetClientRect Lib "user32" Alias "GetClientRect" (ByVal hwnd As Long, lpRect As typRect) As Long
Private Declare Function apiGetWindowRect Lib "user32" Alias "GetWindowRect" (ByVal hwnd As Long, lpRect As typRect) As Long
Private Declare Function apiSetWindowPos Lib "user32" Alias "SetWindowPos" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Declare Function apiShowWindow Lib "user32" Alias "ShowWindow" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
' Type declarations:
Private Type typRect
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type
' Constant declarations:
Private Const SW_RESTORE = 9
Private Const SWP_NOSIZE = &H1 ' Don't alter the size
Private Const SWP_NOZORDER = &H4 ' Don't change the Z-order
Private Const SWP_SHOWWINDOW = &H40 ' Display the window
' **************************************
' * Center a form in the Access window *
' **************************************
' Created 1-22-2002 by Peter M. Schroeder
Public Function gfncCenterForm(parForm As Form) As Boolean
    Dim varAccess As typRect, varForm As typRect
    Dim varX As Long, varY As Long
    
    On Error GoTo CenterForm_Error
    Call apiGetClientRect(hWndAccessApp, varAccess) ' Get the Access client area coordinate
    Call apiGetWindowRect(parForm.Hwnd, varForm) ' Get the form window coordinates
    varX = CLng((varAccess.Left + varAccess.Right) / 2) - CLng((varForm.Right - varForm.Left) / 2) ' Calculate a new left for the form
    varY = CLng((varAccess.Top + varAccess.Bottom) / 2) - CLng((varForm.Bottom - varForm.Top) / 2) ' Calculate a new top for the form
    varY = varY - 45 ' Adjust top for true center
    varY = varY - 20 ' Adjust top for appearance
    Call apiShowWindow(parForm.Hwnd, SW_RESTORE) ' Restore form window
    Call apiSetWindowPos(parForm.Hwnd, 0, varX, varY, (varForm.Right - varForm.Left), (varForm.Bottom - varForm.Top), SWP_NOZORDER Or SWP_SHOWWINDOW Or SWP_NOSIZE) ' Set new form coordinates
    gfncCenterForm = True
    Exit Function
    
CenterForm_Error:
    gfncCenterForm = False
End Function

Thanks.
 
Last edited:
Thanks Gina,

I read the page and found the solution.

I changed statements like this...
Code:
    Private Declare Function apiGetClientRect Lib "user32" Alias "GetClientRect" (ByVal hwnd As Long, lpRect As typRect) As Long

...to something like this
Code:
#If Win64 Then
    Private Declare PtrSafe Function apiGetClientRect Lib "user32" Alias "GetClientRect" (ByVal hwnd As LongLong, lpRect As typRect) As LongLong
#Else
    Private Declare Function apiGetClientRect Lib "user32" Alias "GetClientRect" (ByVal hwnd As Long, lpRect As typRect) As Long
#End If
Obviously, I grouped all "Declare" statements together.

But I've got a question.

I've replaced "Long" with "LongLong" for the 64-bit version of the code.
But, is that necessary, since it seems to work without it?

And if it is necessary, do I need to replace "typRect" too with something else for the 64-bit version of the code.
There are other "Long"s and "typRect"s in the rest of the code. Do they need to be changed?
 
Last edited:
Hmm, to be honest, I don't know. However, from my fellow MVP's I advise changing them appropriately as what may work fine on your system may not on someone else's. So, yes...

Long to LongLong

But again, I am basing this on what I have *heard*, not on first hand knowledge. :D
 
I'm getting the error on the attached screenshot. Any help would be appreciated.
 

Attachments

  • apiShowWindow Error.png
    apiShowWindow Error.png
    43.3 KB · Views: 3,494
Better screenshot with highlights for clarity. Any help would be appreciated - thanks in advance.
 

Attachments

  • apiShowWindow Error.png
    apiShowWindow Error.png
    42.6 KB · Views: 2,985
Sounds like you need to use PtrSafe, did you see Zak14's post?
 
any progress here? I have similar problem
Hi. Welcome to AWF! You are replying to an old thread. You might want to start your own and post the code showing the problem you're having.
 

Users who are viewing this thread

Back
Top Bottom