windows.h include error

116 views
Skip to first unread message

Nico Weber

unread,
May 19, 2011, 2:40:33 PM5/19/11
to Chromium-dev
Hi,

is there a rule that <windows.h> needs to be included before any other
win32 api headers? If I move it below the shellapi.h include in
base/file_util_unittest.cc I get several compile errors, which
suggests that the win32 api include order has some implicit rules, but
there are some files that include win32 api headers before they
include windows.h.

The reason I'm asking is that we have a script that sorts include
files (tools/sort-headers.py), and I'd like to fix that script so that
it doesn't produce output that doesn't compile. Is "put windows.h
first in the include block it's in" ok? Are there other implicit
ordering dependencies for windows headers?

Thanks,
Nico

Ben Goodger (Google)

unread,
May 19, 2011, 2:43:31 PM5/19/11
to [email protected], Chromium-dev
My experience has been that I do have to include windows.h first. I am not aware of any other dependency issues aside from this.

-Ben


--
Chromium Developers mailing list: [email protected]
View archives, change email options, or unsubscribe:
   http://groups.google.com/a/chromium.org/group/chromium-dev

Darin Fisher

unread,
May 19, 2011, 2:50:24 PM5/19/11
Ditto.  It is annoying.
-Darin

Peter Kasting

unread,
May 19, 2011, 3:18:08 PM5/19/11
to [email protected], Chromium-dev
On Thu, May 19, 2011 at 12:40 PM, Nico Weber <[email protected]> wrote:
is there a rule that <windows.h> needs to be included before any other
win32 api headers?

Yes, Microsoft has made this rule and their headers rely on it.

Are there other implicit
ordering dependencies for windows headers?

Yes, there are various other cases like ATL headers that need atlbase.h (IIRC) included first, or needing to include some of the "secure string API" headers in different orders in order to avoid compiler warnings.  We've documented some of these in comments next to the relevant headers.

It would probably be annoying to make the script aware of all the different cases because I don't know that some of them (e.g. that last one) are easily describable.

PK 

Nico Weber

unread,
May 19, 2011, 3:19:46 PM5/19/11
to Peter Kasting, Chromium-dev

Bummer. The only way is to add these on a case-by-case basis then I guess? :-/

Another dependency apparently is that <unknwn.h> needs to come before
<intshcut.h> (http://codereview.chromium.org/7048007/diff/8001/chrome/browser/importer/importer_unittest.cc
, http://build.chromium.org/p/tryserver.chromium/builders/win/builds/32426/steps/compile/logs/stdio#error1
)

> PK

Evan Martin

unread,
May 19, 2011, 3:23:22 PM5/19/11
to Nico Weber, Peter Kasting, Chromium-dev
On Thu, May 19, 2011 at 1:19 PM, Nico Weber <[email protected]> wrote:
>> Yes, there are various other cases like ATL headers that need atlbase.h
>> (IIRC) included first, or needing to include some of the "secure string API"
>> headers in different orders in order to avoid compiler warnings.  We've
>> documented some of these in comments next to the relevant headers.
>> It would probably be annoying to make the script aware of all the different
>> cases because I don't know that some of them (e.g. that last one) are easily
>> describable.
>
> Bummer. The only way is to add these on a case-by-case basis then I guess? :-/
>
> Another dependency apparently is that <unknwn.h> needs to come before
> <intshcut.h> (http://codereview.chromium.org/7048007/diff/8001/chrome/browser/importer/importer_unittest.cc
> , http://build.chromium.org/p/tryserver.chromium/builders/win/builds/32426/steps/compile/logs/stdio#error1
> )

FWIW, this is why sort-headers.py prompts you before committing to a
reordering -- the comment in that file (that the header order is
important) will show up in the diff. You can then just edit these
exceptional files by hand if necessary.

Reply all
Reply to author
Forward
0 new messages