Skip to content

Commit d6ef811

Browse files
authored
Enable classic COM on mingw-w64 (#1215)
1 parent 3deb508 commit d6ef811

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

strings/base_macros.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@
5959
#define WINRT_IMPL_NOVTABLE
6060
#endif
6161

62+
#if defined(__clang__)
63+
#define WINRT_IMPL_HAS_DECLSPEC_UUID __has_declspec_attribute(uuid)
64+
#elif defined(_MSC_VER)
65+
#define WINRT_IMPL_HAS_DECLSPEC_UUID 1
66+
#else
67+
#define WINRT_IMPL_HAS_DECLSPEC_UUID 0
68+
#endif
69+
6270
#ifdef __IUnknown_INTERFACE_DEFINED__
6371
#define WINRT_IMPL_IUNKNOWN_DEFINED
6472
#else

strings/base_meta.h

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -120,27 +120,17 @@ namespace winrt::impl
120120
template <typename T>
121121
struct classic_com_guid_error
122122
{
123-
#ifdef __clang__
124-
#if !__has_declspec_attribute(uuid)
123+
#if !defined(__MINGW32__) && defined(__clang__) && !WINRT_IMPL_HAS_DECLSPEC_UUID
125124
static_assert(std::is_void_v<T> /* dependent_false */, "To use classic COM interfaces, you must compile with -fms-extensions.");
126-
#endif
127-
128-
#ifndef WINRT_IMPL_IUNKNOWN_DEFINED
125+
#elif !defined(WINRT_IMPL_IUNKNOWN_DEFINED)
129126
static_assert(std::is_void_v<T> /* dependent_false */, "To use classic COM interfaces, you must include <unknwn.h> before including C++/WinRT headers.");
130-
#endif
131127
#else // MSVC won't hit this struct, so we can safely assume everything that isn't Clang isn't supported
132128
static_assert(std::is_void_v<T> /* dependent_false */, "Classic COM interfaces are not supported with this compiler.");
133129
#endif
134130
};
135131

136132
template <typename T>
137-
#ifdef __clang__
138-
#if __has_declspec_attribute(uuid) && defined(WINRT_IMPL_IUNKNOWN_DEFINED)
139-
inline constexpr guid guid_v{ __uuidof(T) };
140-
#else
141-
inline constexpr guid guid_v = classic_com_guid_error<T>::value;
142-
#endif
143-
#elif defined(_MSC_VER)
133+
#if (defined(_MSC_VER) && !defined(__clang__)) || ((WINRT_IMPL_HAS_DECLSPEC_UUID || defined(__MINGW32__)) && defined(WINRT_IMPL_IUNKNOWN_DEFINED))
144134
inline constexpr guid guid_v{ __uuidof(T) };
145135
#else
146136
inline constexpr guid guid_v = classic_com_guid_error<T>::value;

0 commit comments

Comments
 (0)