+ Reply to Thread
Results 1 to 13 of 13

64bit compatible code

  1. #1
    Registered User
    Join Date
    08-23-2014
    Location
    england
    MS-Off Ver
    2013
    Posts
    23

    64bit compatible code

    writing code on 2013 64bit and expected to be able to use VB7 as follows

    vba.png


    but doesn't like it. am I doing something wrong?

    (can't get uploaded image to display)

    #If VBA7 Then
    Private Declare PtrSafe Sub GetSystemTime Lib "kernel32" (ByRef lpSystemTime As SYSTEMTIME)
    Private Declare PtrSafe Function GetTimeZoneInformation Lib "kernel32" (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As LongPtr
    #Else
    Private Declare Sub GetSystemTime Lib "kernel32" (ByRef lpSystemTime As SYSTEMTIME)
    Private Declare Function GetTimeZoneInformation Lib "kernel32" (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long
    #End If
    Last edited by dalai; 11-03-2014 at 01:06 PM.

  2. #2
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: 64bit compatible code

    That all looks correct to me.
    Remember what the dormouse said
    Feed your head

  3. #3
    Registered User
    Join Date
    08-23-2014
    Location
    england
    MS-Off Ver
    2013
    Posts
    23

    Re: 64bit compatible code

    ok thanks. that's what I thought but when I edit the code (64bit Office 2013) I get a message for the items in red

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

  4. #4
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: 64bit compatible code

    Can you run the code?

  5. #5
    Registered User
    Join Date
    08-23-2014
    Location
    england
    MS-Off Ver
    2013
    Posts
    23

    Re: 64bit compatible code

    yes.

    I've setup a simple macro and inserted the above pre-processor commands. The code is in red as above but I can compile and run the macro.

    should I ignore this?

  6. #6
    Forum Contributor
    Join Date
    06-04-2013
    Location
    Moscow
    MS-Off Ver
    Office 365
    Posts
    100

    Re: 64bit compatible code

    For 64 bit not exists long statement. It's LongLong must be.
    So, you also must add a check: is the 64-bit system?

    Try this
    Please Login or Register  to view this content.
    I'm sorry my english...

  7. #7
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: 64bit compatible code

    Quote Originally Posted by dalai View Post
    yes.

    I've setup a simple macro and inserted the above pre-processor commands. The code is in red as above but I can compile and run the macro.

    should I ignore this?
    Yes. The code will appear in red but should still work.

  8. #8
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: 64bit compatible code

    FYI, GetTimeZoneInformation returns a Long, not a LongPtr even in 64 bit. There is no need for a #Win64 check here.

  9. #9
    Registered User
    Join Date
    08-23-2014
    Location
    england
    MS-Off Ver
    2013
    Posts
    23

    Re: 64bit compatible code

    Quote Originally Posted by The_Prist View Post
    For 64 bit not exists long statement. It's LongLong must be.
    So, you also must add a check: is the 64-bit system?

    Try this
    Please Login or Register  to view this content.

    thank you. I'm a bit confused now. so PtrSafe not required if Win64?

    here my 32-bit declarations:

    Private Declare Sub GetSystemTime Lib "kernel32" (ByRef lpSystemTime As SYSTEMTIME)
    Private Declare Function GetTimeZoneInformation Lib "kernel32" (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long
    Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    Last edited by dalai; 11-04-2014 at 08:20 AM.

  10. #10
    Registered User
    Join Date
    08-23-2014
    Location
    england
    MS-Off Ver
    2013
    Posts
    23

    Re: 64bit compatible code

    is this ok?

    'Util
    #If VBA7 and Win64 Then
    Private Declare PtrSafe Sub GetSystemTime Lib "kernel32" (ByRef lpSystemTime As SYSTEMTIME)
    'GetTimeZoneInformation returns a Long, not a LongPtr even in 64 bit
    Private Declare PtrSafe Function GetTimeZoneInformation Lib "kernel32" (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long
    #Else
    Private Declare Sub GetSystemTime Lib "kernel32" (ByRef lpSystemTime As SYSTEMTIME)
    Private Declare Function GetTimeZoneInformation Lib "kernel32" (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long
    #End If

    'Main
    #If VBA7 and Win64 Then
    Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    #Else
    Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    #End If
    Last edited by dalai; 11-04-2014 at 09:46 AM.

  11. #11
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: 64bit compatible code

    You only need to check Win64 in rare cases where an API function is 64bit specific - eg it returns a LongLong. For 99% of situations testing VBA7 is sufficient.

  12. #12
    Registered User
    Join Date
    08-23-2014
    Location
    england
    MS-Off Ver
    2013
    Posts
    23

    Re: 64bit compatible code

    ok thanks, so ...

    'Util
    #If VBA7 Then
    Private Declare PtrSafe Sub GetSystemTime Lib "kernel32" (ByRef lpSystemTime As SYSTEMTIME)
    'GetTimeZoneInformation returns a Long, not a LongPtr even in 64 bit
    Private Declare PtrSafe Function GetTimeZoneInformation Lib "kernel32" (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long
    #Else
    Private Declare Sub GetSystemTime Lib "kernel32" (ByRef lpSystemTime As SYSTEMTIME)
    Private Declare Function GetTimeZoneInformation Lib "kernel32" (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long
    #End If

    'Main
    #If VBA7 Then
    Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    #Else
    Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    #End If

  13. #13
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: 64bit compatible code

    Looks OK to me.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. SOAP component30 not compatible with Office 64bit
    By ccs1981 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-23-2014, 03:56 AM
  2. my 32bit vba code won't run in 64bit
    By ncaravela in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-17-2014, 02:15 PM
  3. Change registry settings for IE 64bit in 64bit environment
    By dgdgdg in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-30-2014, 07:56 AM
  4. [SOLVED] Updating Code for 64bit Office
    By D.A.S in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 11-22-2013, 06:16 PM
  5. Replies: 3
    Last Post: 11-23-2012, 01:57 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1