I fixed my own problem, just thought I'd post my solution. Also, I'm
not an expert with exe binaries, so I apologize if any information is
incorrect or misleading.
The exe header was the problem. Windows executables (aka "PE files")
contain header sections, one of which is the "Optional Header." In
the Optional Header section, MajorOperatingSystemVersion and
MajorSubsystemVersion indicates which level of OS the exe will run on.
VS 2005 sets these values to 4 and VS 2008 sets these values to 5.
Using a PE editor (I used CFF Explorer), simply change those values
from 5 to 4 (on the VS 2008 compiled exe). When I did this and
executed the exe on NT4, it ran beautifully!
A few notes:
1) VS 2008 C++ compiler officially no longer supports Win9x, ME, WinNT
("Breaking Changes" http://msdn2.microsoft.com/en-us/library/bb531344.aspx)
2) My issue is probably an issue also with Win9x, ME, not just WinNT
(I have no Win9x boxes to test with).
3) The file alignment of the exe is 1024 bytes, not 4096 bytes like VS
2005 produces. I'm not sure if this is a problem, but it does not
appear to be for me. If this is a problem, pad the exe file with
zeroes until the file size is divisble by 4096 bytes using a hex
editor. Also you may need to update the "FileAlignment" value in the
Optional Header of the exe from 0x200 (512) to 0x1000 (4096).
4) Of course, if your exe calls newer functions that don't exist in
the NT DLLs, you will run into other issues (but at least the exe will
execute and tell you what's wrong).
5) As of yet, I don't know how to compile the code to automatically
set the correct values. It's possible there a #define or #pragma that
will do this, but I haven't researched it yet.
6) The PE header also contains a checksum value. Of course, since the
exe header is modified, the checksum value is almost 100% likely
incorrect. It doesn't appear that Windows cares, since the exe runs
just fine.
On to VS 2008!
P.S. There is similar thread here: http://www.msfn.org/board/Visual-Studio-2008-Windows-9x-t112283.html
("Visual Studio 2008 and Windows 9x")
On Mar 31, 3:31 pm, jerichar99 <jericha...@gmail.com> wrote:
> This is an unusual question, but hopefully someone can point me in the
> right direction. I apologize if this is wrong group to post this, but
> I can't locate aVS2008group (please let me know if there is a more
> appropriate group).
> I have a legacy C++ application that my company runs onNT4.0(yes,
> we still use it!). Currently I compile the code on my development
> machine (Win2k3) usingVS2005 and copy the exe to theNTmachines.
> That works just fine. When I compile the code usingVS2008and copy
> the exe toNT, a dialog box says "[exe name] is not a valid WindowsNT
> application."
> A few things I've checked:
> 1) Yes, the exe file was copied correctly. I've copied it several
> times and the same result.
> 2) The exe runs just fine on the development machine (Win2k3).
> 3) The exe's byte size is _not_ divisible by 4,096 (image section
> size), unlike the VS2005 exe image. I'm not sure if it matters (but I
> did try padding the exe with zeroes using a hex editor, but same
> error).
> Is there a linker option creates an image for legacy OSes (NT, 95,
> 98)?
> UpgradingNT4.0is not an option, unfortunately, since the licenses
> would be very costly and serve us no purpose.