加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 处理Winnt.h的奇怪的编译错误

发布时间:2020-12-16 10:15:15 所属栏目:百科 来源:网络整理
导读:当试图通过 windows.h编译包含winnt.h的文件时,我收到以下错误: MyGl.cpp..microsoft sdkswindowsv6.0aincludewinnt.h(964) : error C2988: unrecognizable template declaration/definition..microsoft sdkswindowsv6.0aincludewinnt.h(964) : e
当试图通过 windows.h编译包含winnt.h的文件时,我收到以下错误:

MyGl.cpp
..microsoft sdkswindowsv6.0aincludewinnt.h(964) : error C2988: unrecognizable template declaration/definition
..microsoft sdkswindowsv6.0aincludewinnt.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.但是,我发现这有点太多了 – 我不认为需要在每个文件中包含所有这些goo.

我所做的就是在我的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’之后包含它.

如果这不起作用,请检查包含路径和预定义宏,看看这些是否会破坏您的构建.

此致,Foredecker

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读