views:

438

answers:

3

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?

+1  A: 

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.

Ignacio Vazquez-Abrams
So there's no solution for this?Will I have to stay with 2 different executable for x64 and x32?
Eldad
Not in the same manner as having a DOS stub.
Ignacio Vazquez-Abrams
I'll be happy to hear about a different solution.
Eldad
+2  A: 

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.

LILkillaBEE
Eldad
Make launcher as a plain x86 exe, and that's it.From that launcher detect 32 or 64 bit win, and run proper version of your util or something that is more good for you.
LILkillaBEE
But this launcher would not work on an x64 bit with no WOW64 installed. Am I wrong?
Eldad
According to Ignacio, there's a collision when trying to combine 32 and 64-bit executable. So how can I make this launcher work on a x64 bit station that cannot run 32 bit applications (Like the WinPE 64bit)?
Eldad
A: 

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.

Francis
An installer is out of the question. I would rather go wuth 2 different executable before going for an installer solution.
Eldad