简体   繁体   中英

Visual Studio 2010 Win32 App won't start on Windows XP

I had to write an simple application with some specific requirements:
1. It should consist of just one exe-file, no installer or external DLL's
2. It should be small
3. It should run on any Windows (Win32) platform (at least on Windows XP), without making any modifications to the Windows installation (no dependencies to .NET, JVM, MFC or Visual Studio redistributables)
4. It should have a simple (dialog based) UI

I decided to do it as a simple Win32 Application in C (C++) and using only the standard win32 api, no fancy stuff. I created the project with Visual Studio 2010 on 64 bit Windows 7 and changed Runtime Library from Multi-threaded DLL to just Multi-threaded. I thought this would produce the most Windows-compatible application possible.

The compiled application works fine on my Windows 7, but I cannot get it to start on any Windows XP PC. I have tried both on Windows XP SP2 and SP3. The strange thing is that I don't get any error message and no rogue processes in the Activity Manager, nothing happens when I double-click the exe-file. And there is no DrWatson log produced.

I have checked the Target Machine in project settings and it is MachineX86.

I have googled a lot on the problem, and one tip was to modify targetver.h, which I have done without result. This is what my targetver.h looks like right now:

#include <WinSDKVer.h>
#define _WIN32_WINNT      _WIN32_WINNT_WINXP
#include <SDKDDKVer.h>

I have also tried dependency walker, but it only shows and error for a delay-loaded DLL called DWMAPI.DLL, which seems to be a Vista DLL. And also warnings for two other delay-loaded DLL's, MPR.DLL and SHLWAPI.DLL. But since they are delay-loaded and I don't think I use anything in them it shouldn't matter (googling on it shows that these warnings should be disregarded).

My goal is to be able to compile an exe that will work on the XP-machines without making any modification to them.

I solved the problem. When I said I did it as plain Win32 without fancy stuff it wasn't completely true. I didn't want the boaring pre-XP look and feel when running on modern operating systems, so I added these lines to stdafx.h (following a tip I found on the net):

#define ISOLATION_AWARE_ENABLED 1
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")

The reason I didn't mention this was that I had already tried to remove these lines, but it still didn't work (and I still can't understand why it didn't work when I removed those lines, I tried it more than once).

But after more reading on MSDN articles I found that these lines needs to be before the include of windows.h so I move it and now it works (both with classic and xp style)

So the problem seems to be that I changed to version 6 of ComCtl32 on the wrong side of the include of windows.h, but I still don't know why it didn't work when I removed those lines. Could Windows be caching the manifest in some way?

也许您在XP计算机上需要此: MSVC 2010运行时

Try creating a program that is statically linked to the C Runtime library.

Do the following in your project in your solution: Go to Properties | Configuration | C/C++ | Code Generation | Runtime Library.

Release: Change /MD to /MT, Multithreaded. Debug: Change /MDd to /MTd, Debug Multithreaded.

If you want to keep using dynamic linking, then copy the MSVC++ runtime file into your XP machine, as suggested by @dbrank(). However, you stated in your original post that you wanted a standalone .exe with no extra files to copy.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM