Include winnt.h in my project - c++

I am doing a small personal project involving printing out info about a PE file.
I have read that most of the pe structure is already defined in winnt.h header.
Upon including the winnt.h, and compiling the project i get the following error:
#error : "No Target Architecture"
I tried putting a define x86, it might have fixed the architecture problem, but there are even more compilation problems.
For example:
1>c:\program files (x86)\windows kits\8.0\include\um\winnt.h(363): error C2146: syntax error : missing ';' before identifier 'WCHAR'
1>c:\program files (x86)\windows kits\8.0\include\um\winnt.h(363): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\windows kits\8.0\include\um\winnt.h(367): error C2143: syntax error : missing ';' before '*'
1>c:\program files (x86)\windows kits\8.0\include\um\winnt.h(367): error C2040: 'PWSTR' : 'CONST' differs in levels of indirection from 'WCHAR *'

check Compiler->Enable Microsoft extensions in Project options or use -Ze flag if you're compiling from the command line.

Related

Compile errors of Eigen's unsupported/CXX11/Tensor module

My project uses Eigen-3.3-beta. I can build my project in visual studio 2015 community which includes <Eigen/Core>. But after I include <unsupported\Eigen\CXX11\Tensor>, I got strange compile errors like these:
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\minwinbase.h(46): error C3646: 'nLength': unknown override specifier
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\minwinbase.h(46): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\minwinbase.h(47): error C3646: 'lpSecurityDescriptor': unknown override specifier
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\minwinbase.h(47): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\minwinbase.h(48): error C3646: 'bInheritHandle': unknown override specifier
......
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\minwinbase.h(295): fatal error C1003: error count exceeds 100; stopping compilation
It seems that my project works properly with Eigen-3.3-beta's normal part except unsupported module. What's more, with unsupported module included, types introduced by GLEW (e.g. GLfloat) cannot be resolved. Did I do something wrong?
It seems this stems from the include of in <unsupported\Eigen\CXX11\Tensor>.
I solved it with help from this thread (Compile error in 'winbase.h' ) and just exchanged line 38 in <unsupported\Eigen\CXX11\Tensor> from #include <winbase.h> with #include <windows.h>.
Edit: This seems to be the way it was fixed in the lasted version in the repository.

Get massive compile error whenever windows.h is included, my environment is visual studio 2013 in win 7

I have a CPP file Log.cpp which has one line code:
#include "windows.h"
When I compile it, massive syntax errors display:
1>------ Build started: Project: topx, Configuration: Debug Win32 ------
1> Log.cpp
1>c:\program files (x86)\windows kits\8.1\include\um\winbase.h(936): error C2065: 'hMem' : undeclared identifier
1>c:\program files (x86)\windows kits\8.1\include\um\winbase.h(936): error C2065: 'dwBytes' : undeclared identifier
1>c:\program files (x86)\windows kits\8.1\include\um\winbase.h(938): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\windows kits\8.1\include\um\winbase.h(938): error C2491: '_Ret_reallocated_bytes_' : definition of dllimport data not allowed
1>c:\program files (x86)\windows kits\8.1\include\um\winbase.h(938): error C2078: too many initializers
1>c:\program files (x86)\windows kits\8.1\include\um\winbase.h(938): error C2146: syntax error : missing ';' before identifier 'HGLOBAL'
1>c:\program files (x86)\windows kits\8.1\include\um\winbase.h(938): error C2143: syntax error : missing ';' before '__stdcall'
1>c:\program files (x86)\windows kits\8.1\include\um\winbase.h(938): error C2377: 'HGLOBAL' : redefinition; typedef cannot be overloaded with any other symbol
1> c:\program files (x86)\windows kits\8.0\include\shared\minwindef.h(211) : see declaration of 'HGLOBAL'
1>c:\program files (x86)\windows kits\8.1\include\um\winbase.h(940): error C2146: syntax error : missing ')' before identifier 'hMem'
1>c:\program files (x86)\windows kits\8.1\include\um\winbase.h(940): warning C4229: anachronism used : modifiers on data are ignored
1>c:\program files (x86)\windows kits\8.1\include\um\winbase.h(940): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\windows kits\8.1\include\um\winbase.h(943): error C2059: syntax error : ')'
....
....
But all is OK when I compile it under windows 8, what is the problem?
Change from:
C:\Program Files (x86)\Windows Kits\8.0\Include\shared
to
C:\Program Files (x86)\Windows Kits\8.1\Include\shared
in "Additional include directories" of project resolve this problem, but I do not know why.

"Triangle" with VS2012?

There is a triangular mesh generator (Shewchuk, CMU), "Triangle", that are recommended by people due to its lightweight. It is written in C. However I cannot use it in my VS2012 C++ project. I am compiling it using x64 platform. I am on Windows 7 64-bit.
Basically, I compile the triangle.c as the makefile described. So, a triangle.o is generated. I then
added triangle.o as additional dependencies in my solution,
added triangle.c and triangle.h in my project .
changed triangle.c in C/C++ precompiled header option, to "not using precompiled header"
Then I got tons of errors like this:
1>C:\Program Files (x86)\Windows Kits\8.0\Include\um\winnt.h(430): error C2143: syntax error : missing ';' before '*'
1>C:\Program Files (x86)\Windows Kits\8.0\Include\um\winnt.h(430): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files (x86)\Windows Kits\8.0\Include\um\winnt.h(497): error C2143: syntax error : missing ';' before '*'
1>C:\Program Files (x86)\Windows Kits\8.0\Include\um\winnt.h(497): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files (x86)\Windows Kits\8.0\Include\um\winnt.h(498): error C2143: syntax error : missing ';' before '*'
1>C:\Program Files (x86)\Windows Kits\8.0\Include\um\winnt.h(498): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files (x86)\Windows Kits\8.0\Include\um\winnt.h(2517): warning C4391: 'SHORT _InterlockedIncrement16(volatile SHORT *)' : incorrect return type for intrinsic function, expected 'short'
I am just wondering, is there anyway to make the triangular mesh generator work with VS2012 C++ project? If so, what is the right way to set it up on VS2012 C++ x64?
You might want to have a look at this: Compilation errors of a simple C++ project in VS 2012.RC 4
disable pre-compiled headers, and delete the pch file from the intermediate directory.
This initially didn't work for me, so I tried moving #include at the top of the file, before all other includes, and this worked for me.

Build Error in the "refclock.h" header file, a part of Windows platform SDK

I am building a VC++ solution & using Win& SDK & Win8 SDK (including these paths in LIB & INCLUDE settings of VS2008).
But I am getting the following build error in refclock.h header file.
I don't understand how can we get the error in a standard MSFT header file. Can anyone kindly help me in getting this fixed?
c:\program files\microsoft sdks\windows\v7.0\samples\multimedia\directshow\baseclasses\refclock.h(80) : error C2061: syntax error : identifier 'CAMSchedule'
2>c:\program files\microsoft sdks\windows\v7.0\samples\multimedia\directshow\baseclasses\refclock.h(139) : error C2143: syntax error : missing ';' before '*'
2>c:\program files\microsoft sdks\windows\v7.0\samples\multimedia\directshow\baseclasses\refclock.h(139) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
2>c:\program files\microsoft sdks\windows\v7.0\samples\multimedia\directshow\baseclasses\refclock.h(139) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
2>c:\program files\microsoft sdks\windows\v7.0\samples\multimedia\directshow\baseclasses\refclock.h(139) : warning C4183: 'GetSchedule': missing return type; assumed to be a member function returning 'int'
2>c:\program files\microsoft sdks\windows\v7.0\samples\multimedia\directshow\baseclasses\refclock.h(178) : error C2143: syntax error : missing ';' before '*'
2>c:\program files\microsoft sdks\windows\v7.0\samples\multimedia\directshow\baseclasses\refclock.h(178) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
2>c:\program files\microsoft sdks\windows\v7.0\samples\multimedia\directshow\baseclasses\refclock.h(178) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
2>c:\program files\microsoft sdks\windows\v7.0\samples\multimedia\directshow\baseclasses\refclock.h(139) : error C2065: 'm_pSchedule' : undeclared identifier
2>c:\program files\microsoft sdks\windows\v7.0\samples\multimedia\directshow\baseclasses\refclock.h(166) : error C2065: 'm_pSchedule' : undeclared identifier
2>c:\program files\microsoft sdks\windows\v7.0\samples\multimedia\directshow\baseclasses\refclock.h(166) : error C2227: left of '->GetEvent' must point to class/struct/union/generic type
It's caused by an error in the refclock.h header and the order your include directories are specified in Visual Studio.
You need to have the BaseClasses directory (Samples/Multimedia/DirectShow) before the SDK include directory, since they both have a schedule.h file and refclock.h uses <> not "" for the include.

syntax error : missing ';' before identifier 'PVOID64' when compiling winnt.h

I've recently got the source-code on a application. When im trying to build the solution, I get an error in all parts where winnt.h is included. The error codes differs a bit, but they always point to these lines in winnt.h:
typedef void *PVOID;
typedef void * POINTER_64 PVOID64;
and
struct {
DWORD crc;
BYTE rgbReserved[14];
} CRC;
So, what could be the cause of this? winnt.h is a standard header and has not been modified. Does it has something to do with me using VS 2010, or me using 64-bit windows? or is it some sort of configuration which is needed?
EDIT:
Here's the exact error-codes:
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h(290): error C2146: syntax error : missing ';' before identifier 'PVOID64'
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h(290): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h(8992): error C2146: syntax error : missing ';' before identifier 'Buffer'
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h(8992): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h(8992): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h(11525): error C2059: syntax error : 'constant'
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h(11525): error C2238: unexpected token(s) preceding ';'
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h(11556): error C2059: syntax error : 'constant'
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h(11556): error C2238: unexpected token(s) preceding ';'
You need to include windows.h rather than winnt.h. When you include windows.h it will, in turn, include winnt.h. You need to do it this way for the necessary macros to be in place that are needed to compile winnt.h.
In this case, POINTER_64 is defined in BaseTsd.h like this:
#define POINTER_64 __ptr64
But if you include winnt.h before including windows.h then POINTER_64 is not defined.
If you are using DirectX SDK, try changing the VC++ Directories for include and lib to be searched last.
It looks like your configuration of the Windows SDK is invalid.
This error is caused by the fact that the compiler is unable to recognize the 'POINTER_64' statement.
You may workaround this problem by replacing 'POINTER_64' with '__ptr64'.
I had the same issue recently. Then I've reinstalled the latest version of the Windows SDK and this fixed the problem.
UPDATE
#David Heffernan, correctly points to the fact that one should include windows.h instead of winnt.h
Try to remove DirectX SDK if you have one.
Here bug is accepted:
http://connect.microsoft.com/VisualStudio/feedback/details/508204/vc10-0-errors-while-compiling-winnt-h
Corrected manually syntax in winnt.h :
typedef void * POINTER_64 PVOID64; => typedef void * POINTER_64, * PVOID64;
If you are using librdkafka, you will get this error whenever "Windows.h" included.
I fixed it by rename "librdkafka/include/basetsd.h" to a different name, or access
this library header via sub path!
I think the author of this library made this file to deal with OS platform compatibility. But with the same file name "basetsd.h" as Windows Core, it just confusing Visual Studio.