Question

I have Visual Studio 2012 update 4 and the Windows SDK 7.1.

I select the "Visual Studio 2012 - Windows XP (v110_xp)" toolkit and the include directories change to use $(WindowsSdkDir_71A).

No errors are given during compile (e.g. it successfully finds winres.h), but when I try to run the exe on Windows XP SP3, it still errors: "test.exe is not a valid Win32 application."

For testing, it's just a C++ hello world.

#include <cstdio>

int main(void)
{
    printf("Hello, World!\r\n");
    return 0;
}

How can I use Visual Studio 2012 to compile for XP?

What should I check to get this working?

How can I test compile on the command line? I'm currently testing on the command line with this, which still gives the invalid win32 error:

"C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\cl.exe" /EHsc /MT /I"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Include" /I"C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include" main.cpp /link /LIBPATH:"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib" /LIBPATH:"C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\lib" 

Update: It works if I use these instructions for the command line: http://blogs.msdn.com/b/vcblog/archive/2012/10/08/10357555.aspx

If I put these settings into my system environment variables, I can also get msbuild and visual studio to compile successfully, but this is not ideal.

Was it helpful?

Solution

The setting that needed to be changed was Project Properties -> Configuration Properties -> Linker -> System -> SubSystem

This needs to be set to CONSOLE or WINDOWS for the appropriate project type, but is not set by default for an "empty project", even if console vs GUI is set elsewhere and it appears to work (e.g. WinMain is the entry point, console does not appear, etc). Minimum Required Version also needs to be 5.01, but judging by the command line help on link.exe, I don't think this does anything unless subsystem is set.

Things to check:

  • Visual Studio 2012 is Update 1 or higher
  • SDK 7.1 is installed and 7.1A exists
  • the "Visual Studio 2012 - Windows XP (v110_xp)" toolkit is used
  • the preprocessor definitions contains _USING_V110_SDK71_
  • the VC++ Directories contain $(WindowsSdkDir_71A)bin, $(WindowsSdkDir_71A)include and $(WindowsSdkDir_71A)lib
  • linker subsystem is console or windows, with minimum required version 5.01
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top