views:

346

answers:

5

I really like the way the SysInternals utilities (e.g. Process Explorer) handle 64bit compatibility. It looks like the 32bit executable has the 64bit version embedded in it, and extracts it if necessary.

I'd like a tool which automates this - i.e. takes 32bit and 64bit executables, packs them together somehow, and inserts stub code to launch the right executable according to which platform its gets run on.

Before I start to roll my own, does anyone know of something like this which already exists?

+4  A: 

This appears to have been covered already (although it's quite shallow on detail) within...

http://stackoverflow.com/questions/802192/roll-64-bit-and-32-bit-versions-of-an-app-into-the-same-binary

middaparka
Bother - didn't find that post when I searched. Still, it doesn't really answer my question - modified my title to make it clearer.
snowcrash09
+2  A: 

Not a tool, but it seems fairly easy to embed your executables in a VC++ project as resources, and run the correct one after checking the OS environment.

Use the IsWow64Process function to detect 32 or 64 bit, and here is a nice writeup including source code on how to embed the executables: http://www.codeproject.com/KB/winsdk/binaryresources.aspx .

Zed
+2  A: 

While this is possible, I would consider it a bad practice since most of those applications (e.g. Process Explorer) extract that file in working directory. If you like to put programs in "Program Files" folder, that clashes with that directory being read-only.

For me it just seems easier to have two programs separated and make shortcut just to x86 file. If that version detects 64-bits, it just needs to launch x64 file.

If you have really good reason to combine those two, than embeedding it as resource seems like a correct path.

Josip Medved
+2  A: 

That's why I like programming in .NET - you can create you application targeted to 'Any' platform and then IL-team will care about running your application in best available mode...

Regent
+2  A: 

Mark Russinovich of SysInternals fame describes their method here. They do embed an x64 image in an x86 image. Unfortunately above blog post doesn't actually go into too much detail but mentions that their technique is based on a much older article found here.

ilmcuts