A single executable for 32 and 64 bit (Without WOW64)
-
24-09-2019 - |
Question
I'm writing a small utility that should run on both 16\32\64 bit systems.
My old utility ran both on 32 and 16 bit by compressing the 16bit version to the 32 bit and applying the /stub
switch in visual studio 2008 (/STUB -MS-DOS Stub File Name ).
I'm looking for a way to do the same with my 64 bit executable. The target 64bit system is Win PE 64bit and it doesn't have the WOW64 installed on it.
Is it possible?
Solution
The DOS stub of Windows executables uses the MZ section, whereas both 32-bit and 64-bit executables use the PE section. This allows the DOS stub to exist within either Windows executable, but causes a collision when trying to combine 32- and 64-bit executables.
OTHER TIPS
You should pack your 32 and 64 bit util in resources of another exe, let's call it launcher 32 bit. Then your launcher should detect on what system it is started from and then extract proper binary from it's resources and start it.
Windows 32-bit runs 16-bit applications by wowexec.exe, and Win64 runs 32-bit application by wow64. So without wow64 it's impossible for your program to create a universal launcher on Windows. (Note: Mac OSX supports multiple architecture in single binary anyway)
The best approach I can figure out is to create a single MSI installer package and put both 32/64 exes into it.