簡體   English   中英

處理Winnt.h的奇怪的編譯錯誤

[英]Weird compile error dealing with Winnt.h

當試圖通過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 但是,我發現這有點太多了 - 我不認為需要在每個文件中包含所有這些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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM