Boost logo

Boost :

Subject: Re: [boost] Recommended way of dealing with windows.h in headers?
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2012-05-02 08:41:49

Mathias Gaunard wrote:
> What's the recommended way to deal with windows.h in Boost?
> I see a lot of libraries doing stuff like
> #if defined( BOOST_USE_WINDOWS_H )
> # include <windows.h>
> #endif
> namespace boost
> {
> namespace detail
> {
> #if !defined( BOOST_USE_WINDOWS_H )
> extern "C" void __stdcall Sleep( unsigned long ms );
> #endif

It sure seems useful to capture that in one place.

> So should libraries just declare all symbols themselves? But
> here the declaration is wrong, it misses __declspec(dllimport)
> for example when the runtime CRT is used, unnecessarily
> requiring import libraries.
> WINBASEAPI/WINADVAPI macros could be used to fix that.

Yet another reason to try to do things once.

At some point, the set of declarations in such a Boost header could become as unwieldy and large as windows.h! (OK, that's hyperbole, but the set of declarations can become sizeable over time.) We'll need our own equivalents of the various typedefs used by windows.h for the types that change with platform (for those that apply to the needed declarations). We'll also need to account for declarations that apply only to certain platforms. IOW, we'll have to recreate various parts of the preprocessor machinery in windows.h.

Despite the pain, those things argue for a common file (set of files) to proxy windows.h so things can be done/fixed correctly in one place.

Rob Stewart robert.stewart_at_[hidden]
Software Engineer using std::disclaimer;
Dev Tools & Components
Susquehanna International Group, LLP


IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.

Boost list run by bdawes at, gregod at, cpdaniel at, john at