当尝试通过 windows.h 编译包含 winnt.h 的文件时,出现以下错误:
MyGl.cpp
..\microsoft sdks\windows\v6.0a\include\winnt.h(964) : error C2988: unrecognizable template declaration/definition
..\microsoft sdks\windows\v6.0a\include\winnt.h(964) : error C2059: syntax error : '&'
他们指向 Winnt.h 中的以下行
extern "C++" // templates cannot be declared to have 'C' linkage
template <typename T, size_t N>
char (*RtlpNumberOf( UNALIGNED T (&)[N] ))[N];
#define RTL_NUMBER_OF_V2(A) (sizeof(*RtlpNumberOf(A)))
对发生的事情有什么想法吗?
我的编译器:
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.21022.08 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.
至少有两种方法可以做到这一点。第一个是简单地包括windows.h
在所有文件的顶部。然后包括winnt.h
仅当您需要时。然而,我发现这有点太多了——我不认为有必要在每个文件中都包含所有这些内容。
我所做的就是在我的 C/C++ 头文件的最顶部(第一件事)。
#ifndef __wtypes_h__
#include <wtypes.h>
#endif
#ifndef __WINDEF_
#include <windef.h>
#endif
这将为您提供数据类型、定义和基本的 Windows API。您可能还需要添加以下内容:
#ifndef _WINUSER_
#include <winuser.h>
#endif
#ifndef __RPC_H__
#include <rpc.h>
#endif
WinNT 是一种特殊的动物 - 如果包含上述文件适合您,则不要包含它。如果您确实需要它,请将其包含在后面wtypes.h
和`windef.h'
如果这不起作用,请检查您的包含路径和预定义宏,看看它们是否可能会破坏您的构建。
问候, 福德克
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)