Suppose I have a program within the VC++ environment.
This program needs to modify itself in order to use certain code for a different operating system.
Let’s say, for example, that the program will modify the code to do A for Windows XP and for Windows 7 it will modify the code to do B.
The code for the action A located on the file "a.h" and the code for the action B located on the file "b.h".
Let’s say I have a function whose purpose is to detect the operating system.
If I wish to load just one of the files by detecting the OS, how can I include a file by such terms like activating a function?
You can’t do such a thing as you exposed it.
The
#includemechanism is handled by the precompiler, that runs at the moment of the compilation, not at runtime, thus, once your binary is compiled, the all the precompiler choices are already made and made their way into the final executable.To do a different thing depending on the version of Windows you have to include the code for both behaviors and choose the correct behavior at runtime, e.g. using the results of the
GetVersionExAPI.