PDA

View Full Version : Solved: 64-bit compilation



Zack Barresse
10-11-2010, 05:14 PM
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:
#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
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?

Kenneth Hobs
10-11-2010, 06:34 PM
Would Win64 help?

http://msdn.microsoft.com/en-us/library/ee691831.aspx

Zack Barresse
10-11-2010, 08:00 PM
No it doesn't work, which is the problem, even though its not what I need.

Jan Karel Pieterse
10-11-2010, 11:24 PM
Care to share your code?
And did you go here too:
http://www.jkp-ads.com/articles/apideclarations.asp (http://www.vbaexpress.com/forum/)

Jan Karel Pieterse
10-11-2010, 11:26 PM
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 (http://www.vbaexpress.com/forum/)

Zack Barresse
10-16-2010, 09:19 AM
Yes, I've read that web page, and others, like those linked there. The code I'm testing is the lock window API...

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

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.

Jan Karel Pieterse
10-16-2010, 10:34 AM
I guess the dim statement also has to become conditional:

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

Zack Barresse
10-16-2010, 11:11 AM
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

Zack Barresse
10-16-2010, 11:12 AM
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.

Jan Karel Pieterse
10-17-2010, 05:08 AM
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 :-)

Zack Barresse
10-17-2010, 08:16 AM
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. :)

Kenneth Hobs
10-17-2010, 08:30 AM
I have 64bit VistaHome but must have installed MSOffice10 in 32bit mode. VBA7 is null.

I get a runtime error 1004 for: VBEhWnd = Application.VBE.MainWindow.Hwnd

VarType(VBEhWnd) is 3, vblong.

Jan Karel Pieterse
10-17-2010, 10:08 AM
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.

Zack Barresse
10-17-2010, 10:16 AM
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.