Consulting

Results 1 to 14 of 14

Thread: Solved: 64-bit compilation

  1. #1
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location

    Solved: 64-bit compilation

    Anyone have any experience with 64-bit Excel and conditional compilation? I'm using it, and I can't seem to get my conditional compile statements to work.

    Here is what I'm using:
    [VBA]#If VBA7 Then
    Private Declare PtrSafe Function LockWindowUpdate Lib "user32" (ByVal hwndLock As LongPtr) As LongPtr
    #Else
    Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) As Long
    #End If[/VBA]
    It still gives me errors, and it's driving me batty. I'm sure it's probably something very simple, bug good grief.

    This is part of an add-in I'm tinkering with. It is the only API statement in the entire project.

    Another oddity with this project (works on 32-bit, just the 64-bit conversion I'm working on) is I can't seem to set a command bar button (in the VBIDE) to a class module event button. Wondering if it didn't get sorted in VBA7?

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location

  3. #3
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    No it doesn't work, which is the problem, even though its not what I need.

  4. #4
    Care to share your code?
    And did you go here too:
    http://www.jkp-ads.com/articles/apideclarations.asp
    Regards,

    Jan Karel Pieterse
    Excel MVP jkp-ads.com

  5. #5
    Care to share your code?
    Don't forget that you may have to conditionallly dim your related variables too:

    #If VBA7 Then
    Dim hwnd as LongPtr
    #Else
    Dim hWnd as Long
    #End If

    And did you go here too:
    http://www.jkp-ads.com/articles/apideclarations.asp
    Regards,

    Jan Karel Pieterse
    Excel MVP jkp-ads.com

  6. #6
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Yes, I've read that web page, and others, like those linked there. The code I'm testing is the lock window API...

    [vba]Option Explicit

    #If VBA7 Then
    Private Declare PtrSafe Function LockWindowUpdate Lib "user32" (ByVal hwndLock As LongPtr) As LongPtr
    #Else
    Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) As Long
    #End If

    Sub TestingAPI()
    Dim VBEHwnd As Long
    VBEHwnd = Application.VBE.MainWindow.hWnd
    LockWindowUpdate (VBEHwnd)
    LockWindowUpdate (0&)
    End Sub[/vba]

    It does run, but I have a compile error on the 32-bit version, which does work on 32-bit systems. Why wouldn the conditional compilation be throwing an error? I need other eyes on this, I'm banging my head.

  7. #7
    I guess the dim statement also has to become conditional:

    [VBA]Sub TestingAPI()
    #If VBA7 Then
    Dim VBEHwnd As LongPtr
    #Else
    Dim VBEHwnd As Long
    #End If
    VBEHwnd = Application.VBE.MainWindow.Hwnd
    LockWindowUpdate (VBEHwnd)
    LockWindowUpdate (0&)
    End Sub

    [/vba]
    Regards,

    Jan Karel Pieterse
    Excel MVP jkp-ads.com

  8. #8
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    I tried that earlier and it didn't make a difference, so I figured I didn't need it. In either case, the 32-bit API still doesn't compile, and is red...

    Option Explicit
    
    #If VBA7 Then
        Private Declare PtrSafe Function LockWindowUpdate Lib "user32" (ByVal hwndLock As LongPtr) As LongPtr
    #Else
        Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) As Long
    #End If
     
    Sub TestingAPI()
        #If VBA7 Then
            Dim VBEhWnd As LongPtr
        #Else
            Dim VBEhWnd As Long
        #End If
        VBEhWnd = Application.VBE.MainWindow.hWnd
        LockWindowUpdate (VBEhWnd)
        LockWindowUpdate (0&)
    End Sub

  9. #9
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    I guess I'm asking if 1) I'm overlooking something obvious, 2) if someone can test in a 64-bit environment to see if the results are the same.

  10. #10
    You must ignore the fact that the lines are red. As long as you get no compile errors when you do a debug, compile, you're fine on the current system. I haven't got a 64 bit system yet, otherwise I'd be testing this too :-)
    Regards,

    Jan Karel Pieterse
    Excel MVP jkp-ads.com

  11. #11
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    I'm still trying to get my 32 bit virtual space setup for my testing and haven't been able to. So you're saying that's normal, interesting. Thanks Jan.

  12. #12
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    I have 64bit VistaHome but must have installed MSOffice10 in 32bit mode. VBA7 is null.

    I get a runtime error 1004 for: [VBA]VBEhWnd = Application.VBE.MainWindow.Hwnd[/VBA]

    VarType(VBEhWnd) is 3, vblong.

  13. #13
    Kenneth: I must have been looking cross-eyed. VBE.MainWindow.Hwnd is NOT an API call. So I expect it just works with a long type declaration.
    Regards,

    Jan Karel Pieterse
    Excel MVP jkp-ads.com

  14. #14
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Quote Originally Posted by Kenneth Hobs
    VBA7 is null.
    What do you mean? If you have Office 2010 you have VBA7. You may have 32-bit though, which is installed by default unless you specifically choose it.

Posting Permissions

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