Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Weird compile error dealing with Winnt.h

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.
like image 471
Frank Krueger Avatar asked Nov 02 '08 18:11

Frank Krueger


1 Answers

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

like image 99
Foredecker Avatar answered Sep 29 '22 06:09

Foredecker