Visual C++ 找不到“Windows 类型”,如 PVOID、DWORD、ULONG 等

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6943865/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 08:38:26  来源:igfitidea点击:

Visual C++ can't find "Windows types" like PVOID, DWORD, ULONG, etc

windowsvisual-c++

提问by dcpomero

Windows can't seem to find any of these types, and I'm completely at a loss for what to do. The things I've found on MSDN seem to suggest that they're included by default, but they haven't worked in Native programs or CLR programs.

Windows 似乎无法找到任何这些类型,我完全不知道该怎么做。我在 MSDN 上找到的东西似乎表明它们默认包含在内,但它们在本机程序或 CLR 程序中不起作用。

The specific errors I'm getting are:

我得到的具体错误是:

"<Project Name>.cpp(10): error C2065: 'PVOID' : undeclared identifier

"<Project Name>.cpp(10): error C2065: 'PVOID' : undeclared identifier

"<Project Name>.cpp(10): error C2146: syntax error : missing ';' before identifier 'varname'

"<Project Name>.cpp(10): error C2146: syntax error : missing ';' before identifier 'varname'

"<Project Name>.cpp(10): error C2065: 'varname' : undeclared identifier

"<Project Name>.cpp(10): error C2065: 'varname' : undeclared identifier

How can I make Visual C++ recognize these types?

如何让 Visual C++ 识别这些类型?

回答by James Johnston

You will need to include windows.h. Add this line at the top of your source file:

您将需要包括windows.h. 在源文件的顶部添加这一行:

#include <windows.h>

回答by Ned Batchelder

You need to include a header file to define these types. Double-check the documentation or samples that you got the type names from to see what headers to include.

您需要包含一个头文件来定义这些类型。仔细检查您从中获得类型名称的文档或示例,以查看要包含哪些标头。

回答by Puppy

You have to include the Windows headers. The Windows headers are included in the default auto-generated projects- most of them. If you started an empty project instead, you won't have them included by default.

您必须包含 Windows 标头。Windows 标头包含在默认自动生成的项目中 - 其中大部分。如果您改为启动一个空项目,则默认情况下不会包含它们。