Boost logo

Boost :

Subject: [boost] Recommended way of dealing with windows.h in headers?
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2012-05-02 07:31:29


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

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.

There is also the file
<boost/detail/win/basic_types.hpp>

that contains a few of the types, but it doesn't seem to be used that
much except by other files in detail/win, and then again they don't
re-use WINAPI and other macros. It also seems to be lacking the
WINBASEAPI/WINADVAPI macros.

Also, why couldn't headers simply include <windef.h> then <winbase.h>?
Does that cause problems too?


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk