Visual C ++应用程序不能在Windows 7上运行

时间:2017-06-09 12:27:39

标签: c++ visual-studio visual-c++ windows-7 windows-10

我正在使用Visual Studio Community 2015,我编写了一些简单的Win32演示应用程序,它应该从Internet下载文件并执行两个HTTP GET请求。

我使用InternetOpenAInternetConnectAHttpOpenRequestAURLDownloadToFile等功能。

我在设置中只更改了平台工具集 Visual Studio 2013(v120),我的targetver.h文件如下所示:

#pragma once

// Including SDKDDKVer.h defines the highest available Windows platform.
// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.

#include <WinSDKVer.h>

#define WINVER 0x0600
#define _WIN32_WINNT 0x0600 

#include <SDKDDKVer.h>

但是,它在我的Windows 10计算机上运行,​​但它不能在Windows 7上运行。它说:缺少MSVCR120.dll文件。我可以安装适当的C ++ Redistributables,但这不是我需要的解决方案。

编译时是否需要包含其他选项以便我可以避免此错误?

2 个答案:

答案 0 :(得分:2)

To avoid your application needing a separate runtime DLL, in the project settings, look under:

C/C++ > Code Generation > Runtime Library

and choose multi-threaded, rather than multi-threaded DLL.

You do not need to change the platform toolset.

答案 1 :(得分:0)

In my project, that I compile with VS 2017 and want to run all the way down to Vista, I do the same as you, but without the first #include <WinSDKVer.h>. I just set the _WIN32_WINNT macro to 0x0600 and so far it's working fine.

I target the Windows 8.1 SDK, and use MFC, if that helps.

I've used dependency walker in the past to diagnose dll dependencies. Hopefully it's something silly like the 32-bit or 64-bit runtimes being missing.

As keith recommended in his answer, you can also try static linking the vc runtime (/MT[d] under C++/Code generation/Runtime Library) so that it doesn't need to load the runtime as a dll. Note that this is not the recommended option, since the VC runtime cannot be patched by Windows Update if it's burned into your executible.