Work on windows 10 64 Bit and Office 64Bit

YasserKhalil
PlatinumLounger
Posts: 4931
Joined: 31 Aug 2016, 09:02

Work on windows 10 64 Bit and Office 64Bit

Post by YasserKhalil »

Hello everyone
I have these declarations

Code: Select all

Private Declare PtrSafe Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare PtrSafe Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
When sending the file to someone who has Windows 64 Bit and Office 64Bit , he encountered an error at some lines
How to make these declarations flexible to work on 32 bit and 64 bit either the windows or office?

User avatar
HansV
Administrator
Posts: 78566
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Work on windows 10 64 Bit and Office 64Bit

Post by HansV »

SendMessageString and SendMessage are the same, use only one.

Code: Select all

Private Declare PtrSafe Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As LongPtr, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As LongPtr
Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As LongPtr
Private Declare PtrSafe Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As LongPtr, ByVal hWnd2 As LongPtr, ByVal lpsz1 As String, ByVal lpsz2 As String) As LongPtr
Private Declare PtrSafe Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As LongPtr, ByVal lpString As String, ByVal cch As LongPtr) As Long
Private Declare PtrSafe Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hWnd As LongPtr) As Long
Last edited by HansV on 27 Feb 2024, 15:20, edited 1 time in total.
Reason: to correct one error
Best wishes,
Hans

User avatar
HansV
Administrator
Posts: 78566
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Work on windows 10 64 Bit and Office 64Bit

Post by HansV »

Best wishes,
Hans

User avatar
rory
5StarLounger
Posts: 818
Joined: 24 Jan 2010, 15:56

Re: Work on windows 10 64 Bit and Office 64Bit

Post by rory »

The first arg (hWnd) to SendMessage should be a LongPtr too.
Regards,
Rory

User avatar
HansV
Administrator
Posts: 78566
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Work on windows 10 64 Bit and Office 64Bit

Post by HansV »

Thanks!
Best wishes,
Hans