Share via

The code in this project must be updated for use on 64 bit systems

Anonymous
2019-11-11T02:27:26+00:00

Hello,

I updated my computer to office 365 using Access.  Now I am receiving an 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". 

Any suggestions of what code needs to be added and where would be appreciated.

Thanks

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

  1. ScottGem 68,810 Reputation points Volunteer Moderator
    2019-11-11T14:09:00+00:00

    So right at the top you have a DECLAREd function:

    Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _

    (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

    All you need to do is edit it to:

    Private Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _

    (ByVal hwnd As LongPtr, ByVal nIndex As LongPtr, ByVal dwNewLong As LongPtr) As Long

    Edit each Declare by adding PtrSafe afterward and change each Long to Long Ptr (within the parentheses).

    100+ people found this answer helpful.
    0 comments No comments

5 additional answers

Sort by: Most helpful
  1. ScottGem 68,810 Reputation points Volunteer Moderator
    2019-11-11T03:40:14+00:00

    Hi Reginald, I'm an independent adviser and can help with this.

    Your code is probably using API calls that require DECLARE statements. Something like :

    DECLARE Sub...

    These statements need to be changed to:

    DECLARE PtrSafe Sub …

    Also any variables declared as Long need to be changed to LongPtr.

    This article explains: https://docs.microsoft.com/en-us/office/vba/lan...

    7 people found this answer helpful.
    0 comments No comments
  2. Anonymous
    2019-11-12T03:48:00+00:00

    Scott,

    You awesome.  Thanks so much for making the code simple enough for me to understand.  I made the 2 simple changes about 75 times but it works.  Thanks again.

    6 people found this answer helpful.
    0 comments No comments
  3. Anonymous
    2019-11-11T03:21:14+00:00

    Take a look at this article:

    .

    Declaring API functions in 64 bit Office

    https://www.jkp-ads.com/Articles/apideclarations.asp

    With the introduction of Windows 7 and Office 2010 VBA developers face a new challenge: ensuring their applications work on both 32 bit and 64 bit platforms.

    This page is meant to become the first stop for anyone who needs the proper syntax for his API declaration statement in Office VBA.  It includes links to related MS documentation.

    3 people found this answer helpful.
    0 comments No comments
  4. Anonymous
    2019-11-11T03:46:34+00:00

    Thank you for the article and I understand the reason why this is happening with the change of 32 bit to 64.  However, I do not know how to code.  What part do I need to copy over?  Some of the code in my program shows red (It is underlined below), is this what needs to be replaced?

    'Team Pro Solutions - www.t-p-s.co.uk

    '

    ' Ken Getz and Michael Kaplan.

    Option Compare Database

    Option Explicit

    Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _

    (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

    '-------------------------------------------------------------------------------------------------------------------

    '   Declarations

    '

    '   These function names were puzzled out by using DUMPBIN /exports

    '   with VBA332.DLL and then puzzling out parameter names and types

    '   through a lot of trial and error and over 100 IPFs in MSACCESS.EXE

    '   and VBA332.DLL.

    '

    '   These parameters may not be named properly but seem to be correct in

    '   light of the function names and what each parameter does.

    '

    '   EbGetExecutingProj: Gives you a handle to the current VBA project

    '   TipGetFunctionId: Gives you a function ID given a function name

    '   TipGetLpfnOfFunctionId: Gives you a pointer a function given its function ID

    '

    '-------------------------------------------------------------------------------------------------------------------

    Private Declare Function GetCurrentVbaProject _

     Lib "vba332.dll" Alias "EbGetExecutingProj" _

     (hProject As Long) As Long

    Private Declare Function GetFuncID _

     Lib "vba332.dll" Alias "TipGetFunctionId" _

     (ByVal hProject As Long, ByVal strFunctionName As String, _

     ByRef strFunctionId As String) As Long

    Private Declare Function GetAddr _

     Lib "vba332.dll" Alias "TipGetLpfnOfFunctionId" _

     (ByVal hProject As Long, ByVal strFunctionId As String, _

     ByRef lpfn As Long) As Long

    '-------------------------------------------------------------------------------------------------------------------

    '   AddrOf

    '

    '   Returns a function pointer of a VBA public function given its name. This function

    '   gives similar functionality to VBA as VB5 has with the AddressOf param type.

    '

    '   NOTE: This function only seems to work if the proc you are trying to get a pointer

    '       to is in the current project. This makes sense, since we are using a function

    '       named EbGetExecutingProj.

    '-------------------------------------------------------------------------------------------------------------------

    Public Function AddrOf(strFuncName As String) As Long

        Dim hProject As Long

        Dim lngResult As Long

        Dim strID As String

        Dim lpfn As Long

        Dim strFuncNameUnicode As String

        Const NO_ERROR = 0

        ' The function name must be in Unicode, so convert it.

        strFuncNameUnicode = StrConv(strFuncName, vbUnicode)

        ' Get the current VBA project

        ' The results of GetCurrentVBAProject seemed inconsistent, in our tests,

        ' so now we just check the project handle when the function returns.

        Call GetCurrentVbaProject(hProject)

        ' Make sure we got a project handle... we always should, but you never know!

        If hProject <> 0 Then

            ' Get the VBA function ID (whatever that is!)

            lngResult = GetFuncID( _

             hProject, strFuncNameUnicode, strID)

            ' We have to check this because we GPF if we try to get a function pointer

            ' of a non-existent function.

            If lngResult = NO_ERROR Then

                ' Get the function pointer.

                lngResult = GetAddr(hProject, strID, lpfn)

                If lngResult = NO_ERROR Then

                    AddrOf = lpfn

                End If

            End If

        End If

    End Function

    ' From Dev Ashish's site.

    'http://www.mvps.org/access/api/api0031.htm

    'Warnings:

    '(1)    AddressOf is COMPLETELY UNSUPPORTED by Microsoft in Office 97

    '       environment. Use it at your own risk!!

    '(2)    Entering debug mode is not recommended as it is likely to

    '       cause problems (GPFs etc.).

    '(3)    Make sure you backup your work and save before running any such code.

    '       Using this technique adds another level of instability since

    '       there are so many different ways to set up things wrong.

    '       Once you get it to work properly, everything should be ok.

    '(4)    Make sure you enter a On Error Resume Next at the top of

    '       any callback function. This is done to ensure that any errors within a callback function are not propagated back to its caller.

    '(5)    Be careful of ByVal or ByRef when passing arguments to the function.

    '       If you don't get this right, nothing's going to work.

    Public Function GetVersion()

    Dim mintAccessVer As Integer

    mintAccessVer = CInt(SysCmd(acSysCmdAccessVer))

    If mintAccessVer = 9 Then       ' Access 2000 ONLY

            'lpPrevWndProc = SetWindowLong( _

             '                       mhWndMDIClient, _

              '                      GWL_WNDPROC, _

               '                     AddressOf modMDIClient.WndProc)

        ElseIf mintAccessVer = 8 Then       ' Access 97  ONLY

            ' You will obviously need Michael Kaplan's and

            ' Ken Getz's AddrOf function in Access 97

            'lpPrevWndProc = apiSetWindowLong( _

                                    mhWndMDIClient, _

                                    GWL_WNDPROC, _

                                    AddrOf("WndProc"))

        End If

    End Function

    0 comments No comments