The CLR has special loader support for the /ANYCPU option.
If you really want to do this for native, the best way to do it is to:
- Build your binary for both 32- and 64-bit
- As part of building the 32-bit binary, include the 64-bit binary as a resource
- On 32-bit machines, just run the 32-bit binary
- On 64-bit machines, when the 32-bit binary runs, unpack the 64-bit binary resource, write it to disk, and run it from there
This is how the Sysinternals tools work (download Process Explorer onto a 64-bit machine and run it: you'll see that it writes procexp64.exe to disk and then runs it from there). It's a hack, but it works.