奇怪的编译错误处理WINNT.H [英] Weird compile error dealing with Winnt.h

查看:326
本文介绍了奇怪的编译错误处理WINNT.H的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当试图编译文件,包括WINNT.H通过WINDOWS.H,我得到以下错误:

 MyGl.cpp
.. \\微软的SDK \\ WINDOWS \\ v6.0a \\包括\\ WINNT.H(964):错误C2988:无法识别的模板声明/定义
.. \\微软的SDK \\ WINDOWS \\ v6.0a \\包括\\ WINNT.H(964):错误C2059:语法错误:'&'

他们指出,在WINNT.H以下行

 的externC ++//模板不能宣称有C联动
模板< typename的T,为size_t N'GT;
CHAR(* RtlpNumberOf(UNALIGNED T(&安培;)[N]))[N];的#define RTL_NUMBER_OF_V2(A)(sizeof的(* RtlpNumberOf(A)))

什么回事任何想法?

我的编译器:

微软(R)32位C / C ++优化编译器版本为15.00.21022.08的80x86
版权所有(C)微软公司。保留所有权利。


解决方案

有至少两种方法可以做到这一点。首先是简单地包括 WINDOWS.H 在所有文件的顶部。然后包括 WINNT.H 只有当你需要它。不过,我觉得这有点过分 - 我没有看到,包括每一个文件中的所有本咕的必要性

我做的,这是在我的C / C ++头文件的最高层(第一件事)。

 的#ifndef __wtypes_h__
#包括LT&;&wtypes.h GT;
#万一的#ifndef __WINDEF_
#包括LT&;&WINDEF.H GT;
#万一

这会得到你的数据类型,定义和基本的Windows API的。您可能还需要添加以下内容:

 的#ifndef _WINUSER_
#包括LT&;&WINUSER.H GT;
#万一的#ifndef __RPC_H__
#包括LT&;&rpc.h GT;
#万一

WINNT是一个有点特殊的动物 - 不包括,如果包括上述文件为你工作。如果你需要它,包括它在 wtypes.h 和`WINDEF.H

如果这不起作用,那么请检查您的包含路径和predefined宏来看看那些可能会破坏你的身材。

问候,Foredecker

When trying to compile a file that include winnt.h via windows.h, I get the following error:

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 : '&'

They point to the following lines in 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)))

Any ideas for what's going on?

My compiler:

Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.21022.08 for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

解决方案

There are at least two ways to do this. The first is to simply include windows.h at the top of all your files. Then include winnt.h only if you need it. However, I find this a bit too much - I don't see the need of including all this goo in every single file.

What I do is this at the very top (first thing) in my C/C++ header files.

#ifndef __wtypes_h__
#include <wtypes.h>
#endif

#ifndef __WINDEF_
#include <windef.h>
#endif

This will get you you the data types, defines, and fundamental Windows API's. You may also need to add the following:

#ifndef _WINUSER_
#include <winuser.h>
#endif

#ifndef __RPC_H__
#include <rpc.h>
#endif

WinNT is a bit of a special animal - don't include it if including the above files works for you. If you do need it, include it after wtypes.h and `windef.h'

If this doesn't work, then check your include paths and predefined macros to see if those might be breaking your build.

Regards, Foredecker

这篇关于奇怪的编译错误处理WINNT.H的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆