1
votes

I am writing an Visual C++ program in pure Win32 API. As per my understanding, I need to separately compile and generate executable for x86 and x64 architecture.

How do I combine them into single executable and emit the x64 at runtime? I have seen Sysinternals tools doing the same , but don't know how it is done programmatically.

Do I have to include my x64 version as a resource into x86 and then write to filesystem and do CreateProcess ?

Any pointers ?

1
In general, x86 applications run just fine on x64. The sysinternals tools however use drivers, which have to be built for the right kernel architecture - Bahbar
But the questions remains. How to do that internally incase executables are different. - Madhur Ahuja
Personally, I hate the way the sysinternals tools do this. They're creating and deleting files needlessly each time they run and you end up with twice as many entries in task manager (with one exe just sitting around waiting to delete the other one's binary). I don't see the point. It's not hard to make an installer that installs the right file on the machine, and for installer-free tools it's not hard to give people both exes in a zip and let them run the appropriate one (or have one run the other if they run the wrong one). - Leo Davidson

1 Answers

3
votes

Yes, they embed the operating specific driver as a resource. Here's a screenshot from Visual Studio after using File + Open + File to open their Handle.exe utility:

alt text

Not exactly sure what they are but it certainly looks like they cover Windows 9x, 32-bit and 64-bit. Next thing they'd do is use the resource API functions (FindResource, SizeofResource, LockResource) and WriteFile() the resource content to a file in a writable directory. Then load the driver with CreateService and StartService.

The main program is x86 so it runs on any version of Windows. Generating binaries at runtime isn't a very customer friendly thing to do btw, they (and their virus scanner) usually like to know what came from where.