Skip to content

Commit ba821c8

Browse files
committed
build(cmake): Add ReactOS ATL and PSEH compatibility layer (TheSuperHackers#2067)
Add ReactOS Active Template Library (ATL) support for MinGW-w64 builds, enabling ATL/COM functionality without MSVC dependencies. This provides the ATL headers needed for COM-based browser control integration. Components: - ReactOS ATL headers (v0.4.15) fetched from ReactOS project - ReactOS PSEH (exception handling) in C++-compatible dummy mode - ATL compatibility header with MinGW-specific macro definitions - PSEH compatibility header ensuring proper exception handling The implementation uses ReactOS PSEH in dummy mode (_USE_DUMMY_PSEH) because MinGW-w64's native PSEH uses GNU C nested functions which are incompatible with C++. This provides ATL functionality needed for: - CComPtr and CComBSTR smart pointers - ATL string conversion macros - COM interface implementations Files: - cmake/reactos-atl.cmake: ReactOS ATL integration - Dependencies/Utility/Utility/atl_compat.h: ATL compatibility layer - Dependencies/Utility/Utility/pseh_compat.h: PSEH compatibility layer - CMakeLists.txt: Include ReactOS ATL configuration
1 parent 1944392 commit ba821c8

4 files changed

Lines changed: 170 additions & 0 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ include(FetchContent)
4141
# MinGW-w64 specific configuration
4242
if(MINGW)
4343
include(cmake/mingw.cmake)
44+
include(cmake/reactos-atl.cmake)
4445
include(cmake/widl.cmake)
4546
endif()
4647

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// TheSuperHackers @build JohnsterID 05/01/2026 Add ATL compatibility layer for MinGW-w64
2+
/**
3+
* @file atl_compat.h
4+
* @brief ATL compatibility layer for MinGW-w64 with ReactOS ATL
5+
*
6+
* Provides compatibility definitions for using ReactOS ATL headers
7+
* with MinGW-w64 GCC compiler. Uses ReactOS PSEH in C++-compatible
8+
* dummy mode (_USE_DUMMY_PSEH) because MinGW-w64's PSEH uses GNU C
9+
* nested functions which are not valid in C++.
10+
*/
11+
12+
#pragma once
13+
14+
#ifdef __MINGW32__
15+
16+
// Include Windows types needed for ATL compatibility
17+
#include <wtypes.h>
18+
19+
// Include PSEH compatibility first (uses ReactOS PSEH in dummy mode)
20+
#include "pseh_compat.h"
21+
22+
// Define _ATL_IIDOF macro for ReactOS ATL (uses MinGW-w64's __uuidof)
23+
#ifndef _ATL_IIDOF
24+
#define _ATL_IIDOF(x) __uuidof(x)
25+
#endif
26+
27+
// Forward declare _Delegate function for COM aggregation support
28+
// ReactOS ATL's COM_INTERFACE_ENTRY_AGGREGATE macro uses _Delegate but doesn't define it
29+
// The actual function pointer will be defined after atlbase.h provides _ATL_CREATORARGFUNC
30+
extern "C" HRESULT WINAPI _ATL_DelegateQueryInterface(void* pv, REFIID riid, LPVOID* ppv, DWORD_PTR dw);
31+
32+
// Suppress additional warnings from ReactOS ATL headers
33+
#pragma GCC diagnostic push
34+
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
35+
#pragma GCC diagnostic ignored "-Wattributes"
36+
37+
// NOTE: ReactOS ATL compile definitions are set in cmake/reactos-atl.cmake:
38+
// - _ATL_CSTRING_EXPLICIT_CONSTRUCTORS
39+
// - _ATL_NO_DEBUG_CRT
40+
// - ATL_NO_ASSERT_ON_DESTROY_NONEXISTENT_WINDOW
41+
// - ATL_NO_DEFAULT_LIBS
42+
// These are applied via target_compile_definitions() on the reactos_atl target.
43+
// Any target linking to reactos_atl will automatically inherit these definitions.
44+
//
45+
// IMPORTANT: _ATL_NO_AUTOMATIC_NAMESPACE is NOT defined because the codebase
46+
// uses ATL types (CComModule, CComObject, CString, etc.) without namespace
47+
// qualification and relies on the automatic 'using namespace ATL;' from ATL headers.
48+
49+
// Define _Delegate implementation and macro now that ATL types are available
50+
inline HRESULT WINAPI _ATL_DelegateQueryInterface(void* pv, REFIID riid, LPVOID* ppv, DWORD_PTR dw)
51+
{
52+
IUnknown** ppunk = reinterpret_cast<IUnknown**>(reinterpret_cast<char*>(pv) + dw);
53+
if (*ppunk == NULL)
54+
return E_NOINTERFACE;
55+
return (*ppunk)->QueryInterface(riid, ppv);
56+
}
57+
58+
#ifndef _Delegate
59+
#define _Delegate ((ATL::_ATL_CREATORARGFUNC*)_ATL_DelegateQueryInterface)
60+
#endif
61+
62+
// Restore compiler warnings after ATL includes
63+
#define ATL_COMPAT_RESTORE_WARNINGS() \
64+
do { \
65+
_Pragma("GCC diagnostic pop") \
66+
PSEH_COMPAT_RESTORE_WARNINGS() \
67+
} while(0)
68+
69+
#else
70+
// Non-MinGW platforms don't need these workarounds
71+
#define ATL_COMPAT_RESTORE_WARNINGS()
72+
#endif // __MINGW32__
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// TheSuperHackers @build JohnsterID 05/01/2026 Add PSEH compatibility for MinGW-w64
2+
/**
3+
* @file pseh_compat.h
4+
* @brief PSEH compatibility for MinGW-w64 with ReactOS ATL
5+
*
6+
* ReactOS ATL headers include <pseh/pseh2.h>. This header ensures
7+
* that ReactOS PSEH is used in C++-compatible dummy mode (_USE_DUMMY_PSEH).
8+
* The cmake configuration (reactos-atl.cmake) adds ReactOS PSEH headers
9+
* to the include path before system headers, and defines _USE_DUMMY_PSEH.
10+
*/
11+
12+
#pragma once
13+
14+
#ifdef __MINGW32__
15+
16+
// Suppress PSEH-related warnings from ReactOS PSEH headers
17+
#pragma GCC diagnostic push
18+
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
19+
#pragma GCC diagnostic ignored "-Wattributes"
20+
#pragma GCC diagnostic ignored "-Wunused-variable"
21+
#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
22+
#pragma GCC diagnostic ignored "-Wunused-label"
23+
24+
// ReactOS PSEH headers will be included by ATL headers
25+
// No need to include them explicitly here
26+
27+
// Restore compiler warnings after PSEH includes
28+
#define PSEH_COMPAT_RESTORE_WARNINGS() \
29+
_Pragma("GCC diagnostic pop")
30+
31+
#else
32+
// Non-MinGW platforms use native SEH or don't need PSEH
33+
#define PSEH_COMPAT_RESTORE_WARNINGS()
34+
#endif // __MINGW32__

cmake/reactos-atl.cmake

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# TheSuperHackers @build JohnsterID 05/01/2026 Add ReactOS ATL and PSEH compatibility for MinGW
2+
# ReactOS ATL headers for MinGW-w64 builds
3+
# Provides ATL/COM support without MSVC dependencies
4+
# Uses ReactOS PSEH in C++-compatible dummy mode (_USE_DUMMY_PSEH)
5+
# because MinGW-w64's PSEH uses GNU C nested functions which don't work in C++
6+
7+
if(MINGW)
8+
message(STATUS "Setting up ReactOS ATL for MinGW-w64")
9+
10+
FetchContent_Declare(
11+
reactos_atl
12+
GIT_REPOSITORY https://github.com/reactos/reactos.git
13+
GIT_TAG 0.4.15-release
14+
GIT_SHALLOW TRUE
15+
GIT_PROGRESS TRUE
16+
SOURCE_SUBDIR sdk/lib/atl
17+
)
18+
19+
FetchContent_GetProperties(reactos_atl)
20+
if(NOT reactos_atl_POPULATED)
21+
FetchContent_Populate(reactos_atl)
22+
23+
# Create interface library for ReactOS ATL headers
24+
add_library(reactos_atl INTERFACE)
25+
26+
# Add ReactOS ATL and PSEH include directories with SYSTEM to suppress warnings
27+
# ReactOS PSEH must come BEFORE system includes to override MinGW's pseh2.h
28+
# (MinGW's pseh2.h uses GNU C nested functions which don't work in C++)
29+
# NOTE: Do NOT include ReactOS CRT headers - use MinGW-w64's CRT instead
30+
target_include_directories(reactos_atl SYSTEM INTERFACE
31+
"${reactos_atl_SOURCE_DIR}/sdk/lib/pseh/include"
32+
"${reactos_atl_SOURCE_DIR}/sdk/lib/atl"
33+
)
34+
35+
# COM support (_com_util::ConvertStringToBSTR and ConvertBSTRToString)
36+
# is provided by Dependencies/Utility/Utility/comsupp_compat.h as a
37+
# header-only implementation. No library needs to be built or linked.
38+
39+
# Add required ATL defines for MinGW compatibility
40+
# NOTE: Do NOT define _ATL_NO_AUTOMATIC_NAMESPACE
41+
# The codebase uses ATL types (CComModule, CComObject, CString, etc.)
42+
# without ATL:: qualification and relies on automatic 'using namespace ATL;'
43+
#
44+
# _USE_DUMMY_PSEH: Use ReactOS PSEH's C++-compatible "dummy" mode
45+
# which provides simple macros instead of GNU C nested functions
46+
target_compile_definitions(reactos_atl INTERFACE
47+
_ATL_CSTRING_EXPLICIT_CONSTRUCTORS
48+
_ATL_NO_DEBUG_CRT
49+
ATL_NO_ASSERT_ON_DESTROY_NONEXISTENT_WINDOW
50+
ATL_NO_DEFAULT_LIBS
51+
_USE_DUMMY_PSEH
52+
)
53+
54+
message(STATUS "ReactOS ATL headers: ${reactos_atl_SOURCE_DIR}/sdk/lib/atl")
55+
message(STATUS "ReactOS PSEH headers: ${reactos_atl_SOURCE_DIR}/sdk/lib/pseh/include")
56+
message(STATUS "COM support (comsupp): Header-only in Dependencies/Utility/Utility/comsupp_compat.h")
57+
message(STATUS "Using ReactOS PSEH in C++-compatible dummy mode (_USE_DUMMY_PSEH)")
58+
message(STATUS "Using MinGW-w64 CRT headers (NOT ReactOS CRT)")
59+
endif()
60+
else()
61+
# Create dummy target for non-MinGW builds
62+
add_library(reactos_atl INTERFACE)
63+
endif()

0 commit comments

Comments
 (0)