2

Possible Duplicate:
Issue using Visual Studio 2010 compiled C++ DLL in Windows 2000

Similar to these questions:
 Can I use Visual Studio 2010's C++ compiler with Visual Studio 2008's C++ Runtime Library?
 Can VS2010 create native executable file working under Windows 2000?


I have C++ code that I'm compiling from the command line (using CL.EXE) using VS2010 (CL version 16.00.30319.0) on a WinXP machine, but I want the resulting native (x86) executable program to run on Win2000, WinXP, etc.

Older versions of CL (VC98, version 12.00.8186) do the job just fine, but the VS2010 version produces an executable that, when run on Win2000, results in a pop-up error:

foo.exe is not a valid Win32 application

The solution must be in the form of CL compiler or linker options, not VisualStudio settings or properties. I don't need any of the newer C++ language features, since the code is a few years old and written to be portable to other OSs, and I want only native code (x86, not .NET or CLI) executables.

(See http://david.tribble.com/src/crlf.cpp and http://david.tribble.com/src/detab.cpp for examples.)

I suppose I could keep using the older compiler (VS 9.0) on my new development environment (WinXP, and eventually Windows 7), but that seems like a less than ideal solution. Surely MS still provides a way to create native executables that are backward-compatible to older but still-extant Windows OSs?

Community
  • 1
  • 1
David R Tribble
  • 11,918
  • 5
  • 42
  • 52
  • @Billy: Good ol' Microsoft, a developer's best friend. – David R Tribble May 22 '11 at 17:11
  • I think support for Win2k also ended years ago... But since you are using 2010 it has inbuild support for building executables in VC9 configuration. – RedX May 22 '11 at 17:13
  • @RedX: VC9 support from the CL command line? – David R Tribble May 22 '11 at 17:15
  • if you are using MSBuild yes. Call MSbuild with `msbuild myProject.vcxproj /p:PlatformToolset=v90` You will have to have an VC9 version installed. See: http://msdn.microsoft.com/en-us/library/ee662426.aspx – RedX May 22 '11 at 17:29
  • No, they don't provide a way to compile code with version 10 of the tools that works with Windows 2000. The later versions of the CRT are incompatible with W2K. But as others have mentioned, you can use the VS 9.0 toolset from within VS 2010, as long as you have VS 2008 installed. Pretty simple to do, I compile a lot of code this way. Just change the settings in your project's properties. – Cody Gray - on strike May 22 '11 at 17:51

1 Answers1

2

Your error "foo.exe is not a valid Win32 application" can be fixed by using editbin to set the "Minimum OS version" field in the PE header to 0x0500 (Windows 2000).

EDITBIN /VERSION:5,0 foo.exe

You'll need an old version of editbin for this, or a third-party tool, since the new one "sanity checks" the version you give it.

After this, the application will load, but it may start complaining about missing functions in kernel32.dll.

Billy's question you linked to will take you farther down the rabbit hole than any sane programmer wants to go.

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
  • `EDITBIN /VERSION:5.0 /SUBSYSTEM:CONSOLE,5.0 foo.exe` works like you say, but the load fails because it can't find `DecodePointer` in `KERNEL32.DLL`. – David R Tribble May 26 '11 at 00:58