Skip to content

Commit

Permalink
Enable classic COM on mingw-w64 (#1215)
Browse files Browse the repository at this point in the history
  • Loading branch information
alvinhochun authored Oct 24, 2022
1 parent 3deb508 commit d6ef811
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
8 changes: 8 additions & 0 deletions strings/base_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@
#define WINRT_IMPL_NOVTABLE
#endif

#if defined(__clang__)
#define WINRT_IMPL_HAS_DECLSPEC_UUID __has_declspec_attribute(uuid)
#elif defined(_MSC_VER)
#define WINRT_IMPL_HAS_DECLSPEC_UUID 1
#else
#define WINRT_IMPL_HAS_DECLSPEC_UUID 0
#endif

#ifdef __IUnknown_INTERFACE_DEFINED__
#define WINRT_IMPL_IUNKNOWN_DEFINED
#else
Expand Down
16 changes: 3 additions & 13 deletions strings/base_meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,27 +120,17 @@ namespace winrt::impl
template <typename T>
struct classic_com_guid_error
{
#ifdef __clang__
#if !__has_declspec_attribute(uuid)
#if !defined(__MINGW32__) && defined(__clang__) && !WINRT_IMPL_HAS_DECLSPEC_UUID
static_assert(std::is_void_v<T> /* dependent_false */, "To use classic COM interfaces, you must compile with -fms-extensions.");
#endif

#ifndef WINRT_IMPL_IUNKNOWN_DEFINED
#elif !defined(WINRT_IMPL_IUNKNOWN_DEFINED)
static_assert(std::is_void_v<T> /* dependent_false */, "To use classic COM interfaces, you must include <unknwn.h> before including C++/WinRT headers.");
#endif
#else // MSVC won't hit this struct, so we can safely assume everything that isn't Clang isn't supported
static_assert(std::is_void_v<T> /* dependent_false */, "Classic COM interfaces are not supported with this compiler.");
#endif
};

template <typename T>
#ifdef __clang__
#if __has_declspec_attribute(uuid) && defined(WINRT_IMPL_IUNKNOWN_DEFINED)
inline constexpr guid guid_v{ __uuidof(T) };
#else
inline constexpr guid guid_v = classic_com_guid_error<T>::value;
#endif
#elif defined(_MSC_VER)
#if (defined(_MSC_VER) && !defined(__clang__)) || ((WINRT_IMPL_HAS_DECLSPEC_UUID || defined(__MINGW32__)) && defined(WINRT_IMPL_IUNKNOWN_DEFINED))
inline constexpr guid guid_v{ __uuidof(T) };
#else
inline constexpr guid guid_v = classic_com_guid_error<T>::value;
Expand Down

0 comments on commit d6ef811

Please sign in to comment.