Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I share HWND between 32 and 64 bit applications in Win x64?

Tags:

MSDN tells me that handles to windows (HWND) can be shared between 32- and 64-bit applications, in Interprocess Communication (MSDN). However, in Win32 a HWND is 32 bits, whereas in 64 bit Windows it is 64 bits. So how can the handles be shared?

I guess the same question applies to handles to named objects such as mutexes, semaphores and file handles.

like image 352
Marc Durdin Avatar asked Nov 30 '09 21:11

Marc Durdin


People also ask

Can 32-bit applications run on a 64-bit PC?

Can I run 32-bit programs on a 64-bit computer? Most programs made for the 32-bit version of Windows will work on the 64-bit version of Windows except for most Antivirus programs. Device drivers that are made for the 32-bit version of Windows will not work correctly on a computer running a 64-bit version of Windows.

How do I run 32-bit applications on 64-bit?

Right-click on the app and choose Properties. In the Properties window, select the Compatibility tab. Then, under the Compatibility mode, check Run this program in compatibility mode for and select the target Windows system.

Will 32-bit and 64-bit combination compatible and will work together?

In short: You can't link a 32-bit app to a 64-bit library. You can run a 32-bit application, using 32-bit shared libraries on a 64-bit OS (at least all the popular 32-/64-bit processors such as AMD, Intel and Sparc). But that doesn't involve any libraries.


1 Answers

As Daniel Rose points out above, the MSDN documentation now states:

... it is safe to truncate the handle (when passing it from 64-bit to 32-bit) or sign-extend the handle (when passing it from 32-bit to 64-bit).

There still seems to be some confusion here, given that I was told zero extension is the correct way by a WOW64 dev. If you are writing a 64 bit module that gets handles from 32 bit modules, the safest bet might be to compare only the lower 32 bits of the handle (i.e. truncate). Otherwise, you may be caught out on a sign-extension vs zero-extension difference.

like image 108
Marc Durdin Avatar answered Sep 23 '22 14:09

Marc Durdin