问题
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:
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:

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.
来源:https://stackoverflow.com/questions/4327228/combine-x86-and-x64-executables-in-single-executable-like-sysinternals-tools