- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在使用 Visual Studio 2012 在 Windows 7 x64 上执行一些测试。看起来 Microsoft 的工具链正在将 _WIN32_WINNT
设置为 0x602
(_WIN32_WINNT_WIN8
).运行我们的测试程序导致 The procedure entry point GetOverlappedResultEx could not be located in the dynamic link library KERNEL32.dll
:
我有两个问题。首先,出于病态的好奇,为什么 Microsoft 将 _WIN32_WINNT
设置为对执行环境无效的值?我能理解用户是否想要这样做,但微软不行,因为它会破坏一切 (q.v.)。
其次,我们如何将WINVER
或_WIN32_WINNT
设置为符号“This Platform”?在这种情况下,“此平台”是 Windows 7。当我在 Windows Vista 上测试时,它将是一个不同的平台。当我在 Windows 8 上测试时,它将是另一个平台。当我在 ARM 开发人员提示下针对 Windows Phone 和 Windows Store 进行测试时,它将是另一个平台。
这个问题很容易重现。这是步骤。我想任何拥有良好测试环境的人都已经完成了前八步。
然后:
hello_world.cpp
(这应该留下1个解决方案文件,1个项目文件,1个源文件)我可以发布 MCVE,这是一个空的源文件,以安抚一些人。这似乎是在浪费时间,因为问题出在工具链而不是源文件上。一个空的 main
真的对这个问题至关重要吗?无论文件中的内容如何,都将设置错误的 WINVER
和 _WIN32_WINNT
。
我知道错误的来源。我们的代码最近更改为更好地支持 Windows 8, Phone 8, Store 8, Server 2012, Windows 10, Phone 10, Store 10 and Windows Universal Platform .变化看起来像这样:
#if defined(CRYPTOPP_WIN32_AVAILABLE)
# if ((WINVER >= 0x0602 /*_WIN32_WINNT_WIN8*/) || (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/))
# include <synchapi.h>
# include <ioapiset.h>
# define USE_WINDOWS8_API
# endif
#endif
...
#if defined(USE_WINDOWS8_API)
BOOL result = GetOverlappedResultEx(GetHandle(), &m_overlapped, &m_lastResult, INFINITE, FALSE);
#else
BOOL result = GetOverlappedResult(GetHandle(), &m_overlapped, &m_lastResult, FALSE);
#endif
具有讽刺意味的是,我们首先添加了 USE_WINDOWS8_API
、额外的包含和对 GetOverlappedResultEx
的调用以安抚这些工具。他们提示不推荐使用的函数并导致脏编译。脏编译给用户带来了治理、C&A 和 ST&E 问题。
我审核了代码以确保我们没有无意或错误地设置值。我确认我们在一个地方执行此操作,并且代码路径未激活,因为 Microsoft 的工具链将值设置为 0x602
:
#ifdef CRYPTOPP_WIN32_AVAILABLE
# ifndef _WIN32_WINNT
# define _WIN32_WINNT 0x0400
# endif
#endif
这是一个相关的堆栈溢出问题:What is WINVER? ,但没有讨论如何设置为“本平台”。
这是微软关于这个主题的文档:Using the Windows Headers和 Modifying WINVER and _WIN32_WINNT .具有讽刺意味的是,他们并没有真正讨论问题或 Windows 10、Windows Phone 10、Windows Store 10 或 Windows 通用平台。
顺便说一句,GCC 有一个类似的-march=native
,它基本上提供了“这个平台”。
最佳答案
“此平台”隐含在平台工具集中。 VS 2012 使用默认为 _WIN32_WINNT=0x0602
(Windows 8) 的 Windows 8.0 SDK。 VS 2013/2015 使用默认为 _WIN32_WINNT=0x0603
(Windows 8.1) 的 Windows 8.1 SDK。如果您使用 VS 2015 和 Windows 10 SDK,它默认为 _WIN32_WINNT=0x0A00
(Windows 10)。
这主要是为了 Windows 应用商店/UWP 应用的利益,它们需要 _WIN32_WINNT
的最新值才能正确构建。对于 Windows 10,_WIN32_WINNT
值不会在构建之间更新,因此您可以配置要使用的并排 Windows 10 SDK。查看Visual C++ Team blog了解详情。
对于 Windows 桌面应用程序(又名经典 Win32),您应该在构建配置中明确设置您支持的操作系统版本。通常这是在 pch.h
或其他全局 header 中完成的,但也可以通过构建命令行/makefile/vcxproj 完成:
#include <WinSDKVer.h>
#define _WIN32_WINNT 0x0600 // Windows Vista SP2 or later
#include <SDKDDKVer.h>
或
#include <WinSDKVer.h>
#define _WIN32_WINNT 0x0601 // Windows 7 or later
#include <SDKDDKVer.h>
Windows 8.x SDK 可以面向 Windows Vista SP2、Windows 7、Windows 8.0、Windows 8.1 或更高版本。
If you need support for Windows XP SP3 or Windows Server 2003 SP2, then you have to use an alternative Platform Toolset setting which selects the Windows 7.1A SDK. See this post for some notes about the differences.
参见 Using the Windows Headers和 this blog article
Keep in mind that VS 2015 itself does not support targeting Windows 7 RTM, only Windows 7 Service Pack 1.
对于 GetOverlappedResultEx
的特定情况,我在我的代码中使用了以下模式,它支持为下层 Windows 7 和 UWP/Windows Store 构建。
HANDLE hEvent = CreateEventEx( nullptr, nullptr,
CREATE_EVENT_MANUAL_RESET, EVENT_MODIFY_STATE | SYNCHRONIZE );
...
// Read and verify header
OVERLAPPED request = {};
request.hEvent = hEvent;
bool wait = false;
if( !ReadFile( hFile, ..., &request ) )
{
DWORD error = GetLastError();
if ( error != ERROR_IO_PENDING )
return HRESULT_FROM_WIN32( error );
wait = true;
}
DWORD bytes;
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
BOOL result = GetOverlappedResultEx( hFile, &request, &bytes, INFINITE, FALSE );
#else
if ( wait )
(void)WaitForSingleObject( hEvent, INFINITE );
BOOL result = GetOverlappedResult( hFile, &request, &bytes, FALSE );
#endif
然后我为每个受支持的平台提供多个构建的静态库。请记住,WACK 工具会检查您的 EXE/DLL 导入和导出表,并将标记任何不受支持的 API。因此,您无法选择运行时,并且必须仅引用“Windows 8”构建中支持的 API。
关于windows - Visual Studio 在 Windows 7 上将 WINVER/_WIN32_WINNT 设置为 Windows 8?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37668692/
我想根据我使用的 visual studio 版本编译不同的东西,比如 #if VISUAL_STUDIO_VERSION > 2015 eventH?.Invoke(this, EventArgs.
在 Visual Studio 2010 中调试并将鼠标悬停在变量名称上时,我可以选择使用 3 种不同的内置可视化工具:文本、XML 和 HTML。 这是我所指的示例: 由于我越来越多地使用基于 JS
我将可视化编程语言理解为允许程序员在屏幕上操作图形(而不是文本)对象以构建功能的语言。 我在 C#、VB 等中看到的最接近的东西是 RAD 控件,但这只是组成 UI 和最简单的功能——甚至与语言本身无
我目前正在使用 Visual Studio 2015 来编程 ASP.NET Core 应用程序。我对安装 Visual Studio 2017 有以下疑问: 什么被认为是最佳实践和/或最干净的方法?
尝试从扩展和更新获取 Visual Studio 扩展时,出现以下错误:- 向 visualstudiogallery.msdn.microsoft.com/Services/VStudio/Exte
我已经开发了Windows服务,并且该服务正在我的帐户下在本地计算机上运行。当我尝试通过在Visual Studio 2008中将其作为一个过程附加该服务来调试该服务时,我得到“无法附加到该过程。 V
作为标准安装的一部分,Visual Studio Code 带有一个名为“Monokai Dimmed”的颜色主题。 有没有办法将它移植到 Visual Studio 2015?我检查了社区主题( h
Visual Studio Community Edition是否可以使用Visual Studio Online帐户上的存储库? 我一直为包含在Online帐户中的Visual Studio Onl
我正在使用文本可视化工具在 Visual Studio 中调试字符串变量。然而,似乎字符串中间的大部分不见了。这背后的原因是什么? 最佳答案 Visual Studio 中的 Text Visuali
我正在开始一个涉及使用多个 SDK 的新项目,包括: 英特尔凌动开发者 SDK 文本转语音 SDK(建议?) 某种网络摄像头和增强现实支持(建议?) 我目前有 2008,但我也可以安装 2010。是否
我想知道,如果我发送一个解决方案文件夹(它是用 visual studio C# 编写的),您可以在 visual studio for mac 中打开解决方案吗? 在visual studio 20
有没有办法在 Visual Studio Code 和 Visual Studio 中设置相同的快捷方式(而不必每次都手动更改它们)? 例如,我在 Visual Studio Code 中经常使用 A
我无法启用 实时可视化树 在 Visual Studio 2017 用于 UWP 应用程序 (C#)。这个工具在 VS2015 上工作,但在 VS2017 中从来没有为我工作过。它对我的 WPF 项目
我刚开始了解 Visual Studio Code。我想知道,我可以将 Visual Studio 替换为所有 .NET 开发相关的工作吗? 我可以节省 Visual Studio 许可的成本吗? V
我安装了具有有效许可证(Visual Studio 订阅)的 Visual Studio 2019 企业版(VS 2019 16.1.4),它运行良好。 突然之间,当我尝试打开项目或项目中的任何文件时
Visual Studio 2015 Pro 提供以下 错误 : error BC36716: Visual Basic 9.0 does not support implicit line cont
我正在我的 PC 中使用 .net Framework 2.0 和 Visual C#(Microsoft Visual Studio 2008)开发 Windows 应用程序。 完成我的项目后,我必
有什么方法可以在启动 VS 时禁用 VA X 并仅在需要时将其重新打开?因为它会导致一些滞后。我似乎在 VS 的选项或 VA 的选项中都找不到该选项。 最佳答案 持shift在 Visual Stud
我可以将 Visual Studio 命令提示符 与免费的 Visual C# Express 一起使用吗? Visual Studio 命令提示符 被引用 here : Run 'Visual St
这很容易成为 Visual Studio 历史上最烦人的“功能”之一,我不明白它为什么存在 -- 曾经 . 为什么 CodePlex 项目需要关心我使用的是什么版本的 Visual Studio? 在
我是一名优秀的程序员,十分优秀!