C Program Written in VS2012 Works w/ Win7/8/2008R2/2012, but not 2003/XP/32bit?

后端 未结 3 1435
野的像风
野的像风 2021-02-08 15:16

I have to start by saying that I am very much a programming noob. I do not understand all the compiler options or nuances of the IDE, not by a longshot. But I am trying to teach

相关标签:
3条回答
  • 2021-02-08 15:37

    VS2012 originally shipped without supporting XP/2003. The updated CRT and runtime support libraries are using too many Windows api functions that are not available on those operating systems. This created quite a stir among its customers, to put it mildly, and they re-engineered the libraries to dynamically bind to these functions and limp along it they are missing. This was made available in Update 1, you'll need to use Project + Properties, General, Platform Toolset = v110_xp to build programs that use those libraries.

    Note how it changes a linker setting, the important one, Linker > System > Minimum Required Version = "5.01". Which ensures that the executable file is marked to be compatible with the XP sub-system version. You'll also build against SDK version 7.1, the last one that is still compatible with XP.

    When you use the default toolset (v110) then you target sub-system 6.00 and SDK version 8. Version 6.00 was the last major kernel revision, started with Vista.

    A brief overview of the new api functions being used to give you a (very rough) idea what is missing in the XP version:

    • FlsAlloc, FlsFree, FlsGetValue, FlsSetValue : safe thread-local storage
    • InitializeCriticalSectionEx, CreateSemaphoreEx : safety
    • SetThreadStackGuarantee : stability
    • CreateThreadPoolTimer, SetThreadPoolTimer, WaitForThreadPoolTimerCallbacks, CloseThreadPoolTimer : cheaper timers
    • CreateThreadPoolWait, SetThreadPoolWait, CloseThreadPoolWait : cheaper waits?
    • FlushProcessWriteBuffers, GetCurrentProcessorNumber, GetLogicalProcessorInformation : threading
    • FreeLibraryWhenCallbackReturns : stability?
    • CreateSymbolicLink : functionality
    • InitOnceExecuteOnce : unknown
    • SetDefaultDllDirectories : unknown
    • EnumLocalesEx, CompareStringEx, GetDateFormatEx, GetLocalInfoEx, GetTimeFormatEx, GetUserDefaultLocaleName, IsValidLocaleName, LCMapStringEx : better locale support
    0 讨论(0)
  • 2021-02-08 15:44

    I figured it out myself. (But thank you Hans for steering me in the right direction.) For some reason, even with Update 1 and even after setting my toolset to v110_xp, and setting the minimum required version to 5.01 in the Linker options, the resulting dumpbin app.exe /headers still reports a minimum operating system version of 6.0.

    So I simply ran

    editbin.exe app.exe /SUBSYSTEM:CONSOLE,5.01 /OSVERSION:5.1
    

    And the executable now runs just fine on older operating systems. I'm thinking there still might be a little bit of a bug somewhere in Visual Studio.

    0 讨论(0)
  • 2021-02-08 15:47

    The MSVC Team Blog says that when using MSBuild or DEVENV from the command-line with the v110_xp platform toolset, no other changes are necessary. This information is incorrect/incomplete. The /SUBSYSTEM linker argument and associated "Minimum Required Version" must also be set appropriately.

    The MSDN documentation for /ENTRY states that, if the /SUBSYSTEM argument is not specified that the SUBSYSTEM and ENTRY POINT are determined automatically. My hunch is that when this happens, the SUBSYSTEM's "Minimum Required Version" argument is also automatically overridden.

    The v110_xp toolset automatically specifies the SUBSYSTEM's MRV ("5.1" (WindowsXP)) but not the SUBSYSTEM. As such, the MRV will be overridden, for example, by the linker to "6.0". Running the application will then cause WindowsXP to show the error message stating that the application "is not a valid Win32 application."

    0 讨论(0)
提交回复
热议问题