Is there any way to compile an EXE file, so that it will run natively in both x86 and x64? Something开发者_开发技巧 like: compile both codebases and pack them into a single executable.
I know .NET code could run in "any cpu" mode, but it is not what I want.
A 32-bit executable will run natively on 32-bit and x64 Windows machines. The only way you're going to get x64 execution within a 32-bit PE file is by using an undocumented gate, which I highly doubt anyone uses in practice because it's highly version dependent (and undocumented).
Then again you make it so the 32-bit binary will execute a 64-bit version of the binary and exit if it detects a 64-bit CPU...
You could take the Process Explorer approach. In your 32-bit binary embed the 64-bit binary as a resource. If the 32-bit binary is launched on a 64-bit machine, extract the 64-bit binary and launch that.
精彩评论