简体   繁体   English

Visual Studio 2010 Win32 App无法在Windows XP上启动

[英]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 1.它应该只包含一个exe文件,没有安装程序或外部DLL。
2. It should be small 2.应该小
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) 3.它应该可以在任何Windows(Win32)平台上运行(至少在Windows XP上),而无需对Windows安装进行任何修改(不依赖于.NET,JVM,MFC或Visual Studio可再发行组件)
4. It should have a simple (dialog based) UI 4.它应该有一个简单的(基于对话框的)UI

I decided to do it as a simple Win32 Application in C (C++) and using only the standard win32 api, no fancy stuff. 我决定将其作为C(C ++)中的简单Win32应用程序进行,并且仅使用标准的win32 api,没有花哨的东西。 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. 我在64位Windows 7上使用Visual Studio 2010创建了该项目,并将运行库从多线程DLL更改为仅多线程。 I thought this would produce the most Windows-compatible application possible. 我认为这将产生与Windows兼容的应用程序。

The compiled application works fine on my Windows 7, but I cannot get it to start on any Windows XP PC. 编译后的应用程序可以在Windows 7上正常运行,但无法在任何Windows XP PC上启动它。 I have tried both on Windows XP SP2 and SP3. 我在Windows XP SP2和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. 奇怪的是,我在活动管理器中没有收到任何错误消息,也没有恶意程序,双击exe文件时什么也没发生。 And there is no DrWatson log produced. 并且没有产生DrWatson日志。

I have checked the Target Machine in project settings and it is MachineX86. 我已经在项目设置中检查了目标计算机,它是MachineX86。

I have googled a lot on the problem, and one tip was to modify targetver.h, which I have done without result. 我已经在这个问题上搜索了很多,一个提示是修改targetver.h,但我没有结果。 This is what my targetver.h looks like right now: 这就是我的targetver.h现在的样子:

#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. 我也尝试过依赖项遍历器,但是它只显示并加载名为DWMAPI.DLL的延迟加载的DLL并显示错误,该DLL似乎是Vista DLL。 And also warnings for two other delay-loaded DLL's, MPR.DLL and SHLWAPI.DLL. 并且还警告其他两个延迟加载的DLL,MPR.DLL和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. 我的目标是能够编译一个可以在XP计算机上运行的exe,而无需对其进行任何修改。

I solved the problem. 我解决了问题。 When I said I did it as plain Win32 without fancy stuff it wasn't completely true. 当我说我像没有花哨的东西的普通Win32那样做时,那不是完全正确的。 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): 在现代操作系统上运行时,我不希望出现XP之前的外观和感觉,因此我在stdafx.h中添加了以下几行(遵循我在网上找到的提示):

#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) 但是,在对MSDN文章进行了更多阅读之后,我发现这些行必须在包含windows.h之前,所以我将其移动,现在它可以工作了(包括经典和xp样式)

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. 所以问题似乎是我在windows.h包含的错误一侧更改为ComCtl32的版本6,但是我仍然不知道为什么在删除这些行时它不起作用。 Could Windows be caching the manifest in some way? Windows可以某种方式缓存清单吗?

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

Try creating a program that is statically linked to the C Runtime library. 尝试创建一个静态链接到C运行时库的程序。

Do the following in your project in your solution: Go to Properties | 在解决方案的项目中执行以下操作: Configuration | 配置| C/C++ | C / C ++ | Code Generation | 代码生成| Runtime Library. 运行时库。

Release: Change /MD to /MT, Multithreaded. 发行:将/ MD更改为/ MT,多线程。 Debug: Change /MDd to /MTd, Debug Multithreaded. 调试:将/ MDd更改为/ MTd,调试多线程。

If you want to keep using dynamic linking, then copy the MSVC++ runtime file into your XP machine, as suggested by @dbrank(). 如果要继续使用动态链接,请按照@dbrank()的建议将MSVC ++运行时文件复制到XP计算机中。 However, you stated in your original post that you wanted a standalone .exe with no extra files to copy. 但是,您在原始帖子中说过,您想要一个没有复制其他文件的独立.exe。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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