Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS2010 Lots of errors when including standard libraries

When I include a standard library into my VS2010 project, I get a TON of errors like these (these errors were from adding in shellapi.h). I get similar errors when adding in something like Windows.h or Wininet.h or anything like that.

1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\ShellAPI.h(56): error C2065: 'HDROP' : undeclared identifier
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\ShellAPI.h(56): 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\ShellAPI.h(59): error C2144: syntax error : 'int' should be preceded by ';'
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\ShellAPI.h(59): 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\ShellAPI.h(59): error C2146: syntax error : missing ';' before identifier 'STDAPICALLTYPE'
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\ShellAPI.h(59): 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\ShellAPI.h(59): error C2146: syntax error : missing ';' before identifier 'DragQueryFileA'
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\ShellAPI.h(59): 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\ShellAPI.h(59): error C2065: 'HDROP' : undeclared identifier
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\ShellAPI.h(59): error C2146: syntax error : missing ')' before identifier 'hDrop'
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\ShellAPI.h(59): 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\ShellAPI.h(59): error C2059: syntax error : ')'
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\ShellAPI.h(61): error C2144: syntax error : 'int' should be preceded by ';'
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\ShellAPI.h(61): 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\ShellAPI.h(61): error C2086: 'int EXTERN_C' : redefinition

I'm sure this is just something to do with a project setting, but I have no idea what setting I need to change. Where should I begin?

UPDATE

The solution was to make sure that windows.h was loaded first. I did not know it was dependent on that. For future reference, where should I have looked to see that dependency?

like image 842
Jake Wilson Avatar asked Jun 01 '10 22:06

Jake Wilson


2 Answers

I got these exact same errors when adding

#include <shellapi.h>

to one of my files. I solved the problem by adding

#include <windows.h>

directly before it.

(You've got to love - or rather, hate - Windows headers that don't #include the headers that they themselves require. If I did that in my own code I'd get yelled at by my superiors!)

like image 83
aldo Avatar answered Dec 01 '22 01:12

aldo


This happens when one of your includes is broken, then you include a standard header, because your syntax error directly carries on. For example, if you forget a semi, then include another header, that header will report syntax errors. For this reason, you should always include "clean" headers like system headers first, then own-defined headers.

like image 43
Puppy Avatar answered Dec 01 '22 02:12

Puppy