Help updating code for 64 bit use

Javi

Active Member
Joined
May 26, 2011
Messages
440
Hi All,

I opened this workbook on a different computer and received the below error. Looking for some assistance making this code compatible with both 32-bit and 64-bit users.

Thanks!


VBA Code:
Private Declare Function FindWindowA Lib "user32" _
        (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowLongA Lib "user32" _
        (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLongA Lib "user32" _
        (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
        
        Public yukleme As Variant
Dim r, lst_column As Long




1600619402859.png
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
After more researching I found the issue and solution.

Had to add "PrtSafe" to each declare statement.


VBA Code:
Private Declare [B]PtrSafe [/B]Function FindWindowA Lib "user32" _
        (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare [B]PtrSafe[/B] Function GetWindowLongA Lib "user32" _
        (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare [B]PtrSafe[/B] Function SetWindowLongA Lib "user32" _
        (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
        
        Public yukleme As Variant
Dim r, lst_column As Long
 
Upvote 0
Hi Javi, happy you found a working solution.

Just looking at your post if you want to manually format code in your postings then you need to use the Rich (BB code) tag option rather than the VBA tag to get it to display correctly on the forum (or the </> with RICH underneath it icon in the reply window) ;)

1600631262748.png


Rich (BB code):
Private Declare PtrSafe Function FindWindowA Lib "user32" _
        (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
 
Upvote 0
Thank you RoryA,

You are 100% correct. After I made that modification, I did not get the error any longer. Also I did not fully test all of the functionality of my workbook. Now that I've tested it the code is not function properly. I am looking into the link you provided. Thanks again.
 
Upvote 0
My latest attempt to resolve this incompatibility is in the code below. I would greatly appreciate any help or assistance. The below code works well in a 32-bit system, when I open the workbook in a 64-bit environment it fails.




VBA Code:
Private Declare Function FindWindowA Lib "USER32" _
        (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare PtrSafe Function FindWindow Lib "USER32" _
        (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr



Private Declare Function GetWindowLongA Lib "USER32" _
        (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare PtrSafe Function GetWindowLongPtr Lib "USER32" Alias "GetWindowLongPtrA" (ByVal hWnd As LongPtr, ByVal nIndex As Long) As LongPtr
    


Private Declare Function SetWindowLongA Lib "USER32" _
        (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare PtrSafe Function SetWindowLong Lib "USER32" _
        (ByVal hWnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As Long) As LongPtr


        
        Public yukleme As Variant
Dim r, lst_column As Long
 
Upvote 0
You'll need to post the code that actually uses those API calls as well, since there will almost certainly be changes required to variable types.
 
Upvote 0
Thank you for your assistance. I ended up going in a different direction so the code is no longer needed. I do appreciate your replies.
 
Upvote 0

Forum statistics

Threads
1,214,998
Messages
6,122,638
Members
449,093
Latest member
Ahmad123098

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top