Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduction of included Windows SDK headers #157

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions include/boost/stacktrace/detail/frame_msvc.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,17 @@
#include <boost/core/noncopyable.hpp>
#include <boost/stacktrace/detail/to_dec_array.hpp>
#include <boost/stacktrace/detail/to_hex_array.hpp>

#ifdef WIN32_LEAN_AND_MEAN
#include <windows.h>
#else
// Prevent inclusion of extra Windows SDK headers which can cause conflict
// with other code using Windows SDK
#define WIN32_LEAN_AND_MEAN
Copy link
Contributor Author

@mabrarov mabrarov Mar 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The downside of this solution is following:

If both conditions are met:

  1. Boost.Stacktrace user's compilation unit includes windows.h header file after inclusion of Boost.Stacktrace header files.
  2. Boost.Stacktrace user's compilation unit doesn't have WIN32_LEAN_AND_MEAN macro defined (IMHO, it is a rare case).

then the compilation unit loses "extra" Windows SDK headers (cderr.h, dde.h, ddeml.h, dlgs.h, lzexpand.h, mmsystem.h, nb30.h, shellapi.h, winperf.h, winsock.h, wincrypt.h, winefs.h, winscard.h, winspool.h, ole.h or ole2.h, commdlg.h), because windows.h header is not going to be included one more time into the same compilation unit, i.e. this solution potentially can cause regression for the users of Boost.Stacktrace, but that regression can be solved by including "extra" Windows SDK header files explicitly.

#include <windows.h>
#undef WIN32_LEAN_AND_MEAN
#endif

#include "dbgeng.h"
Copy link
Contributor Author

@mabrarov mabrarov Mar 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even dbgeng.h includes windows.h:

dbgeng.h -> objbase.h -> rpc.h:

#if !defined( RPC_NO_WINDOWS_H ) && !defined( MAC ) && !defined( _MAC ) && !defined(_KRPCENV_)
/*
 * Pull in WINDOWS.H if necessary
 */
#ifndef _INC_WINDOWS
#include <windows.h>
#endif /* _INC_WINDOWS */
#endif // RPC_NO_WINDOWS_H

So it's hard to include only needed Windows SDK headers without inclusion of windows.h.


#include <mutex>
Expand Down