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

Conversation

mabrarov
Copy link
Contributor

Avoid inclusion of rarely used Windows SDK headers which can cause conflict with other code using Windows SDK.

Refer to issue #155 for example of conflict with Boost.Asio caused by Winsock 1.x header (winsock.h) being included through windows.h in Boost.Stacktrace and conflicting with Winsock 2 header (winsock2.h). Refer to chriskohlhoff/asio#1441 for details.

…nflict with other code using Windows SDK.

Signed-off-by: Marat Abrarov <abrarov@gmail.com>
#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.

#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.

@apolukhin apolukhin merged commit 39afcef into boostorg:develop Apr 16, 2024
1 check passed
@apolukhin
Copy link
Member

Many thanks for the workaround!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants