diff --git a/cppwinrt/code_writers.h b/cppwinrt/code_writers.h index 2e9c458b5..dbdec7b11 100644 --- a/cppwinrt/code_writers.h +++ b/cppwinrt/code_writers.h @@ -203,9 +203,20 @@ namespace cppwinrt return { w, write_close_namespace }; } + [[nodiscard]] static finish_with wrap_impl_namespace_without_export(writer& w) + { + auto format = R"(extern "C++" namespace winrt::impl +{ +)"; + + w.write(format); + + return { w, write_close_namespace }; + } + [[nodiscard]] static finish_with wrap_std_namespace(writer& w) { - w.write(R"(WINRT_EXPORT namespace std + w.write(R"(extern "C++" namespace std { )"); diff --git a/cppwinrt/file_writers.h b/cppwinrt/file_writers.h index 6f9b4db5d..397785fe5 100644 --- a/cppwinrt/file_writers.h +++ b/cppwinrt/file_writers.h @@ -44,6 +44,11 @@ namespace cppwinrt { auto wrap_file_guard = wrap_open_file_guard(w, "BASE"); + if (settings.modules) + { + w.write("#ifndef WINRT_CONSUME_MODULE\n"); + } + { // In module builds, generated projection headers must be "module-aware": // When `WINRT_MODULE` is defined (inside a module interface unit), suppress textual includes so the @@ -85,6 +90,11 @@ namespace cppwinrt w.write(strings::base_coroutine_threadpool); w.write(strings::base_natvis); w.write(strings::base_version); + + if (settings.modules) + { + w.write("#endif\n"); + } } w.flush_to_file(settings.output_folder + "winrt/base.h"); } @@ -142,7 +152,7 @@ namespace cppwinrt w.write_each(members.contracts); } { - auto wrap_impl = wrap_impl_namespace(w); + auto wrap_impl = wrap_impl_namespace_without_export(w); w.write_each(members.interfaces, "interface_category"); w.write_each(members.classes, "class_category"); w.write_each(members.enums, "enum_category"); @@ -165,9 +175,12 @@ namespace cppwinrt w.write_each(members.classes); w.write_each(members.interfaces); w.write_each(members.delegates); - w.write_each(members.interfaces); w.write_each(members.structs); } + { + auto wrap_impl = wrap_impl_namespace(w); + w.write_each(members.interfaces); + } if (settings.modules) { @@ -319,66 +332,38 @@ namespace cppwinrt #undef GetCurrentTime #endif +// Include in advance so that all of numerics's dependencies can be in the global module fragment +#include +#include +#if __has_include() && __has_include() +#include +#endif + export module winrt.base; // Module dependencies: // - std -// - winrt.numerics (re-exported when available) import std; -export import winrt.numerics; - -#if __has_include() -#define WINRT_IMPL_NUMERICS -#endif - -#include "winrt/base.h" -)"); - w.flush_to_file(settings.output_folder + "winrt/winrt.base.ixx"); - } - - static void write_numerics_ixx() - { - // Emits $(out)\winrt\winrt.numerics.ixx (export module winrt.numerics;) - // pulls in large, legacy headers that are hard to control and can trigger module - // diagnostics when textually included in a module purview. - // If the header does not exist, then the module exports nothing. To speed up module scanning, modules - // can't be controlled by preprocessor directives. Therefore, winrt.base cannot conditionally import it. - // In header builds we preserve the historical behavior (base headers include it), but in module builds we - // centralize it in this single module and have `winrt.base` re-export it. - // MSVC warns (C5244) when encountering textual includes inside a module purview; suppress for this file. - writer w; - write_preamble(w); - write_module_global_fragment(w); - - w.write(R"( -export module winrt.numerics; - -// Module dependencies: -// - (none) - -#if __has_include() -#ifdef _MSC_VER -#pragma warning(push) +// An MSVC warning whose cause cannot be analyzed +// warning C5244: '#include ' in the purview of module 'winrt.base' appears erroneous. Consider moving that directive before the module declaration, or replace the textual inclusion with 'import ;'. #pragma warning(disable : 5244) -#endif -#include +#if __has_include() #define _WINDOWS_NUMERICS_NAMESPACE_ winrt::Windows::Foundation::Numerics -#define _WINDOWS_NUMERICS_BEGIN_NAMESPACE_ export extern "C++" namespace winrt::Windows::Foundation::Numerics +#define _WINDOWS_NUMERICS_BEGIN_NAMESPACE_ export extern "C++" namespace _WINDOWS_NUMERICS_NAMESPACE_ #define _WINDOWS_NUMERICS_END_NAMESPACE_ #include #undef _WINDOWS_NUMERICS_NAMESPACE_ #undef _WINDOWS_NUMERICS_BEGIN_NAMESPACE_ #undef _WINDOWS_NUMERICS_END_NAMESPACE_ -#ifdef _MSC_VER -#pragma warning(pop) -#endif #endif + +#include "winrt/base.h" )"); - w.flush_to_file(settings.output_folder + "winrt/winrt.numerics.ixx"); + w.flush_to_file(settings.output_folder + "winrt/winrt.base.ixx"); } static void write_namespace_ixx(std::string_view const& ns, std::vector const& imports) @@ -581,7 +566,7 @@ export import winrt.base; w.type_namespace = ns; { - auto wrap_impl = wrap_impl_namespace(w); + auto wrap_impl = wrap_impl_namespace_without_export(w); w.write_each(members.interfaces); w.param_names = true; w.write_each(members.delegates); diff --git a/cppwinrt/main.cpp b/cppwinrt/main.cpp index 9f2e4403b..8695e10ca 100644 --- a/cppwinrt/main.cpp +++ b/cppwinrt/main.cpp @@ -622,7 +622,6 @@ R"( local Local ^%WinDir^%\System32\WinMetadata folder if (settings.modules) { - write_numerics_ixx(); write_base_ixx(); } diff --git a/cppwinrt/type_writers.h b/cppwinrt/type_writers.h index bb56c5724..182007701 100644 --- a/cppwinrt/type_writers.h +++ b/cppwinrt/type_writers.h @@ -334,13 +334,7 @@ namespace cppwinrt { if (ns == "Windows.Foundation.Numerics") { - if (name == "Matrix3x2") { name = "float3x2"; } - else if (name == "Matrix4x4") { name = "float4x4"; } - else if (name == "Plane") { name = "plane"; } - else if (name == "Quaternion") { name = "quaternion"; } - else if (name == "Vector2") { name = "float2"; } - else if (name == "Vector3") { name = "float3"; } - else if (name == "Vector4") { name = "float4"; } + transform_special_numeric_type(name); write("winrt::@::%", ns, name); } diff --git a/strings/base_abi.h b/strings/base_abi.h index 4b7b8f77f..7a5b3550b 100644 --- a/strings/base_abi.h +++ b/strings/base_abi.h @@ -1,5 +1,5 @@ -WINRT_EXPORT namespace winrt::impl +extern "C++" namespace winrt::impl { template <> struct abi { @@ -11,7 +11,7 @@ WINRT_EXPORT namespace winrt::impl }; }; - using unknown_abi = abi_t; + WINRT_EXPORT using unknown_abi = abi_t; template <> struct abi { @@ -23,7 +23,7 @@ WINRT_EXPORT namespace winrt::impl }; }; - using inspectable_abi = abi_t; + WINRT_EXPORT using inspectable_abi = abi_t; template <> struct abi { @@ -33,14 +33,14 @@ WINRT_EXPORT namespace winrt::impl }; }; - struct WINRT_IMPL_ABI_DECL IAgileObject : unknown_abi {}; + WINRT_EXPORT struct WINRT_IMPL_ABI_DECL IAgileObject : unknown_abi {}; - struct WINRT_IMPL_ABI_DECL IAgileReference : unknown_abi + WINRT_EXPORT struct WINRT_IMPL_ABI_DECL IAgileReference : unknown_abi { virtual std::int32_t __stdcall Resolve(guid const& id, void** object) noexcept = 0; }; - struct WINRT_IMPL_ABI_DECL IMarshal : unknown_abi + WINRT_EXPORT struct WINRT_IMPL_ABI_DECL IMarshal : unknown_abi { virtual std::int32_t __stdcall GetUnmarshalClass(guid const& riid, void* pv, std::uint32_t dwDestContext, void* pvDestContext, std::uint32_t mshlflags, guid* pCid) noexcept = 0; virtual std::int32_t __stdcall GetMarshalSizeMax(guid const& riid, void* pv, std::uint32_t dwDestContext, void* pvDestContext, std::uint32_t mshlflags, std::uint32_t* pSize) noexcept = 0; @@ -50,20 +50,20 @@ WINRT_EXPORT namespace winrt::impl virtual std::int32_t __stdcall DisconnectObject(std::uint32_t dwReserved) noexcept = 0; }; - struct WINRT_IMPL_ABI_DECL IGlobalInterfaceTable : unknown_abi + WINRT_EXPORT struct WINRT_IMPL_ABI_DECL IGlobalInterfaceTable : unknown_abi { virtual std::int32_t __stdcall RegisterInterfaceInGlobal(void* object, guid const& iid, std::uint32_t* cookie) noexcept = 0; virtual std::int32_t __stdcall RevokeInterfaceFromGlobal(std::uint32_t cookie) noexcept = 0; virtual std::int32_t __stdcall GetInterfaceFromGlobal(std::uint32_t cookie, guid const& iid, void** object) noexcept = 0; }; - struct WINRT_IMPL_ABI_DECL IStaticLifetime : inspectable_abi + WINRT_EXPORT struct WINRT_IMPL_ABI_DECL IStaticLifetime : inspectable_abi { virtual std::int32_t __stdcall unused() noexcept = 0; virtual std::int32_t __stdcall GetCollection(void** value) noexcept = 0; }; - struct WINRT_IMPL_ABI_DECL IStaticLifetimeCollection : inspectable_abi + WINRT_EXPORT struct WINRT_IMPL_ABI_DECL IStaticLifetimeCollection : inspectable_abi { virtual std::int32_t __stdcall Lookup(void*, void**) noexcept = 0; virtual std::int32_t __stdcall unused() noexcept = 0; @@ -74,23 +74,23 @@ WINRT_EXPORT namespace winrt::impl virtual std::int32_t __stdcall unused4() noexcept = 0; }; - struct WINRT_IMPL_ABI_DECL IWeakReference : unknown_abi + WINRT_EXPORT struct WINRT_IMPL_ABI_DECL IWeakReference : unknown_abi { virtual std::int32_t __stdcall Resolve(guid const& iid, void** objectReference) noexcept = 0; }; - struct WINRT_IMPL_ABI_DECL IWeakReferenceSource : unknown_abi + WINRT_EXPORT struct WINRT_IMPL_ABI_DECL IWeakReferenceSource : unknown_abi { virtual std::int32_t __stdcall GetWeakReference(IWeakReference** weakReference) noexcept = 0; }; - struct WINRT_IMPL_ABI_DECL IRestrictedErrorInfo : unknown_abi + WINRT_EXPORT struct WINRT_IMPL_ABI_DECL IRestrictedErrorInfo : unknown_abi { virtual std::int32_t __stdcall GetErrorDetails(bstr* description, std::int32_t* error, bstr* restrictedDescription, bstr* capabilitySid) noexcept = 0; virtual std::int32_t __stdcall GetReference(bstr* reference) noexcept = 0; }; - struct WINRT_IMPL_ABI_DECL IErrorInfo : unknown_abi + WINRT_EXPORT struct WINRT_IMPL_ABI_DECL IErrorInfo : unknown_abi { virtual std::int32_t __stdcall GetGUID(guid* value) noexcept = 0; virtual std::int32_t __stdcall GetSource(bstr* value) noexcept = 0; @@ -99,7 +99,7 @@ WINRT_EXPORT namespace winrt::impl virtual std::int32_t __stdcall GetHelpContext(std::uint32_t* value) noexcept = 0; }; - struct WINRT_IMPL_ABI_DECL ILanguageExceptionErrorInfo2 : unknown_abi + WINRT_EXPORT struct WINRT_IMPL_ABI_DECL ILanguageExceptionErrorInfo2 : unknown_abi { virtual std::int32_t __stdcall GetLanguageException(void** exception) noexcept = 0; virtual std::int32_t __stdcall GetPreviousLanguageExceptionErrorInfo(ILanguageExceptionErrorInfo2** previous) noexcept = 0; @@ -107,14 +107,14 @@ WINRT_EXPORT namespace winrt::impl virtual std::int32_t __stdcall GetPropagationContextHead(ILanguageExceptionErrorInfo2** head) noexcept = 0; }; - struct ICallbackWithNoReentrancyToApplicationSTA; + WINRT_EXPORT struct ICallbackWithNoReentrancyToApplicationSTA; - struct WINRT_IMPL_ABI_DECL IContextCallback : unknown_abi + WINRT_EXPORT struct WINRT_IMPL_ABI_DECL IContextCallback : unknown_abi { virtual std::int32_t __stdcall ContextCallback(std::int32_t(__stdcall* callback)(com_callback_args*), com_callback_args* args, guid const& iid, int method, void* reserved) noexcept = 0; }; - struct WINRT_IMPL_ABI_DECL IServerSecurity : unknown_abi + WINRT_EXPORT struct WINRT_IMPL_ABI_DECL IServerSecurity : unknown_abi { virtual std::int32_t __stdcall QueryBlanket(std::uint32_t*, std::uint32_t*, wchar_t**, std::uint32_t*, std::uint32_t*, void**, std::uint32_t*) noexcept = 0; virtual std::int32_t __stdcall ImpersonateClient() noexcept = 0; @@ -122,12 +122,12 @@ WINRT_EXPORT namespace winrt::impl virtual std::int32_t __stdcall IsImpersonating() noexcept = 0; }; - struct WINRT_IMPL_ABI_DECL IBufferByteAccess : unknown_abi + WINRT_EXPORT struct WINRT_IMPL_ABI_DECL IBufferByteAccess : unknown_abi { virtual std::int32_t __stdcall Buffer(std::uint8_t** value) noexcept = 0; }; - struct WINRT_IMPL_ABI_DECL IMemoryBufferByteAccess : unknown_abi + WINRT_EXPORT struct WINRT_IMPL_ABI_DECL IMemoryBufferByteAccess : unknown_abi { virtual std::int32_t __stdcall GetBuffer(std::uint8_t** value, std::uint32_t* capacity) noexcept = 0; }; diff --git a/strings/base_activation.h b/strings/base_activation.h index ec4a3e82a..1cee4c306 100644 --- a/strings/base_activation.h +++ b/strings/base_activation.h @@ -1,7 +1,7 @@ -WINRT_EXPORT namespace winrt::impl +extern "C++" namespace winrt::impl { - struct library_traits + WINRT_EXPORT struct library_traits { using type = void*; @@ -16,9 +16,9 @@ WINRT_EXPORT namespace winrt::impl } }; - using library_handle = handle_type; + WINRT_EXPORT using library_handle = handle_type; - template + WINRT_EXPORT template WINRT_IMPL_NOINLINE hresult get_runtime_activation_factory_impl(param::hstring const& name, winrt::guid const& guid, void** result) noexcept { if (winrt_activation_handler) @@ -96,16 +96,16 @@ WINRT_EXPORT namespace winrt::impl return hr; } - template + WINRT_EXPORT template hresult get_runtime_activation_factory(param::hstring const& name, void** result) noexcept { return get_runtime_activation_factory_impl>(name, guid_of(), result); } } -WINRT_EXPORT namespace winrt +extern "C++" namespace winrt { - template + WINRT_EXPORT template impl::com_ref get_activation_factory(param::hstring const& name) { void* result{}; @@ -114,7 +114,7 @@ WINRT_EXPORT namespace winrt } } -WINRT_EXPORT namespace winrt::impl +extern "C++" namespace winrt::impl { #ifdef __clang__ @@ -122,7 +122,7 @@ WINRT_EXPORT namespace winrt::impl #pragma clang diagnostic ignored "-Wdeprecated-declarations" #endif - template + WINRT_EXPORT template T* interlocked_read_pointer(T* const volatile* target) noexcept { #if defined(_M_IX86) || defined(_M_X64) @@ -152,16 +152,16 @@ WINRT_EXPORT namespace winrt::impl #endif #ifdef _WIN64 - inline constexpr std::uint32_t memory_allocation_alignment{ 16 }; + WINRT_EXPORT inline constexpr std::uint32_t memory_allocation_alignment{ 16 }; #if defined(_MSC_VER) && !defined(__clang__) #pragma warning(push) #pragma warning(disable:4324) // structure was padded due to alignment specifier #endif - struct alignas(16) slist_entry + WINRT_EXPORT struct alignas(16) slist_entry { slist_entry* next; }; - union alignas(16) slist_header + WINRT_EXPORT union alignas(16) slist_header { struct { @@ -180,12 +180,12 @@ WINRT_EXPORT namespace winrt::impl #pragma warning(pop) #endif #else - inline constexpr std::uint32_t memory_allocation_alignment{ 8 }; - struct slist_entry + WINRT_EXPORT inline constexpr std::uint32_t memory_allocation_alignment{ 8 }; + WINRT_EXPORT struct slist_entry { slist_entry* next; }; - union slist_header + WINRT_EXPORT union slist_header { std::uint64_t reserved1; struct @@ -197,7 +197,7 @@ WINRT_EXPORT namespace winrt::impl }; #endif - struct factory_count_guard + WINRT_EXPORT struct factory_count_guard { factory_count_guard(factory_count_guard const&) = delete; factory_count_guard& operator=(factory_count_guard const&) = delete; @@ -228,7 +228,7 @@ WINRT_EXPORT namespace winrt::impl [[maybe_unused]] std::size_t& m_count; // Field is unused when WINRT_NO_MODULE_LOCK is defined. }; - struct factory_cache_entry_base + WINRT_EXPORT struct factory_cache_entry_base { struct alignas(sizeof(void*) * 2) object_and_count { @@ -277,7 +277,7 @@ WINRT_EXPORT namespace winrt::impl #error Unsupported architecture: verify that zero-initialization of SLIST_HEADER is still safe #endif - struct factory_cache + WINRT_EXPORT struct factory_cache { factory_cache(factory_cache const&) = delete; factory_cache& operator=(factory_cache const&) = delete; @@ -308,13 +308,13 @@ WINRT_EXPORT namespace winrt::impl alignas(memory_allocation_alignment) slist_header m_list; }; - inline factory_cache& get_factory_cache() noexcept + WINRT_EXPORT inline factory_cache& get_factory_cache() noexcept { static factory_cache cache; return cache; } - template + WINRT_EXPORT template struct factory_cache_entry : factory_cache_entry_base { template @@ -351,10 +351,10 @@ WINRT_EXPORT namespace winrt::impl } }; - template + WINRT_EXPORT template factory_cache_entry factory_cache_entry_v{}; - template + WINRT_EXPORT template auto call_factory(F&& callback) { auto& factory = factory_cache_entry_v; @@ -371,7 +371,7 @@ WINRT_EXPORT namespace winrt::impl return factory.call(callback); } - template + WINRT_EXPORT template auto call_factory_cast(F&& callback) { auto& factory = factory_cache_entry_v; @@ -388,7 +388,7 @@ WINRT_EXPORT namespace winrt::impl return factory.call(static_cast(callback)); } - template + WINRT_EXPORT template com_ref try_get_activation_factory(param::hstring const& name, hresult_error* exception = nullptr) noexcept { void* result{}; @@ -422,15 +422,15 @@ WINRT_EXPORT namespace winrt::impl }; } -WINRT_EXPORT namespace winrt +extern "C++" namespace winrt { - enum class apartment_type : std::int32_t + WINRT_EXPORT enum class apartment_type : std::int32_t { multi_threaded = 0, single_threaded = 2, }; - inline void init_apartment(apartment_type const type = apartment_type::multi_threaded) + WINRT_EXPORT inline void init_apartment(apartment_type const type = apartment_type::multi_threaded) { hresult const result = WINRT_IMPL_CoInitializeEx(nullptr, static_cast(type)); @@ -440,12 +440,12 @@ WINRT_EXPORT namespace winrt } } - inline void uninit_apartment() noexcept + WINRT_EXPORT inline void uninit_apartment() noexcept { WINRT_IMPL_CoUninitialize(); } - template + WINRT_EXPORT template auto get_activation_factory() { // Normally, the callback avoids having to return a ref-counted object and the resulting AddRef/Release bump. @@ -457,42 +457,42 @@ WINRT_EXPORT namespace winrt }); } - template + WINRT_EXPORT template auto try_get_activation_factory() noexcept { return impl::try_get_activation_factory(name_of()); } - template + WINRT_EXPORT template auto try_get_activation_factory(hresult_error& exception) noexcept { return impl::try_get_activation_factory(name_of(), &exception); } - template + WINRT_EXPORT template auto try_get_activation_factory(param::hstring const& name) noexcept { return impl::try_get_activation_factory(name); } - template + WINRT_EXPORT template auto try_get_activation_factory(param::hstring const& name, hresult_error& exception) noexcept { return impl::try_get_activation_factory(name, &exception); } - inline void clear_factory_cache() noexcept + WINRT_EXPORT inline void clear_factory_cache() noexcept { impl::get_factory_cache().clear(); } - template + WINRT_EXPORT template auto try_create_instance(guid const& clsid, std::uint32_t context = 0x1 /*CLSCTX_INPROC_SERVER*/, void* outer = nullptr) { return try_capture(WINRT_IMPL_CoCreateInstance, clsid, outer, context); } - template + WINRT_EXPORT template auto create_instance(guid const& clsid, std::uint32_t context = 0x1 /*CLSCTX_INPROC_SERVER*/, void* outer = nullptr) { return capture(WINRT_IMPL_CoCreateInstance, clsid, outer, context); @@ -500,7 +500,7 @@ WINRT_EXPORT namespace winrt namespace Windows::Foundation { - struct IActivationFactory : IInspectable + WINRT_EXPORT struct IActivationFactory : IInspectable { IActivationFactory(std::nullptr_t = nullptr) noexcept {} IActivationFactory(void* ptr, take_ownership_from_abi_t) noexcept : IInspectable(ptr, take_ownership_from_abi) {} @@ -516,9 +516,9 @@ WINRT_EXPORT namespace winrt } } -WINRT_EXPORT namespace winrt::impl +extern "C++" namespace winrt::impl { - template + WINRT_EXPORT template T fast_activate(Windows::Foundation::IActivationFactory const& factory) { void* result{}; diff --git a/strings/base_agile_ref.h b/strings/base_agile_ref.h index af8345037..a9c89617e 100644 --- a/strings/base_agile_ref.h +++ b/strings/base_agile_ref.h @@ -1,12 +1,12 @@ -WINRT_EXPORT namespace winrt +extern "C++" namespace winrt { #if defined(WINRT_NO_MODULE_LOCK) // Defining WINRT_NO_MODULE_LOCK is appropriate for apps (executables) or pinned DLLs (that don't support unloading) // and can thus avoid the synchronization overhead imposed by the default module lock. - constexpr auto get_module_lock() noexcept + WINRT_EXPORT constexpr auto get_module_lock() noexcept { struct lock { @@ -38,7 +38,7 @@ WINRT_EXPORT namespace winrt // This is the default implementation for use with DllCanUnloadNow. - inline impl::atomic_ref_count& get_module_lock() noexcept + WINRT_EXPORT inline impl::atomic_ref_count& get_module_lock() noexcept { static impl::atomic_ref_count s_lock; return s_lock; @@ -47,9 +47,9 @@ WINRT_EXPORT namespace winrt #endif } -WINRT_EXPORT namespace winrt::impl +extern "C++" namespace winrt::impl { - template + WINRT_EXPORT template struct module_lock_updater; template<> @@ -69,22 +69,22 @@ WINRT_EXPORT namespace winrt::impl template<> struct module_lock_updater {}; - using update_module_lock = module_lock_updater; + WINRT_EXPORT using update_module_lock = module_lock_updater; - inline void* load_library(wchar_t const* library) noexcept + WINRT_EXPORT inline void* load_library(wchar_t const* library) noexcept { return WINRT_IMPL_LoadLibraryExW(library, nullptr, 0x00001000 /* LOAD_LIBRARY_SEARCH_DEFAULT_DIRS */); } - inline hresult get_agile_reference(winrt::guid const& iid, void* object, void** reference) noexcept + WINRT_EXPORT inline hresult get_agile_reference(winrt::guid const& iid, void* object, void** reference) noexcept { return WINRT_IMPL_RoGetAgileReference(0, iid, object, reference); } } -WINRT_EXPORT namespace winrt +extern "C++" namespace winrt { - template + WINRT_EXPORT template struct agile_ref { agile_ref(std::nullptr_t = nullptr) noexcept {} @@ -121,7 +121,7 @@ WINRT_EXPORT namespace winrt template agile_ref(T const&)->agile_ref>; - template + WINRT_EXPORT template agile_ref> make_agile(T const& object) { return object; diff --git a/strings/base_array.h b/strings/base_array.h index ce536d807..1ff263ae3 100644 --- a/strings/base_array.h +++ b/strings/base_array.h @@ -1,7 +1,7 @@ -WINRT_EXPORT namespace winrt +extern "C++" namespace winrt { - template + WINRT_EXPORT template struct array_view { using value_type = T; @@ -252,7 +252,7 @@ WINRT_EXPORT namespace winrt template array_view(std::span& value) -> array_view; template array_view(std::span const& value) -> array_view; - template + WINRT_EXPORT template struct com_array : array_view { using value_type = typename array_view::value_type; @@ -417,7 +417,7 @@ WINRT_EXPORT namespace winrt template com_array(std::span const& value) -> com_array>; - template + WINRT_EXPORT template auto get_abi(array_view object) noexcept { using U = std::remove_const_t; @@ -434,7 +434,7 @@ WINRT_EXPORT namespace winrt } } - template + WINRT_EXPORT template auto put_abi(array_view object) noexcept { if constexpr (!std::is_trivially_destructible_v) @@ -445,29 +445,29 @@ WINRT_EXPORT namespace winrt return get_abi(object); } - template + WINRT_EXPORT template auto put_abi(com_array& object) noexcept { object.clear(); return reinterpret_cast*>(&object); } - template + WINRT_EXPORT template std::pair> detach_abi(com_array& object) noexcept { return object.detach_abi(); } - template + WINRT_EXPORT template auto detach_abi(com_array&& object) noexcept { return detach_abi(object); } } -WINRT_EXPORT namespace winrt::impl +extern "C++" namespace winrt::impl { - template + WINRT_EXPORT template struct array_size_proxy { array_size_proxy& operator=(array_size_proxy const&) = delete; @@ -497,13 +497,13 @@ WINRT_EXPORT namespace winrt::impl std::uint32_t m_size{ 0 }; }; - template + WINRT_EXPORT template array_size_proxy put_size_abi(com_array& object) noexcept { return array_size_proxy(object); } - template + WINRT_EXPORT template struct com_array_proxy { com_array_proxy(std::uint32_t* size, winrt::impl::arg_out* value) noexcept : m_size(size), m_value(value) @@ -533,29 +533,29 @@ WINRT_EXPORT namespace winrt::impl }; } -WINRT_EXPORT namespace winrt +extern "C++" namespace winrt { - template + WINRT_EXPORT template auto detach_abi(std::uint32_t* __valueSize, impl::arg_out* value) noexcept { return impl::com_array_proxy(__valueSize, value); } - inline hstring get_class_name(Windows::Foundation::IInspectable const& object) + WINRT_EXPORT inline hstring get_class_name(Windows::Foundation::IInspectable const& object) { void* value{}; check_hresult(static_cast(*impl::abi_cast(object))->GetRuntimeClassName(&value)); return { value, take_ownership_from_abi }; } - inline com_array get_interfaces(Windows::Foundation::IInspectable const& object) + WINRT_EXPORT inline com_array get_interfaces(Windows::Foundation::IInspectable const& object) { com_array value; check_hresult(static_cast(*impl::abi_cast(object))->GetIids(impl::put_size_abi(value), put_abi(value))); return value; } - inline Windows::Foundation::TrustLevel get_trust_level(Windows::Foundation::IInspectable const& object) + WINRT_EXPORT inline Windows::Foundation::TrustLevel get_trust_level(Windows::Foundation::IInspectable const& object) { Windows::Foundation::TrustLevel value{}; check_hresult(static_cast(*impl::abi_cast(object))->GetTrustLevel(&value)); diff --git a/strings/base_chrono.h b/strings/base_chrono.h index 7934ac5b2..721ca55cb 100644 --- a/strings/base_chrono.h +++ b/strings/base_chrono.h @@ -1,7 +1,7 @@ -WINRT_EXPORT namespace winrt +extern "C++" namespace winrt { - struct file_time + WINRT_EXPORT struct file_time { std::uint64_t value{}; @@ -24,7 +24,7 @@ WINRT_EXPORT namespace winrt #endif }; - struct clock + WINRT_EXPORT struct clock { using rep = std::int64_t; using period = impl::filetime_period; diff --git a/strings/base_collections.h b/strings/base_collections.h index 7d8dc2e77..55278465d 100644 --- a/strings/base_collections.h +++ b/strings/base_collections.h @@ -1,5 +1,5 @@ -WINRT_EXPORT namespace winrt::impl +extern "C++" namespace winrt::impl { namespace wfc = Windows::Foundation::Collections; @@ -14,7 +14,7 @@ WINRT_EXPORT namespace winrt::impl return get_end_iterator(static_cast(*this)); } - template + WINRT_EXPORT template struct key_value_pair; template @@ -42,13 +42,13 @@ WINRT_EXPORT namespace winrt::impl V const m_value; }; - template + WINRT_EXPORT template struct is_key_value_pair : std::false_type {}; template struct is_key_value_pair> : std::true_type {}; - struct input_scope + WINRT_EXPORT struct input_scope { void invalidate_scope() noexcept { @@ -68,7 +68,7 @@ WINRT_EXPORT namespace winrt::impl bool m_invalid{}; }; - struct no_collection_version + WINRT_EXPORT struct no_collection_version { struct iterator_type { @@ -82,7 +82,7 @@ WINRT_EXPORT namespace winrt::impl }; }; - struct collection_version + WINRT_EXPORT struct collection_version { struct iterator_type { @@ -119,7 +119,7 @@ WINRT_EXPORT namespace winrt::impl std::atomic m_version{}; }; - template + WINRT_EXPORT template struct range_container { T const first; diff --git a/strings/base_collections_base.h b/strings/base_collections_base.h index d107c633e..0197268c2 100644 --- a/strings/base_collections_base.h +++ b/strings/base_collections_base.h @@ -1,8 +1,9 @@ -WINRT_EXPORT namespace winrt::impl + +extern "C++" namespace winrt::impl { - struct nop_lock_guard {}; + WINRT_EXPORT struct nop_lock_guard {}; - struct single_threaded_collection_base + WINRT_EXPORT struct single_threaded_collection_base { [[nodiscard]] auto acquire_exclusive() const { @@ -15,7 +16,7 @@ WINRT_EXPORT namespace winrt::impl } }; - struct multi_threaded_collection_base + WINRT_EXPORT struct multi_threaded_collection_base { [[nodiscard]] auto acquire_exclusive() const { @@ -32,10 +33,10 @@ WINRT_EXPORT namespace winrt::impl mutable slim_mutex m_mutex; }; - template + WINRT_EXPORT template using container_type_t = std::decay_t().get_container())>; - template + WINRT_EXPORT template struct removed_values { void assign(container_type_t& value) @@ -57,7 +58,7 @@ WINRT_EXPORT namespace winrt::impl } }; - template + WINRT_EXPORT template struct removed_value { // Trivially destructible; okay to run destructor under lock @@ -79,9 +80,9 @@ WINRT_EXPORT namespace winrt::impl }; } -WINRT_EXPORT namespace winrt +extern "C++" namespace winrt { - template + WINRT_EXPORT template struct iterable_base : Version { template @@ -245,7 +246,7 @@ WINRT_EXPORT namespace winrt }; }; - template + WINRT_EXPORT template struct vector_view_base : iterable_base { T GetAt(std::uint32_t const index) const @@ -298,7 +299,7 @@ WINRT_EXPORT namespace winrt } }; - template + WINRT_EXPORT template struct vector_base : vector_view_base { Windows::Foundation::Collections::IVectorView GetView() const noexcept @@ -414,7 +415,7 @@ WINRT_EXPORT namespace winrt } }; - template + WINRT_EXPORT template struct observable_vector_base : vector_base { event_token VectorChanged(Windows::Foundation::Collections::VectorChangedEventHandler const& handler) @@ -505,7 +506,7 @@ WINRT_EXPORT namespace winrt }; }; - template + WINRT_EXPORT template struct map_view_base : iterable_base, Version> { // specialization of Lookup that avoids throwing the hresult @@ -555,7 +556,7 @@ WINRT_EXPORT namespace winrt }; - template + WINRT_EXPORT template struct map_base : map_view_base { Windows::Foundation::Collections::IMapView GetView() const @@ -604,7 +605,7 @@ WINRT_EXPORT namespace winrt } }; - template + WINRT_EXPORT template struct observable_map_base : map_base { event_token MapChanged(Windows::Foundation::Collections::MapChangedEventHandler const& handler) diff --git a/strings/base_collections_input_iterable.h b/strings/base_collections_input_iterable.h index 302d403b7..4477762de 100644 --- a/strings/base_collections_input_iterable.h +++ b/strings/base_collections_input_iterable.h @@ -1,7 +1,7 @@ -WINRT_EXPORT namespace winrt::impl +extern "C++" namespace winrt::impl { - template + WINRT_EXPORT template struct input_iterable : implements, non_agile, no_weak_ref, wfc::IIterable>, iterable_base, T> @@ -22,7 +22,7 @@ WINRT_EXPORT namespace winrt::impl Container const m_values; }; - template + WINRT_EXPORT template struct scoped_input_iterable : input_scope, implements, non_agile, no_weak_ref, wfc::IIterable>, @@ -54,13 +54,13 @@ WINRT_EXPORT namespace winrt::impl InputIt const m_end; }; - template + WINRT_EXPORT template auto make_input_iterable(Container&& values) { return make>(std::forward(values)); } - template + WINRT_EXPORT template auto make_scoped_input_iterable(InputIt first, InputIt last) { using interface_type = wfc::IIterable; @@ -72,9 +72,9 @@ WINRT_EXPORT namespace winrt::impl } } -WINRT_EXPORT namespace winrt::param +extern "C++" namespace winrt::param { - template + WINRT_EXPORT template struct iterable { using value_type = T; @@ -226,13 +226,13 @@ WINRT_EXPORT namespace winrt::param bool m_owned{ true }; }; - template + WINRT_EXPORT template auto get_abi(iterable const& object) noexcept { return *impl::abi_cast(object); } - template + WINRT_EXPORT template struct async_iterable { using value_type = T; @@ -348,7 +348,7 @@ WINRT_EXPORT namespace winrt::param bool m_owned{ true }; }; - template + WINRT_EXPORT template auto get_abi(async_iterable const& object) noexcept { return *impl::abi_cast(object); diff --git a/strings/base_collections_input_map.h b/strings/base_collections_input_map.h index 7cc8cca9c..805e1bffd 100644 --- a/strings/base_collections_input_map.h +++ b/strings/base_collections_input_map.h @@ -1,7 +1,7 @@ -WINRT_EXPORT namespace winrt::impl +extern "C++" namespace winrt::impl { - template + WINRT_EXPORT template struct map_impl : implements, wfc::IMap, wfc::IMapView, wfc::IIterable>>, map_base, K, V>, @@ -31,19 +31,19 @@ WINRT_EXPORT namespace winrt::impl Container m_values; }; - template + WINRT_EXPORT template using input_map = map_impl; - template + WINRT_EXPORT template auto make_input_map(Container&& values) { return make>(std::forward(values)); } } -WINRT_EXPORT namespace winrt::param +extern "C++" namespace winrt::param { - template + WINRT_EXPORT template struct map { using value_type = Windows::Foundation::Collections::IKeyValuePair; @@ -104,7 +104,7 @@ WINRT_EXPORT namespace winrt::param bool m_owned{ true }; }; - template + WINRT_EXPORT template auto get_abi(map const& object) noexcept { return *impl::abi_cast(object); diff --git a/strings/base_collections_input_map_view.h b/strings/base_collections_input_map_view.h index 43262300f..65d617441 100644 --- a/strings/base_collections_input_map_view.h +++ b/strings/base_collections_input_map_view.h @@ -1,7 +1,7 @@ -WINRT_EXPORT namespace winrt::impl +extern "C++" namespace winrt::impl { - template + WINRT_EXPORT template struct input_map_view : implements, non_agile, no_weak_ref, wfc::IMapView, wfc::IIterable>>, map_view_base, K, V> @@ -22,7 +22,7 @@ WINRT_EXPORT namespace winrt::impl Container const m_values; }; - template + WINRT_EXPORT template struct scoped_input_map_view : input_scope, implements, non_agile, no_weak_ref, wfc::IMapView, wfc::IIterable>>, @@ -53,13 +53,13 @@ WINRT_EXPORT namespace winrt::impl Container const& m_values; }; - template + WINRT_EXPORT template auto make_input_map_view(Container&& values) { return make>(std::forward(values)); } - template + WINRT_EXPORT template auto make_scoped_input_map_view(Container const& values) { using interface_type = wfc::IMapView; @@ -71,9 +71,9 @@ WINRT_EXPORT namespace winrt::impl } } -WINRT_EXPORT namespace winrt::param +extern "C++" namespace winrt::param { - template + WINRT_EXPORT template struct map_view { using value_type = Windows::Foundation::Collections::IKeyValuePair; @@ -146,13 +146,13 @@ WINRT_EXPORT namespace winrt::param bool m_owned{ true }; }; - template + WINRT_EXPORT template auto get_abi(map_view const& object) noexcept { return *impl::abi_cast(object); } - template + WINRT_EXPORT template struct async_map_view { using value_type = Windows::Foundation::Collections::IKeyValuePair; @@ -213,7 +213,7 @@ WINRT_EXPORT namespace winrt::param bool m_owned{ true }; }; - template + WINRT_EXPORT template auto get_abi(async_map_view const& object) noexcept { return *impl::abi_cast(object); diff --git a/strings/base_collections_input_vector.h b/strings/base_collections_input_vector.h index 412e591a8..9b2682632 100644 --- a/strings/base_collections_input_vector.h +++ b/strings/base_collections_input_vector.h @@ -1,7 +1,7 @@ -WINRT_EXPORT namespace winrt::impl +extern "C++" namespace winrt::impl { - template + WINRT_EXPORT template struct vector_impl : implements, wfc::IVector, wfc::IVectorView, wfc::IIterable>, vector_base, T>, @@ -31,13 +31,13 @@ WINRT_EXPORT namespace winrt::impl Container m_values; }; - template + WINRT_EXPORT template using input_vector = vector_impl; } -WINRT_EXPORT namespace winrt::param +extern "C++" namespace winrt::param { - template + WINRT_EXPORT template struct vector { using value_type = T; @@ -92,7 +92,7 @@ WINRT_EXPORT namespace winrt::param bool m_owned = true; }; - template + WINRT_EXPORT template auto get_abi(vector const& object) noexcept { return *impl::abi_cast(object); diff --git a/strings/base_collections_input_vector_view.h b/strings/base_collections_input_vector_view.h index 0674f384b..50b218322 100644 --- a/strings/base_collections_input_vector_view.h +++ b/strings/base_collections_input_vector_view.h @@ -1,7 +1,7 @@ -WINRT_EXPORT namespace winrt::impl +extern "C++" namespace winrt::impl { - template + WINRT_EXPORT template struct input_vector_view : implements, non_agile, no_weak_ref, wfc::IVectorView, wfc::IIterable>, vector_view_base, T> @@ -22,7 +22,7 @@ WINRT_EXPORT namespace winrt::impl Container const m_values; }; - template + WINRT_EXPORT template struct scoped_input_vector_view : input_scope, implements, non_agile, no_weak_ref, wfc::IVectorView, wfc::IIterable>, @@ -54,7 +54,7 @@ WINRT_EXPORT namespace winrt::impl InputIt const m_end; }; - template + WINRT_EXPORT template auto make_scoped_input_vector_view(InputIt first, InputIt last) { using interface_type = wfc::IVectorView; @@ -66,9 +66,9 @@ WINRT_EXPORT namespace winrt::impl } } -WINRT_EXPORT namespace winrt::param +extern "C++" namespace winrt::param { - template + WINRT_EXPORT template struct vector_view { using value_type = T; @@ -142,13 +142,13 @@ WINRT_EXPORT namespace winrt::param bool m_owned{ true }; }; - template + WINRT_EXPORT template auto get_abi(vector_view const& object) noexcept { return *impl::abi_cast(object); } - template + WINRT_EXPORT template struct async_vector_view { using value_type = T; @@ -203,7 +203,7 @@ WINRT_EXPORT namespace winrt::param bool m_owned{ true }; }; - template + WINRT_EXPORT template auto get_abi(async_vector_view const& object) noexcept { return *impl::abi_cast(object); diff --git a/strings/base_collections_map.h b/strings/base_collections_map.h index b40247dab..19b6127eb 100644 --- a/strings/base_collections_map.h +++ b/strings/base_collections_map.h @@ -1,10 +1,10 @@ -WINRT_EXPORT namespace winrt::impl +extern "C++" namespace winrt::impl { - template + WINRT_EXPORT template using multi_threaded_map = map_impl; - template + WINRT_EXPORT template struct observable_map_impl : implements, wfc::IObservableMap, wfc::IMap, wfc::IMapView, wfc::IIterable>>, observable_map_base, K, V>, @@ -34,89 +34,89 @@ WINRT_EXPORT namespace winrt::impl Container m_values; }; - template + WINRT_EXPORT template using observable_map = observable_map_impl; - template + WINRT_EXPORT template using multi_threaded_observable_map = observable_map_impl; } -WINRT_EXPORT namespace winrt +extern "C++" namespace winrt { - template , typename Allocator = std::allocator>> + WINRT_EXPORT template , typename Allocator = std::allocator>> Windows::Foundation::Collections::IMap single_threaded_map() { return make>>(std::map{}); } - template , typename Allocator = std::allocator>> + WINRT_EXPORT template , typename Allocator = std::allocator>> Windows::Foundation::Collections::IMap single_threaded_map(std::map&& values) { return make>>(std::move(values)); } - template , typename KeyEqual = std::equal_to, typename Allocator = std::allocator>> + WINRT_EXPORT template , typename KeyEqual = std::equal_to, typename Allocator = std::allocator>> Windows::Foundation::Collections::IMap single_threaded_map(std::unordered_map&& values) { return make>>(std::move(values)); } - template , typename Allocator = std::allocator>> + WINRT_EXPORT template , typename Allocator = std::allocator>> Windows::Foundation::Collections::IMap multi_threaded_map() { return make>>(std::map{}); } - template , typename Allocator = std::allocator>> + WINRT_EXPORT template , typename Allocator = std::allocator>> Windows::Foundation::Collections::IMap multi_threaded_map(std::map&& values) { return make>>(std::move(values)); } - template , typename KeyEqual = std::equal_to, typename Allocator = std::allocator>> + WINRT_EXPORT template , typename KeyEqual = std::equal_to, typename Allocator = std::allocator>> Windows::Foundation::Collections::IMap multi_threaded_map(std::unordered_map&& values) { return make>>(std::move(values)); } - template , typename Allocator = std::allocator>> + WINRT_EXPORT template , typename Allocator = std::allocator>> Windows::Foundation::Collections::IObservableMap single_threaded_observable_map() { return make>>(std::map{}); } - template , typename Allocator = std::allocator>> + WINRT_EXPORT template , typename Allocator = std::allocator>> Windows::Foundation::Collections::IObservableMap single_threaded_observable_map(std::map&& values) { return make>>(std::move(values)); } - template , typename KeyEqual = std::equal_to, typename Allocator = std::allocator>> + WINRT_EXPORT template , typename KeyEqual = std::equal_to, typename Allocator = std::allocator>> Windows::Foundation::Collections::IObservableMap single_threaded_observable_map(std::unordered_map&& values) { return make>>(std::move(values)); } - template , typename Allocator = std::allocator>> + WINRT_EXPORT template , typename Allocator = std::allocator>> Windows::Foundation::Collections::IObservableMap multi_threaded_observable_map() { return make>>(std::map{}); } - template , typename Allocator = std::allocator>> + WINRT_EXPORT template , typename Allocator = std::allocator>> Windows::Foundation::Collections::IObservableMap multi_threaded_observable_map(std::map&& values) { return make>>(std::move(values)); } - template , typename KeyEqual = std::equal_to, typename Allocator = std::allocator>> + WINRT_EXPORT template , typename KeyEqual = std::equal_to, typename Allocator = std::allocator>> Windows::Foundation::Collections::IObservableMap multi_threaded_observable_map(std::unordered_map&& values) { return make>>(std::move(values)); } } -namespace std +extern "C++" namespace std { template struct tuple_size> @@ -132,7 +132,7 @@ namespace std }; } -namespace winrt::Windows::Foundation::Collections +extern "C++" namespace winrt::Windows::Foundation::Collections { template std::tuple_element_t> get(IKeyValuePair const& kvp) diff --git a/strings/base_collections_vector.h b/strings/base_collections_vector.h index 3388806af..8b015fa1b 100644 --- a/strings/base_collections_vector.h +++ b/strings/base_collections_vector.h @@ -1,10 +1,10 @@ -WINRT_EXPORT namespace winrt::impl +extern "C++" namespace winrt::impl { - template + WINRT_EXPORT template using multi_threaded_vector = vector_impl; - template + WINRT_EXPORT template struct inspectable_observable_vector : observable_vector_base, Windows::Foundation::IInspectable>, implements, @@ -35,10 +35,10 @@ WINRT_EXPORT namespace winrt::impl Container m_values; }; - template + WINRT_EXPORT template using multi_threaded_inspectable_observable_vector = inspectable_observable_vector; - template + WINRT_EXPORT template struct convertible_observable_vector : observable_vector_base, T>, implements, @@ -293,25 +293,25 @@ WINRT_EXPORT namespace winrt::impl Container m_values; }; - template + WINRT_EXPORT template using multi_threaded_convertible_observable_vector = convertible_observable_vector; } -WINRT_EXPORT namespace winrt +extern "C++" namespace winrt { - template > + WINRT_EXPORT template > Windows::Foundation::Collections::IVector single_threaded_vector(std::vector&& values = {}) { return make>>(std::move(values)); } - template > + WINRT_EXPORT template > Windows::Foundation::Collections::IVector multi_threaded_vector(std::vector&& values = {}) { return make>>(std::move(values)); } - template > + WINRT_EXPORT template > Windows::Foundation::Collections::IObservableVector single_threaded_observable_vector(std::vector&& values = {}) { if constexpr (std::is_same_v) @@ -324,7 +324,7 @@ WINRT_EXPORT namespace winrt } } - template > + WINRT_EXPORT template > Windows::Foundation::Collections::IObservableVector multi_threaded_observable_vector(std::vector&& values = {}) { if constexpr (std::is_same_v) diff --git a/strings/base_com_ptr.h b/strings/base_com_ptr.h index 1925bf5df..7aaa0cd95 100644 --- a/strings/base_com_ptr.h +++ b/strings/base_com_ptr.h @@ -1,13 +1,13 @@ -WINRT_EXPORT namespace winrt +extern "C++" namespace winrt { - template + WINRT_EXPORT template struct com_ptr; } -WINRT_EXPORT namespace winrt::impl +extern "C++" namespace winrt::impl { - struct capture_decay + WINRT_EXPORT struct capture_decay { void** result; @@ -18,26 +18,26 @@ WINRT_EXPORT namespace winrt::impl } }; - template + WINRT_EXPORT template std::int32_t capture_to(void**result, F function, Args&& ...args) { return function(args..., guid_of(), capture_decay{ result }); } - template + WINRT_EXPORT template requires (std::is_class_v || std::is_union_v) std::int32_t capture_to(void** result, O* object, M method, Args&& ...args) { return (object->*method)(args..., guid_of(), capture_decay{ result }); } - template + WINRT_EXPORT template std::int32_t capture_to(void** result, com_ptr const& object, M method, Args&& ...args); } -WINRT_EXPORT namespace winrt +extern "C++" namespace winrt { - template + WINRT_EXPORT template struct com_ptr { using type = impl::abi_t; @@ -262,7 +262,7 @@ WINRT_EXPORT namespace winrt type* m_ptr{}; }; - template + WINRT_EXPORT template impl::com_ref try_capture(Args&& ...args) { void* result{}; @@ -270,7 +270,7 @@ WINRT_EXPORT namespace winrt return { result, take_ownership_from_abi }; } - template + WINRT_EXPORT template impl::com_ref capture(Args&& ...args) { void* result{}; @@ -278,42 +278,45 @@ WINRT_EXPORT namespace winrt return { result, take_ownership_from_abi }; } - template + WINRT_EXPORT template auto get_abi(com_ptr const& object) noexcept { return object.get(); } - template + WINRT_EXPORT template auto put_abi(com_ptr& object) noexcept { return object.put_void(); } - template + WINRT_EXPORT template void attach_abi(com_ptr& object, impl::abi_t* value) noexcept { object.attach(value); } - template + WINRT_EXPORT template auto detach_abi(com_ptr& object) noexcept { return object.detach(); } } -WINRT_EXPORT namespace winrt::impl +extern "C++" namespace winrt::impl { - template + WINRT_EXPORT template std::int32_t capture_to(void** result, com_ptr const& object, M method, Args&& ...args) { return (object.get()->*(method))(args..., guid_of(), capture_decay{ result }); } } -template -void** IID_PPV_ARGS_Helper(winrt::com_ptr* ptr) noexcept +extern "C++" { - return winrt::put_abi(*ptr); + template + void** IID_PPV_ARGS_Helper(winrt::com_ptr* ptr) noexcept + { + return winrt::put_abi(*ptr); + } } diff --git a/strings/base_composable.h b/strings/base_composable.h index a6d5da179..0e1bd6536 100644 --- a/strings/base_composable.h +++ b/strings/base_composable.h @@ -1,7 +1,7 @@ -WINRT_EXPORT namespace winrt::impl +extern "C++" namespace winrt::impl { - template + WINRT_EXPORT template struct composable_factory { #if defined(_MSC_VER) && !defined(__clang__) @@ -33,7 +33,7 @@ WINRT_EXPORT namespace winrt::impl } }; - template + WINRT_EXPORT template class WINRT_IMPL_EMPTY_BASES produce_dispatch_to_overridable_base { protected: @@ -55,10 +55,10 @@ WINRT_EXPORT namespace winrt::impl } }; - template + WINRT_EXPORT template struct produce_dispatch_to_overridable; - template + WINRT_EXPORT template class dispatch_to_overridable { class wrapper : public produce_dispatch_to_overridable... diff --git a/strings/base_coroutine_foundation.h b/strings/base_coroutine_foundation.h index db8e299a4..f9dd949ed 100644 --- a/strings/base_coroutine_foundation.h +++ b/strings/base_coroutine_foundation.h @@ -1,10 +1,10 @@ -WINRT_EXPORT namespace winrt::impl +extern "C++" namespace winrt::impl { - template + WINRT_EXPORT template struct async_completed_handler; - template + WINRT_EXPORT template using async_completed_handler_t = typename async_completed_handler::type; template <> @@ -31,14 +31,14 @@ WINRT_EXPORT namespace winrt::impl using type = Windows::Foundation::AsyncOperationWithProgressCompletedHandler; }; - inline void check_sta_blocking_wait() noexcept + WINRT_EXPORT inline void check_sta_blocking_wait() noexcept { // Note: A blocking wait on the UI thread for an asynchronous operation can cause a deadlock. // See https://docs.microsoft.com/windows/uwp/cpp-and-winrt-apis/concurrency#block-the-calling-thread WINRT_ASSERT(!is_sta_thread()); } - template + WINRT_EXPORT template std::pair make_delegate_with_shared_state(H&& handler) { auto d = make_delegate(std::forward(handler)); @@ -46,7 +46,7 @@ WINRT_EXPORT namespace winrt::impl return { std::move(d), abi }; } - template + WINRT_EXPORT template auto wait_for_completed(Async const& async, std::uint32_t const timeout) { struct shared_type @@ -67,7 +67,7 @@ WINRT_EXPORT namespace winrt::impl return shared->status; } - template + WINRT_EXPORT template auto wait_for(Async const& async, Windows::Foundation::TimeSpan const& timeout) { check_sta_blocking_wait(); @@ -76,7 +76,7 @@ WINRT_EXPORT namespace winrt::impl return wait_for_completed(async, static_cast(milliseconds)); } - inline void check_status_canceled(Windows::Foundation::AsyncStatus status) + WINRT_EXPORT inline void check_status_canceled(Windows::Foundation::AsyncStatus status) { if (status == Windows::Foundation::AsyncStatus::Canceled) { @@ -84,7 +84,7 @@ WINRT_EXPORT namespace winrt::impl } } - template + WINRT_EXPORT template auto wait_get(Async const& async) { check_sta_blocking_wait(); @@ -99,9 +99,9 @@ WINRT_EXPORT namespace winrt::impl return async.GetResults(); } - struct ignore_apartment_context {}; + WINRT_EXPORT struct ignore_apartment_context {}; - template + WINRT_EXPORT template struct disconnect_aware_handler : private std::conditional_t { disconnect_aware_handler(Awaiter* awaiter, std::coroutine_handle<> handle) noexcept @@ -149,7 +149,7 @@ WINRT_EXPORT namespace winrt::impl } }; - template + WINRT_EXPORT template struct await_adapter : cancellable_awaiter> { template @@ -257,9 +257,9 @@ WINRT_EXPORT namespace winrt::impl } } -WINRT_EXPORT namespace winrt +extern "C++" namespace winrt { - template + WINRT_EXPORT template requires std::convertible_to inline impl::await_adapter, false> resume_agile(Async&& async) { @@ -267,52 +267,52 @@ WINRT_EXPORT namespace winrt }; } -WINRT_EXPORT namespace winrt::Windows::Foundation +extern "C++" namespace winrt::Windows::Foundation { - inline impl::await_adapter operator co_await(IAsyncAction const& async) + WINRT_EXPORT inline impl::await_adapter operator co_await(IAsyncAction const& async) { return{ async }; } - template + WINRT_EXPORT template impl::await_adapter> operator co_await(IAsyncActionWithProgress const& async) { return{ async }; } - template + WINRT_EXPORT template impl::await_adapter> operator co_await(IAsyncOperation const& async) { return{ async }; } - template + WINRT_EXPORT template impl::await_adapter> operator co_await(IAsyncOperationWithProgress const& async) { return{ async }; } } -WINRT_EXPORT namespace winrt +extern "C++" namespace winrt { - struct get_progress_token_t {}; + WINRT_EXPORT struct get_progress_token_t {}; - inline get_progress_token_t get_progress_token() noexcept + WINRT_EXPORT inline get_progress_token_t get_progress_token() noexcept { return{}; } - struct get_cancellation_token_t {}; + WINRT_EXPORT struct get_cancellation_token_t {}; - inline get_cancellation_token_t get_cancellation_token() noexcept + WINRT_EXPORT inline get_cancellation_token_t get_cancellation_token() noexcept { return{}; } } -WINRT_EXPORT namespace winrt::impl +extern "C++" namespace winrt::impl { - template + WINRT_EXPORT template struct cancellation_token { cancellation_token(Promise* promise) noexcept : m_promise(promise) @@ -357,7 +357,7 @@ WINRT_EXPORT namespace winrt::impl Promise* m_promise; }; - template + WINRT_EXPORT template struct progress_token { progress_token(Promise* promise) noexcept : @@ -396,7 +396,7 @@ WINRT_EXPORT namespace winrt::impl Promise* m_promise; }; - template + WINRT_EXPORT template struct promise_base : implements, cancellable_promise { using AsyncStatus = Windows::Foundation::AsyncStatus; @@ -702,7 +702,7 @@ WINRT_EXPORT namespace winrt::impl }; } -WINRT_EXPORT namespace std +extern "C++" namespace std { template struct coroutine_traits @@ -835,16 +835,16 @@ WINRT_EXPORT namespace std }; } -WINRT_EXPORT namespace winrt +extern "C++" namespace winrt { - template + WINRT_EXPORT template Windows::Foundation::IAsyncAction when_all(T... async) { (void(co_await async), ...); co_return; } - template + WINRT_EXPORT template T when_any(T const& first, Rest const& ... rest) { static_assert(impl::has_category_v, "T must be WinRT async type such as IAsyncAction or IAsyncOperation."); diff --git a/strings/base_coroutine_system.h b/strings/base_coroutine_system.h index 96d942bec..9430dd498 100644 --- a/strings/base_coroutine_system.h +++ b/strings/base_coroutine_system.h @@ -1,7 +1,7 @@ -WINRT_EXPORT namespace winrt +extern "C++" namespace winrt { - [[nodiscard]] inline auto resume_foreground( + WINRT_EXPORT [[nodiscard]] inline auto resume_foreground( Windows::System::DispatcherQueue const& dispatcher, Windows::System::DispatcherQueuePriority const priority = Windows::System::DispatcherQueuePriority::Normal) noexcept { @@ -41,7 +41,7 @@ WINRT_EXPORT namespace winrt return awaitable{ dispatcher, priority }; }; - inline auto operator co_await(Windows::System::DispatcherQueue const& dispatcher) + WINRT_EXPORT inline auto operator co_await(Windows::System::DispatcherQueue const& dispatcher) { return resume_foreground(dispatcher); } diff --git a/strings/base_coroutine_system_winui.h b/strings/base_coroutine_system_winui.h index 93eb4fe61..037d2afdf 100644 --- a/strings/base_coroutine_system_winui.h +++ b/strings/base_coroutine_system_winui.h @@ -1,7 +1,7 @@ -WINRT_EXPORT namespace winrt +extern "C++" namespace winrt { - [[nodiscard]] inline auto resume_foreground( + WINRT_EXPORT [[nodiscard]] inline auto resume_foreground( Microsoft::System::DispatcherQueue const& dispatcher, Microsoft::System::DispatcherQueuePriority const priority = Microsoft::System::DispatcherQueuePriority::Normal) noexcept { @@ -39,9 +39,9 @@ WINRT_EXPORT namespace winrt }; return awaitable{ dispatcher, priority }; - }; + } - inline auto operator co_await(Microsoft::System::DispatcherQueue const& dispatcher) + WINRT_EXPORT inline auto operator co_await(Microsoft::System::DispatcherQueue const& dispatcher) { return resume_foreground(dispatcher); } diff --git a/strings/base_coroutine_threadpool.h b/strings/base_coroutine_threadpool.h index 9a3bbb652..df28f9fbb 100644 --- a/strings/base_coroutine_threadpool.h +++ b/strings/base_coroutine_threadpool.h @@ -1,7 +1,7 @@ -WINRT_EXPORT namespace winrt::impl +extern "C++" namespace winrt::impl { - inline auto submit_threadpool_callback(void(__stdcall* callback)(void*, void* context), void* context) + WINRT_EXPORT inline auto submit_threadpool_callback(void(__stdcall* callback)(void*, void* context), void* context) { if (!WINRT_IMPL_TrySubmitThreadpoolCallback(callback, context, nullptr)) { @@ -9,17 +9,17 @@ WINRT_EXPORT namespace winrt::impl } } - inline void __stdcall resume_background_callback(void*, void* context) noexcept + WINRT_EXPORT inline void __stdcall resume_background_callback(void*, void* context) noexcept { std::coroutine_handle<>::from_address(context)(); }; - inline auto resume_background(std::coroutine_handle<> handle) + WINRT_EXPORT inline auto resume_background(std::coroutine_handle<> handle) { submit_threadpool_callback(resume_background_callback, handle.address()); } - inline std::pair get_apartment_type() noexcept + WINRT_EXPORT inline std::pair get_apartment_type() noexcept { std::int32_t aptType; std::int32_t aptTypeQualifier; @@ -33,7 +33,7 @@ WINRT_EXPORT namespace winrt::impl } } - inline bool is_sta_thread() noexcept + WINRT_EXPORT inline bool is_sta_thread() noexcept { auto type = get_apartment_type(); switch (type.first) @@ -48,7 +48,7 @@ WINRT_EXPORT namespace winrt::impl return false; } - struct resume_apartment_context + WINRT_EXPORT struct resume_apartment_context { resume_apartment_context() = default; resume_apartment_context(std::nullptr_t) : m_context(nullptr), m_context_type(-1) {} @@ -62,13 +62,13 @@ WINRT_EXPORT namespace winrt::impl movable_primitive m_context_type = get_apartment_type().first; }; - inline std::int32_t __stdcall resume_apartment_callback(com_callback_args* args) noexcept + WINRT_EXPORT inline std::int32_t __stdcall resume_apartment_callback(com_callback_args* args) noexcept { std::coroutine_handle<>::from_address(args->data)(); return 0; }; - [[nodiscard]] inline bool resume_apartment_sync(com_ptr const& context, std::coroutine_handle<> handle, std::int32_t* failure) + WINRT_EXPORT [[nodiscard]] inline bool resume_apartment_sync(com_ptr const& context, std::coroutine_handle<> handle, std::int32_t* failure) { com_callback_args args{}; args.data = handle.address(); @@ -83,7 +83,7 @@ WINRT_EXPORT namespace winrt::impl return true; } - struct threadpool_resume + WINRT_EXPORT struct threadpool_resume { threadpool_resume(com_ptr const& context, std::coroutine_handle<> handle, std::int32_t* failure) : m_context(context), m_handle(handle), m_failure(failure) { } @@ -92,7 +92,7 @@ WINRT_EXPORT namespace winrt::impl std::int32_t* m_failure; }; - inline void __stdcall fallback_submit_threadpool_callback(void*, void* p) noexcept + WINRT_EXPORT inline void __stdcall fallback_submit_threadpool_callback(void*, void* p) noexcept { std::unique_ptr state{ static_cast(p) }; if (!resume_apartment_sync(state->m_context, state->m_handle, state->m_failure)) @@ -101,14 +101,14 @@ WINRT_EXPORT namespace winrt::impl } } - inline void resume_apartment_on_threadpool(com_ptr const& context, std::coroutine_handle<> handle, std::int32_t* failure) + WINRT_EXPORT inline void resume_apartment_on_threadpool(com_ptr const& context, std::coroutine_handle<> handle, std::int32_t* failure) { auto state = std::make_unique(context, handle, failure); submit_threadpool_callback(fallback_submit_threadpool_callback, state.get()); state.release(); } - [[nodiscard]] inline auto resume_apartment(resume_apartment_context const& context, std::coroutine_handle<> handle, std::int32_t* failure) + WINRT_EXPORT [[nodiscard]] inline auto resume_apartment(resume_apartment_context const& context, std::coroutine_handle<> handle, std::int32_t* failure) { WINRT_ASSERT(context.valid()); if ((context.m_context == nullptr) || (context.m_context == try_capture(WINRT_IMPL_CoGetObjectContext))) @@ -131,9 +131,9 @@ WINRT_EXPORT namespace winrt::impl } } - using canceller_t = void(*)(void*); + WINRT_EXPORT using canceller_t = void(*)(void*); - struct unique_cancellation_lock + WINRT_EXPORT struct unique_cancellation_lock { std::atomic& m_pcanceller; @@ -144,9 +144,9 @@ WINRT_EXPORT namespace winrt::impl }; } -WINRT_EXPORT namespace winrt +extern "C++" namespace winrt { - struct cancellable_promise + WINRT_EXPORT struct cancellable_promise { void set_canceller(impl::canceller_t canceller, void* context) { @@ -202,7 +202,7 @@ WINRT_EXPORT namespace winrt bool m_originate_on_cancel{ true }; // By default, will call RoOriginateError before throwing a cancel error code. }; - template + WINRT_EXPORT template struct cancellable_awaiter { cancellable_awaiter() noexcept = default; @@ -242,9 +242,9 @@ WINRT_EXPORT namespace winrt }; } -WINRT_EXPORT namespace winrt +extern "C++" namespace winrt { - [[nodiscard]] inline auto resume_background() noexcept + WINRT_EXPORT [[nodiscard]] inline auto resume_background() noexcept { struct awaitable { @@ -266,7 +266,7 @@ WINRT_EXPORT namespace winrt return awaitable{}; } - template + WINRT_EXPORT template [[nodiscard]] auto resume_background(T const& context) noexcept { struct awaitable @@ -310,7 +310,7 @@ WINRT_EXPORT namespace winrt return awaitable{ context }; } - struct apartment_context + WINRT_EXPORT struct apartment_context { apartment_context() = default; apartment_context(std::nullptr_t) : context(nullptr) { } @@ -322,9 +322,9 @@ WINRT_EXPORT namespace winrt }; } -WINRT_EXPORT namespace winrt::impl +extern "C++" namespace winrt::impl { - struct apartment_awaiter + WINRT_EXPORT struct apartment_awaiter { apartment_context const& context; std::int32_t failure = 0; @@ -346,7 +346,7 @@ WINRT_EXPORT namespace winrt::impl } }; - struct timespan_awaiter : cancellable_awaiter + WINRT_EXPORT struct timespan_awaiter : cancellable_awaiter { explicit timespan_awaiter(Windows::Foundation::TimeSpan duration) noexcept : m_duration(duration) @@ -452,7 +452,7 @@ WINRT_EXPORT namespace winrt::impl std::atomic m_state{ state::idle }; }; - struct signal_awaiter : cancellable_awaiter + WINRT_EXPORT struct signal_awaiter : cancellable_awaiter { signal_awaiter(void* handle, Windows::Foundation::TimeSpan timeout) noexcept : m_timeout(timeout), @@ -567,29 +567,29 @@ WINRT_EXPORT namespace winrt::impl }; } -WINRT_EXPORT namespace winrt +extern "C++" namespace winrt { - inline impl::apartment_awaiter operator co_await(apartment_context const& context) + WINRT_EXPORT inline impl::apartment_awaiter operator co_await(apartment_context const& context) { return{ context }; } - [[nodiscard]] inline impl::timespan_awaiter resume_after(Windows::Foundation::TimeSpan duration) noexcept + WINRT_EXPORT [[nodiscard]] inline impl::timespan_awaiter resume_after(Windows::Foundation::TimeSpan duration) noexcept { return impl::timespan_awaiter{ duration }; } - inline impl::timespan_awaiter operator co_await(Windows::Foundation::TimeSpan duration) + WINRT_EXPORT inline impl::timespan_awaiter operator co_await(Windows::Foundation::TimeSpan duration) { return resume_after(duration); } - [[nodiscard]] inline impl::signal_awaiter resume_on_signal(void* handle, Windows::Foundation::TimeSpan timeout = {}) noexcept + WINRT_EXPORT [[nodiscard]] inline impl::signal_awaiter resume_on_signal(void* handle, Windows::Foundation::TimeSpan timeout = {}) noexcept { return impl::signal_awaiter{ handle, timeout }; } - struct thread_pool + WINRT_EXPORT struct thread_pool { thread_pool() : m_pool(check_pointer(WINRT_IMPL_CreateThreadpool(nullptr))) @@ -669,10 +669,10 @@ WINRT_EXPORT namespace winrt environment m_environment; }; - struct fire_and_forget {}; + WINRT_EXPORT struct fire_and_forget {}; } -WINRT_EXPORT namespace std +extern "C++" namespace std { template struct coroutine_traits diff --git a/strings/base_coroutine_ui_core.h b/strings/base_coroutine_ui_core.h index 03d374905..af248c1e9 100644 --- a/strings/base_coroutine_ui_core.h +++ b/strings/base_coroutine_ui_core.h @@ -1,7 +1,7 @@ -WINRT_EXPORT namespace winrt +extern "C++" namespace winrt { - [[nodiscard]] inline auto resume_foreground( + WINRT_EXPORT [[nodiscard]] inline auto resume_foreground( Windows::UI::Core::CoreDispatcher const& dispatcher, Windows::UI::Core::CoreDispatcherPriority const priority = Windows::UI::Core::CoreDispatcherPriority::Normal) noexcept { @@ -39,7 +39,7 @@ WINRT_EXPORT namespace winrt return awaitable{ dispatcher, priority }; }; - inline auto operator co_await(Windows::UI::Core::CoreDispatcher const& dispatcher) + WINRT_EXPORT inline auto operator co_await(Windows::UI::Core::CoreDispatcher const& dispatcher) { return resume_foreground(dispatcher); } diff --git a/strings/base_deferral.h b/strings/base_deferral.h index 702cf3a32..590824828 100644 --- a/strings/base_deferral.h +++ b/strings/base_deferral.h @@ -1,7 +1,7 @@ -WINRT_EXPORT namespace winrt +extern "C++" namespace winrt { - template + WINRT_EXPORT template struct deferrable_event_args { Windows::Foundation::Deferral GetDeferral() diff --git a/strings/base_delegate.h b/strings/base_delegate.h index 5d3c1b722..f48c4af17 100644 --- a/strings/base_delegate.h +++ b/strings/base_delegate.h @@ -1,12 +1,12 @@ -WINRT_EXPORT namespace winrt::impl +extern "C++" namespace winrt::impl { #if defined(_MSC_VER) && !defined(__clang__) #pragma warning(push) #pragma warning(disable:4458) // declaration hides class member (okay because we do not use named members of base class) #endif - struct implements_delegate_base + WINRT_EXPORT struct implements_delegate_base { WINRT_IMPL_NOINLINE std::uint32_t increment_reference() noexcept { @@ -40,7 +40,7 @@ WINRT_EXPORT namespace winrt::impl atomic_ref_count m_references{ 1 }; }; - template + WINRT_EXPORT template struct implements_delegate : abi_t, implements_delegate_base, H, update_module_lock { implements_delegate(H&& handler) : H(std::forward(handler)) @@ -70,13 +70,13 @@ WINRT_EXPORT namespace winrt::impl } }; - template + WINRT_EXPORT template T make_delegate(H&& handler) { return { static_cast(static_cast*>(new delegate(std::forward(handler)))), take_ownership_from_abi }; } - template + WINRT_EXPORT template T make_agile_delegate(T const& delegate) noexcept { if constexpr (!has_category_v) @@ -108,13 +108,13 @@ WINRT_EXPORT namespace winrt::impl } } - template + WINRT_EXPORT template struct WINRT_IMPL_ABI_DECL variadic_delegate_abi : unknown_abi { virtual R invoke(Args const& ...) = 0; }; - template + WINRT_EXPORT template struct variadic_delegate final : variadic_delegate_abi, implements_delegate_base, H, update_module_lock { variadic_delegate(H&& handler) : H(std::forward(handler)) @@ -156,7 +156,7 @@ WINRT_EXPORT namespace winrt::impl } }; - template + WINRT_EXPORT template struct WINRT_IMPL_EMPTY_BASES delegate_base : Windows::Foundation::IUnknown { delegate_base(std::nullptr_t = nullptr) noexcept {} @@ -220,9 +220,9 @@ WINRT_EXPORT namespace winrt::impl #endif } -WINRT_EXPORT namespace winrt +extern "C++" namespace winrt { - template + WINRT_EXPORT template struct WINRT_IMPL_EMPTY_BASES delegate : impl::delegate_base { using impl::delegate_base::delegate_base; diff --git a/strings/base_error.h b/strings/base_error.h index 36e1ed588..55aedbeb5 100644 --- a/strings/base_error.h +++ b/strings/base_error.h @@ -7,9 +7,9 @@ #define WINRT_IMPL_RETURNADDRESS() nullptr #endif -WINRT_EXPORT namespace winrt::impl +extern "C++" namespace winrt::impl { - struct heap_traits + WINRT_EXPORT struct heap_traits { using type = wchar_t*; @@ -24,7 +24,7 @@ WINRT_EXPORT namespace winrt::impl } }; - struct bstr_traits + WINRT_EXPORT struct bstr_traits { using type = wchar_t*; @@ -39,9 +39,9 @@ WINRT_EXPORT namespace winrt::impl } }; - using bstr_handle = handle_type; + WINRT_EXPORT using bstr_handle = handle_type; - inline hstring trim_hresult_message(wchar_t const* const message, std::uint32_t size) noexcept + WINRT_EXPORT inline hstring trim_hresult_message(wchar_t const* const message, std::uint32_t size) noexcept { wchar_t const* back = message + size - 1; @@ -54,7 +54,7 @@ WINRT_EXPORT namespace winrt::impl return { message, size }; } - inline hstring message_from_hresult(hresult code) noexcept + WINRT_EXPORT inline hstring message_from_hresult(hresult code) noexcept { handle_type message; @@ -69,20 +69,20 @@ WINRT_EXPORT namespace winrt::impl return trim_hresult_message(message.get(), size); } - constexpr std::int32_t hresult_from_win32(std::uint32_t const x) noexcept + WINRT_EXPORT constexpr std::int32_t hresult_from_win32(std::uint32_t const x) noexcept { return (std::int32_t)(x) <= 0 ? (std::int32_t)(x) : (std::int32_t)(((x) & 0x0000FFFF) | (7 << 16) | 0x80000000); } - constexpr std::int32_t hresult_from_nt(std::uint32_t const x) noexcept + WINRT_EXPORT constexpr std::int32_t hresult_from_nt(std::uint32_t const x) noexcept { return ((std::int32_t)((x) | 0x10000000)); } } -WINRT_EXPORT namespace winrt +extern "C++" namespace winrt { - struct hresult_error + WINRT_EXPORT struct hresult_error { struct no_originate_t {}; static constexpr no_originate_t no_originate{}; @@ -210,9 +210,6 @@ WINRT_EXPORT namespace winrt { WINRT_VERIFY(WINRT_IMPL_RoOriginateLanguageException(code, message, nullptr)); - // This is an extension point that can be filled in by other libraries (such as WIL) to get call outs when errors are - // originated. This is intended for logging purposes. When possible include the std::source_information so that accurate - // information is available on the caller who generated the error. if (winrt_throw_hresult_handler) { winrt_throw_hresult_handler(sourceInformation.line(), sourceInformation.file_name(), sourceInformation.function_name(), WINRT_IMPL_RETURNADDRESS(), code); @@ -245,91 +242,91 @@ WINRT_EXPORT namespace winrt #endif }; - struct hresult_access_denied : hresult_error + WINRT_EXPORT struct hresult_access_denied : hresult_error { hresult_access_denied(winrt::impl::slim_source_location const& sourceInformation = winrt::impl::slim_source_location::current()) noexcept : hresult_error(impl::error_access_denied, sourceInformation) {} hresult_access_denied(param::hstring const& message, winrt::impl::slim_source_location const& sourceInformation = winrt::impl::slim_source_location::current()) noexcept : hresult_error(impl::error_access_denied, message, sourceInformation) {} hresult_access_denied(take_ownership_from_abi_t, winrt::impl::slim_source_location const& sourceInformation = winrt::impl::slim_source_location::current()) noexcept : hresult_error(impl::error_access_denied, take_ownership_from_abi, sourceInformation) {} }; - struct hresult_wrong_thread : hresult_error + WINRT_EXPORT struct hresult_wrong_thread : hresult_error { hresult_wrong_thread(winrt::impl::slim_source_location const& sourceInformation = winrt::impl::slim_source_location::current()) noexcept : hresult_error(impl::error_wrong_thread, sourceInformation) {} hresult_wrong_thread(param::hstring const& message, winrt::impl::slim_source_location const& sourceInformation = winrt::impl::slim_source_location::current()) noexcept : hresult_error(impl::error_wrong_thread, message, sourceInformation) {} hresult_wrong_thread(take_ownership_from_abi_t, winrt::impl::slim_source_location const& sourceInformation = winrt::impl::slim_source_location::current()) noexcept : hresult_error(impl::error_wrong_thread, take_ownership_from_abi, sourceInformation) {} }; - struct hresult_not_implemented : hresult_error + WINRT_EXPORT struct hresult_not_implemented : hresult_error { hresult_not_implemented(winrt::impl::slim_source_location const& sourceInformation = winrt::impl::slim_source_location::current()) noexcept : hresult_error(impl::error_not_implemented, sourceInformation) {} hresult_not_implemented(param::hstring const& message, winrt::impl::slim_source_location const& sourceInformation = winrt::impl::slim_source_location::current()) noexcept : hresult_error(impl::error_not_implemented, message, sourceInformation) {} hresult_not_implemented(take_ownership_from_abi_t, winrt::impl::slim_source_location const& sourceInformation = winrt::impl::slim_source_location::current()) noexcept : hresult_error(impl::error_not_implemented, take_ownership_from_abi, sourceInformation) {} }; - struct hresult_invalid_argument : hresult_error + WINRT_EXPORT struct hresult_invalid_argument : hresult_error { hresult_invalid_argument(winrt::impl::slim_source_location const& sourceInformation = winrt::impl::slim_source_location::current()) noexcept : hresult_error(impl::error_invalid_argument, sourceInformation) {} hresult_invalid_argument(param::hstring const& message, winrt::impl::slim_source_location const& sourceInformation = winrt::impl::slim_source_location::current()) noexcept : hresult_error(impl::error_invalid_argument, message, sourceInformation) {} hresult_invalid_argument(take_ownership_from_abi_t, winrt::impl::slim_source_location const& sourceInformation = winrt::impl::slim_source_location::current()) noexcept : hresult_error(impl::error_invalid_argument, take_ownership_from_abi, sourceInformation) {} }; - struct hresult_out_of_bounds : hresult_error + WINRT_EXPORT struct hresult_out_of_bounds : hresult_error { hresult_out_of_bounds(winrt::impl::slim_source_location const& sourceInformation = winrt::impl::slim_source_location::current()) noexcept : hresult_error(impl::error_out_of_bounds, sourceInformation) {} hresult_out_of_bounds(param::hstring const& message, winrt::impl::slim_source_location const& sourceInformation = winrt::impl::slim_source_location::current()) noexcept : hresult_error(impl::error_out_of_bounds, message, sourceInformation) {} hresult_out_of_bounds(take_ownership_from_abi_t, winrt::impl::slim_source_location const& sourceInformation = winrt::impl::slim_source_location::current()) noexcept : hresult_error(impl::error_out_of_bounds, take_ownership_from_abi, sourceInformation) {} }; - struct hresult_no_interface : hresult_error + WINRT_EXPORT struct hresult_no_interface : hresult_error { hresult_no_interface(winrt::impl::slim_source_location const& sourceInformation = winrt::impl::slim_source_location::current()) noexcept : hresult_error(impl::error_no_interface, sourceInformation) {} hresult_no_interface(param::hstring const& message, winrt::impl::slim_source_location const& sourceInformation = winrt::impl::slim_source_location::current()) noexcept : hresult_error(impl::error_no_interface, message, sourceInformation) {} hresult_no_interface(take_ownership_from_abi_t, winrt::impl::slim_source_location const& sourceInformation = winrt::impl::slim_source_location::current()) noexcept : hresult_error(impl::error_no_interface, take_ownership_from_abi, sourceInformation) {} }; - struct hresult_class_not_available : hresult_error + WINRT_EXPORT struct hresult_class_not_available : hresult_error { hresult_class_not_available(winrt::impl::slim_source_location const& sourceInformation = winrt::impl::slim_source_location::current()) noexcept : hresult_error(impl::error_class_not_available, sourceInformation) {} hresult_class_not_available(param::hstring const& message, winrt::impl::slim_source_location const& sourceInformation = winrt::impl::slim_source_location::current()) noexcept : hresult_error(impl::error_class_not_available, message, sourceInformation) {} hresult_class_not_available(take_ownership_from_abi_t, winrt::impl::slim_source_location const& sourceInformation = winrt::impl::slim_source_location::current()) noexcept : hresult_error(impl::error_class_not_available, take_ownership_from_abi, sourceInformation) {} }; - struct hresult_class_not_registered : hresult_error + WINRT_EXPORT struct hresult_class_not_registered : hresult_error { hresult_class_not_registered(winrt::impl::slim_source_location const& sourceInformation = winrt::impl::slim_source_location::current()) noexcept : hresult_error(impl::error_class_not_registered, sourceInformation) {} hresult_class_not_registered(param::hstring const& message, winrt::impl::slim_source_location const& sourceInformation = winrt::impl::slim_source_location::current()) noexcept : hresult_error(impl::error_class_not_registered, message, sourceInformation) {} hresult_class_not_registered(take_ownership_from_abi_t, winrt::impl::slim_source_location const& sourceInformation = winrt::impl::slim_source_location::current()) noexcept : hresult_error(impl::error_class_not_registered, take_ownership_from_abi, sourceInformation) {} }; - struct hresult_changed_state : hresult_error + WINRT_EXPORT struct hresult_changed_state : hresult_error { hresult_changed_state(winrt::impl::slim_source_location const& sourceInformation = winrt::impl::slim_source_location::current()) noexcept : hresult_error(impl::error_changed_state, sourceInformation) {} hresult_changed_state(param::hstring const& message, winrt::impl::slim_source_location const& sourceInformation = winrt::impl::slim_source_location::current()) noexcept : hresult_error(impl::error_changed_state, message, sourceInformation) {} hresult_changed_state(take_ownership_from_abi_t, winrt::impl::slim_source_location const& sourceInformation = winrt::impl::slim_source_location::current()) noexcept : hresult_error(impl::error_changed_state, take_ownership_from_abi, sourceInformation) {} }; - struct hresult_illegal_method_call : hresult_error + WINRT_EXPORT struct hresult_illegal_method_call : hresult_error { hresult_illegal_method_call(winrt::impl::slim_source_location const& sourceInformation = winrt::impl::slim_source_location::current()) noexcept : hresult_error(impl::error_illegal_method_call, sourceInformation) {} hresult_illegal_method_call(param::hstring const& message, winrt::impl::slim_source_location const& sourceInformation = winrt::impl::slim_source_location::current()) noexcept : hresult_error(impl::error_illegal_method_call, message, sourceInformation) {} hresult_illegal_method_call(take_ownership_from_abi_t, winrt::impl::slim_source_location const& sourceInformation = winrt::impl::slim_source_location::current()) noexcept : hresult_error(impl::error_illegal_method_call, take_ownership_from_abi, sourceInformation) {} }; - struct hresult_illegal_state_change : hresult_error + WINRT_EXPORT struct hresult_illegal_state_change : hresult_error { hresult_illegal_state_change(winrt::impl::slim_source_location const& sourceInformation = winrt::impl::slim_source_location::current()) noexcept : hresult_error(impl::error_illegal_state_change, sourceInformation) {} hresult_illegal_state_change(param::hstring const& message, winrt::impl::slim_source_location const& sourceInformation = winrt::impl::slim_source_location::current()) noexcept : hresult_error(impl::error_illegal_state_change, message, sourceInformation) {} hresult_illegal_state_change(take_ownership_from_abi_t, winrt::impl::slim_source_location const& sourceInformation = winrt::impl::slim_source_location::current()) noexcept : hresult_error(impl::error_illegal_state_change, take_ownership_from_abi, sourceInformation) {} }; - struct hresult_illegal_delegate_assignment : hresult_error + WINRT_EXPORT struct hresult_illegal_delegate_assignment : hresult_error { hresult_illegal_delegate_assignment(winrt::impl::slim_source_location const& sourceInformation = winrt::impl::slim_source_location::current()) noexcept : hresult_error(impl::error_illegal_delegate_assignment, sourceInformation) {} hresult_illegal_delegate_assignment(param::hstring const& message, winrt::impl::slim_source_location const& sourceInformation = winrt::impl::slim_source_location::current()) noexcept : hresult_error(impl::error_illegal_delegate_assignment, message, sourceInformation) {} hresult_illegal_delegate_assignment(take_ownership_from_abi_t, winrt::impl::slim_source_location const& sourceInformation = winrt::impl::slim_source_location::current()) noexcept : hresult_error(impl::error_illegal_delegate_assignment, take_ownership_from_abi, sourceInformation) {} }; - struct hresult_canceled : hresult_error + WINRT_EXPORT struct hresult_canceled : hresult_error { hresult_canceled(winrt::impl::slim_source_location const& sourceInformation = winrt::impl::slim_source_location::current()) noexcept : hresult_error(impl::error_canceled, sourceInformation) {} hresult_canceled(hresult_error::no_originate_t) noexcept : hresult_error(impl::error_canceled, hresult_error::no_originate) {} @@ -337,7 +334,7 @@ WINRT_EXPORT namespace winrt hresult_canceled(take_ownership_from_abi_t, winrt::impl::slim_source_location const& sourceInformation = winrt::impl::slim_source_location::current()) noexcept : hresult_error(impl::error_canceled, take_ownership_from_abi, sourceInformation) {} }; - [[noreturn]] inline WINRT_IMPL_NOINLINE void throw_hresult(hresult const result, winrt::impl::slim_source_location const& sourceInformation = winrt::impl::slim_source_location::current()) + WINRT_EXPORT [[noreturn]] inline WINRT_IMPL_NOINLINE void throw_hresult(hresult const result, winrt::impl::slim_source_location const& sourceInformation = winrt::impl::slim_source_location::current()) { if (winrt_throw_hresult_handler) { @@ -417,7 +414,7 @@ WINRT_EXPORT namespace winrt throw hresult_error(result, take_ownership_from_abi, sourceInformation); } - inline WINRT_IMPL_NOINLINE hresult to_hresult() noexcept + WINRT_EXPORT inline WINRT_IMPL_NOINLINE hresult to_hresult() noexcept { if (winrt_to_hresult_handler) { @@ -450,7 +447,7 @@ WINRT_EXPORT namespace winrt } } - inline WINRT_IMPL_NOINLINE hstring to_message() + WINRT_EXPORT inline WINRT_IMPL_NOINLINE hstring to_message() { if (winrt_to_message_handler) { @@ -475,12 +472,12 @@ WINRT_EXPORT namespace winrt } } - [[noreturn]] inline void throw_last_error(winrt::impl::slim_source_location const& sourceInformation = winrt::impl::slim_source_location::current()) + WINRT_EXPORT [[noreturn]] inline void throw_last_error(winrt::impl::slim_source_location const& sourceInformation = winrt::impl::slim_source_location::current()) { throw_hresult(impl::hresult_from_win32(WINRT_IMPL_GetLastError()), sourceInformation); } - inline hresult check_hresult(hresult const result, winrt::impl::slim_source_location const& sourceInformation) + WINRT_EXPORT inline hresult check_hresult(hresult const result, winrt::impl::slim_source_location const& sourceInformation) { if (result < 0) { @@ -489,7 +486,7 @@ WINRT_EXPORT namespace winrt return result; } - template + WINRT_EXPORT template void check_nt(T result, winrt::impl::slim_source_location const& sourceInformation = winrt::impl::slim_source_location::current()) { if (result != 0) @@ -498,7 +495,7 @@ WINRT_EXPORT namespace winrt } } - template + WINRT_EXPORT template void check_win32(T result, winrt::impl::slim_source_location const& sourceInformation = winrt::impl::slim_source_location::current()) { if (result != 0) @@ -507,7 +504,7 @@ WINRT_EXPORT namespace winrt } } - template + WINRT_EXPORT template T check_bool(T result, winrt::impl::slim_source_location const& sourceInformation = winrt::impl::slim_source_location::current()) { if (!result) @@ -518,7 +515,7 @@ WINRT_EXPORT namespace winrt return result; } - template + WINRT_EXPORT template T* check_pointer(T* pointer, winrt::impl::slim_source_location const& sourceInformation = winrt::impl::slim_source_location::current()) { if (!pointer) @@ -529,16 +526,16 @@ WINRT_EXPORT namespace winrt return pointer; } - [[noreturn]] inline void terminate() noexcept + WINRT_EXPORT [[noreturn]] inline void terminate() noexcept { WINRT_IMPL_RoFailFastWithErrorContext(to_hresult()); std::abort(); } } -WINRT_EXPORT namespace winrt::impl +extern "C++" namespace winrt::impl { - inline hresult check_hresult_allow_bounds(hresult const result, winrt::impl::slim_source_location const& sourceInformation = winrt::impl::slim_source_location::current()) + WINRT_EXPORT inline hresult check_hresult_allow_bounds(hresult const result, winrt::impl::slim_source_location const& sourceInformation = winrt::impl::slim_source_location::current()) { if (result != impl::error_out_of_bounds && result != impl::error_fail && result != impl::error_file_not_found) { diff --git a/strings/base_events.h b/strings/base_events.h index 0855f4614..023935d73 100644 --- a/strings/base_events.h +++ b/strings/base_events.h @@ -1,7 +1,7 @@ -WINRT_EXPORT namespace winrt +extern "C++" namespace winrt { - struct event_token + WINRT_EXPORT struct event_token { std::int64_t value{}; @@ -13,10 +13,10 @@ WINRT_EXPORT namespace winrt bool operator==(event_token const& other) const noexcept = default; }; - struct auto_revoke_t {}; - inline constexpr auto_revoke_t auto_revoke{}; + WINRT_EXPORT struct auto_revoke_t {}; + WINRT_EXPORT inline constexpr auto_revoke_t auto_revoke{}; - template + WINRT_EXPORT template struct event_revoker { using method_type = std::int32_t(__stdcall impl::abi_t::*)(winrt::event_token); @@ -71,7 +71,7 @@ WINRT_EXPORT namespace winrt event_token m_token{}; }; - template + WINRT_EXPORT template struct factory_event_revoker { using method_type = std::int32_t(__stdcall impl::abi_t::*)(winrt::event_token); @@ -127,9 +127,9 @@ WINRT_EXPORT namespace winrt }; } -WINRT_EXPORT namespace winrt::impl +extern "C++" namespace winrt::impl { - template + WINRT_EXPORT template struct event_revoker { event_revoker() noexcept = default; @@ -190,7 +190,7 @@ WINRT_EXPORT namespace winrt::impl event_token m_token{}; }; - template + WINRT_EXPORT template struct factory_event_revoker { factory_event_revoker() noexcept = default; @@ -250,13 +250,13 @@ WINRT_EXPORT namespace winrt::impl event_token m_token{}; }; - template + WINRT_EXPORT template Revoker make_event_revoker(S source, event_token token) { return { static_cast(*source), token }; } - template + WINRT_EXPORT template struct event_array { using value_type = T; @@ -324,7 +324,7 @@ WINRT_EXPORT namespace winrt::impl std::uint32_t m_size{ 0 }; }; - template + WINRT_EXPORT template com_ptr> make_event_array(std::uint32_t const capacity) { void* raw = ::operator new(sizeof(event_array) + (sizeof(T)* capacity)); @@ -334,7 +334,7 @@ WINRT_EXPORT namespace winrt::impl return { new(raw) event_array(capacity), take_ownership_from_abi }; } - WINRT_IMPL_NOINLINE inline bool report_failed_invoke() + WINRT_EXPORT WINRT_IMPL_NOINLINE inline bool report_failed_invoke() { std::int32_t const code = to_hresult(); WINRT_IMPL_RoTransformError(code, 0, nullptr); @@ -349,7 +349,7 @@ WINRT_EXPORT namespace winrt::impl return true; } - template + WINRT_EXPORT template bool invoke(Delegate const& delegate, Arg const&... args) noexcept { try @@ -365,9 +365,9 @@ WINRT_EXPORT namespace winrt::impl } } -WINRT_EXPORT namespace winrt +extern "C++" namespace winrt { - template + WINRT_EXPORT template struct event { using delegate_type = Delegate; diff --git a/strings/base_extern.h b/strings/base_extern.h index 25c25e9d2..0d6ccfb2c 100644 --- a/strings/base_extern.h +++ b/strings/base_extern.h @@ -1,8 +1,8 @@ -WINRT_EXPORT __declspec(selectany) std::int32_t(__stdcall* winrt_to_hresult_handler)(void* address) noexcept {}; -WINRT_EXPORT __declspec(selectany) winrt::hstring(__stdcall* winrt_to_message_handler)(void* address) {}; -WINRT_EXPORT __declspec(selectany) void(__stdcall* winrt_throw_hresult_handler)(std::uint32_t lineNumber, char const* fileName, char const* functionName, void* returnAddress, winrt::hresult const result) noexcept {}; -WINRT_EXPORT __declspec(selectany) std::int32_t(__stdcall* winrt_activation_handler)(void* classId, winrt::guid const& iid, void** factory) noexcept {}; +extern "C++" __declspec(selectany) std::int32_t(__stdcall* winrt_to_hresult_handler)(void* address) noexcept {}; +extern "C++" __declspec(selectany) winrt::hstring(__stdcall* winrt_to_message_handler)(void* address) {}; +extern "C++" __declspec(selectany) void(__stdcall* winrt_throw_hresult_handler)(std::uint32_t lineNumber, char const* fileName, char const* functionName, void* returnAddress, winrt::hresult const result) noexcept {}; +extern "C++" __declspec(selectany) std::int32_t(__stdcall* winrt_activation_handler)(void* classId, winrt::guid const& iid, void** factory) noexcept {}; #if defined(_MSC_VER) #ifdef _M_HYBRID diff --git a/strings/base_fast_forward.h b/strings/base_fast_forward.h index a5954298c..2ec43d223 100644 --- a/strings/base_fast_forward.h +++ b/strings/base_fast_forward.h @@ -1,3 +1,4 @@ + #include #include @@ -28,7 +29,7 @@ static_assert(WINRT_FAST_ABI_SIZE >= %); #pragma detect_mismatch("WINRT_FAST_ABI_SIZE", WINRT_IMPL_STRING(WINRT_FAST_ABI_SIZE)) -namespace winrt::impl +extern "C++" namespace winrt::impl { // Thunk definitions are in arch-specific assembly sources % @@ -138,7 +139,7 @@ namespace winrt::impl static_assert(offsetof(fast_abi_forwarder, m_offset) == sizeof(fast_abi_forwarder::m_vfptr) + sizeof(fast_abi_forwarder::m_owner)); } -namespace winrt +extern "C++" namespace winrt { template auto make_fast_abi_forwarder(void* owner, TGuid const& guid, std::size_t offset) diff --git a/strings/base_foundation.h b/strings/base_foundation.h index 52a02ecd7..d9741c3d1 100644 --- a/strings/base_foundation.h +++ b/strings/base_foundation.h @@ -1,7 +1,7 @@ -WINRT_EXPORT namespace winrt::Windows::Foundation +extern "C++" namespace winrt::Windows::Foundation { - struct Point + WINRT_EXPORT struct Point { float X; float Y; @@ -28,7 +28,7 @@ WINRT_EXPORT namespace winrt::Windows::Foundation constexpr bool operator==(Point const&) const noexcept = default; }; - struct Size + WINRT_EXPORT struct Size { float Width; float Height; @@ -55,7 +55,7 @@ WINRT_EXPORT namespace winrt::Windows::Foundation constexpr bool operator==(Size const&) const noexcept = default; }; - struct Rect + WINRT_EXPORT struct Rect { float X; float Y; @@ -76,7 +76,7 @@ WINRT_EXPORT namespace winrt::Windows::Foundation }; } -WINRT_EXPORT namespace winrt::impl +extern "C++" namespace winrt::impl { template <> inline constexpr auto& name_v = L"Windows.Foundation.Point"; template <> inline constexpr auto& name_v = L"Windows.Foundation.Size"; diff --git a/strings/base_handle.h b/strings/base_handle.h index 7a65af7b3..9c3a983e6 100644 --- a/strings/base_handle.h +++ b/strings/base_handle.h @@ -1,7 +1,7 @@ -WINRT_EXPORT namespace winrt +extern "C++" namespace winrt { - template + WINRT_EXPORT template struct handle_type { using type = typename T::type; @@ -79,7 +79,7 @@ WINRT_EXPORT namespace winrt type m_value = T::invalid(); }; - struct handle_traits + WINRT_EXPORT struct handle_traits { using type = void*; @@ -94,9 +94,9 @@ WINRT_EXPORT namespace winrt } }; - using handle = handle_type; + WINRT_EXPORT using handle = handle_type; - struct file_handle_traits + WINRT_EXPORT struct file_handle_traits { using type = void*; @@ -111,5 +111,5 @@ WINRT_EXPORT namespace winrt } }; - using file_handle = handle_type; + WINRT_EXPORT using file_handle = handle_type; } diff --git a/strings/base_identity.h b/strings/base_identity.h index 8120a2fbf..48950975c 100644 --- a/strings/base_identity.h +++ b/strings/base_identity.h @@ -1,16 +1,16 @@ WINRT_EXPORT namespace winrt { - template + WINRT_EXPORT template using default_interface = typename impl::default_interface::type; - template + WINRT_EXPORT template constexpr guid const& guid_of() noexcept { return impl::guid_v>; } - template + WINRT_EXPORT template bool is_guid_of(guid const& id) noexcept { return ((id == guid_of()) || ...); @@ -19,31 +19,31 @@ WINRT_EXPORT namespace winrt WINRT_EXPORT namespace winrt::impl { - template + WINRT_EXPORT template constexpr std::array to_array(T const* value, std::index_sequence const) noexcept { return { value[Index]... }; } - template + WINRT_EXPORT template constexpr auto to_array(std::array const& value) noexcept { return value; } - template + WINRT_EXPORT template constexpr auto to_array(char const(&value)[Size]) noexcept { return to_array(value, std::make_index_sequence()); } - template + WINRT_EXPORT template constexpr auto to_array(wchar_t const(&value)[Size]) noexcept { return to_array(value, std::make_index_sequence()); } - template + WINRT_EXPORT template constexpr std::array concat( [[maybe_unused]] std::array const& left, [[maybe_unused]] std::array const& right, @@ -53,37 +53,37 @@ WINRT_EXPORT namespace winrt::impl return { left[LeftIndex]..., right[RightIndex]... }; } - template + WINRT_EXPORT template constexpr auto concat(std::array const& left, std::array const& right) noexcept { return concat(left, right, std::make_index_sequence(), std::make_index_sequence()); } - template + WINRT_EXPORT template constexpr auto concat(std::array const& left, T const(&right)[RightSize]) noexcept { return concat(left, to_array(right)); } - template + WINRT_EXPORT template constexpr auto concat(T const(&left)[LeftSize], std::array const& right) noexcept { return concat(to_array(left), right); } - template + WINRT_EXPORT template constexpr auto concat(std::array const& left, T const right) noexcept { return concat(left, std::array{right}); } - template + WINRT_EXPORT template constexpr auto concat(T const left, std::array const& right) noexcept { return concat(std::array{left}, right); } - template + WINRT_EXPORT template constexpr auto combine(First const& first, Rest const&... rest) noexcept { if constexpr (sizeof...(rest) == 0) @@ -96,37 +96,37 @@ WINRT_EXPORT namespace winrt::impl } } - template + WINRT_EXPORT template constexpr std::array zconcat_base(std::array const& left, std::array const& right, std::index_sequence const, std::index_sequence const) noexcept { return { left[LI]..., right[RI]..., T{} }; } - template + WINRT_EXPORT template constexpr auto zconcat(std::array const& left, std::array const& right) noexcept { return zconcat_base(left, right, std::make_index_sequence(), std::make_index_sequence()); } - template + WINRT_EXPORT template constexpr std::array to_zarray_base(T const(&value)[S], std::index_sequence const) noexcept { return { value[I]... }; } - template + WINRT_EXPORT template constexpr auto to_zarray(T const(&value)[S]) noexcept { return to_zarray_base(value, std::make_index_sequence()); } - template + WINRT_EXPORT template constexpr auto to_zarray(std::array const& value) noexcept { return value; } - template + WINRT_EXPORT template constexpr auto zcombine(First const& first, Rest const&... rest) noexcept { if constexpr (sizeof...(rest) == 0) @@ -139,48 +139,48 @@ WINRT_EXPORT namespace winrt::impl } } - constexpr std::array to_array(std::uint32_t value) noexcept + WINRT_EXPORT constexpr std::array to_array(std::uint32_t value) noexcept { return { static_cast(value & 0x000000ff), static_cast((value & 0x0000ff00) >> 8), static_cast((value & 0x00ff0000) >> 16), static_cast((value & 0xff000000) >> 24) }; } - constexpr std::array to_array(std::uint16_t value) noexcept + WINRT_EXPORT constexpr std::array to_array(std::uint16_t value) noexcept { return { static_cast(value & 0x00ff), static_cast((value & 0xff00) >> 8) }; } - constexpr auto to_array(guid const& value) noexcept + WINRT_EXPORT constexpr auto to_array(guid const& value) noexcept { return combine(to_array(value.Data1), to_array(value.Data2), to_array(value.Data3), std::array{ value.Data4[0], value.Data4[1], value.Data4[2], value.Data4[3], value.Data4[4], value.Data4[5], value.Data4[6], value.Data4[7] }); } - template + WINRT_EXPORT template constexpr T to_hex_digit(std::uint8_t value) noexcept { value &= 0xF; return value < 10 ? static_cast('0') + value : static_cast('a') + (value - 10); } - template + WINRT_EXPORT template constexpr std::array uint8_to_hex(std::uint8_t const value) noexcept { return { to_hex_digit(value >> 4), to_hex_digit(value & 0xF) }; } - template + WINRT_EXPORT template constexpr auto uint16_to_hex(std::uint16_t value) noexcept { return combine(uint8_to_hex(static_cast(value >> 8)), uint8_to_hex(value & 0xFF)); } - template + WINRT_EXPORT template constexpr auto uint32_to_hex(std::uint32_t const value) noexcept { return combine(uint16_to_hex(value >> 16), uint16_to_hex(value & 0xFFFF)); } - template + WINRT_EXPORT template constexpr auto to_array(guid const& value) noexcept { return combine @@ -197,17 +197,17 @@ WINRT_EXPORT namespace winrt::impl ); } - constexpr std::uint32_t to_guid(std::uint8_t a, std::uint8_t b, std::uint8_t c, std::uint8_t d) noexcept + WINRT_EXPORT constexpr std::uint32_t to_guid(std::uint8_t a, std::uint8_t b, std::uint8_t c, std::uint8_t d) noexcept { return (static_cast(d) << 24) | (static_cast(c) << 16) | (static_cast(b) << 8) | static_cast(a); } - constexpr std::uint16_t to_guid(std::uint8_t a, std::uint8_t b) noexcept + WINRT_EXPORT constexpr std::uint16_t to_guid(std::uint8_t a, std::uint8_t b) noexcept { return (static_cast(b) << 8) | static_cast(a); } - template + WINRT_EXPORT template constexpr guid to_guid(std::array const& arr) noexcept { return @@ -219,17 +219,17 @@ WINRT_EXPORT namespace winrt::impl }; } - constexpr std::uint32_t endian_swap(std::uint32_t value) noexcept + WINRT_EXPORT constexpr std::uint32_t endian_swap(std::uint32_t value) noexcept { return (value & 0xFF000000) >> 24 | (value & 0x00FF0000) >> 8 | (value & 0x0000FF00) << 8 | (value & 0x000000FF) << 24; } - constexpr std::uint16_t endian_swap(std::uint16_t value) noexcept + WINRT_EXPORT constexpr std::uint16_t endian_swap(std::uint16_t value) noexcept { return (value & 0xFF00) >> 8 | (value & 0x00FF) << 8; } - constexpr guid endian_swap(guid value) noexcept + WINRT_EXPORT constexpr guid endian_swap(guid value) noexcept { value.Data1 = endian_swap(value.Data1); value.Data2 = endian_swap(value.Data2); @@ -237,40 +237,40 @@ WINRT_EXPORT namespace winrt::impl return value; } - constexpr guid set_named_guid_fields(guid value) noexcept + WINRT_EXPORT constexpr guid set_named_guid_fields(guid value) noexcept { value.Data3 = static_cast((value.Data3 & 0x0fff) | (5 << 12)); value.Data4[0] = static_cast((value.Data4[0] & 0x3f) | 0x80); return value; } - template + WINRT_EXPORT template constexpr std::array char_to_byte_array(std::array const& value, std::index_sequence const) noexcept { return { static_cast(value[Index])... }; } - constexpr auto sha1_rotl(std::uint8_t bits, std::uint32_t word) noexcept + WINRT_EXPORT constexpr auto sha1_rotl(std::uint8_t bits, std::uint32_t word) noexcept { return (word << bits) | (word >> (32 - bits)); } - constexpr auto sha_ch(std::uint32_t x, std::uint32_t y, std::uint32_t z) noexcept + WINRT_EXPORT constexpr auto sha_ch(std::uint32_t x, std::uint32_t y, std::uint32_t z) noexcept { return (x & y) ^ ((~x) & z); } - constexpr auto sha_parity(std::uint32_t x, std::uint32_t y, std::uint32_t z) noexcept + WINRT_EXPORT constexpr auto sha_parity(std::uint32_t x, std::uint32_t y, std::uint32_t z) noexcept { return x ^ y ^ z; } - constexpr auto sha_maj(std::uint32_t x, std::uint32_t y, std::uint32_t z) noexcept + WINRT_EXPORT constexpr auto sha_maj(std::uint32_t x, std::uint32_t y, std::uint32_t z) noexcept { return (x & y) ^ (x & z) ^ (y & z); } - constexpr std::array process_msg_block(std::uint8_t const* input, std::size_t start_pos, std::array const& intermediate_hash) noexcept + WINRT_EXPORT constexpr std::array process_msg_block(std::uint8_t const* input, std::size_t start_pos, std::array const& intermediate_hash) noexcept { std::uint32_t const K[4] = { 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xCA62C1D6 }; std::array W = {}; @@ -340,13 +340,13 @@ WINRT_EXPORT namespace winrt::impl return { intermediate_hash[0] + A, intermediate_hash[1] + B, intermediate_hash[2] + C, intermediate_hash[3] + D, intermediate_hash[4] + E }; } - template + WINRT_EXPORT template constexpr std::array process_msg_block(std::array const& input, std::size_t start_pos, std::array const& intermediate_hash) noexcept { return process_msg_block(input.data(), start_pos, intermediate_hash); } - constexpr std::array size_to_bytes(std::size_t size) noexcept + WINRT_EXPORT constexpr std::array size_to_bytes(std::size_t size) noexcept { return { @@ -361,20 +361,20 @@ WINRT_EXPORT namespace winrt::impl }; } - template + WINRT_EXPORT template constexpr std::array make_remaining([[maybe_unused]] std::array const& input, [[maybe_unused]] std::size_t start_pos, std::index_sequence) noexcept { return { input[Index + start_pos]..., 0x80 }; } - template + WINRT_EXPORT template constexpr auto make_remaining(std::array const& input, std::size_t start_pos) noexcept { constexpr auto remaining_size = Size % 64; return make_remaining(input, start_pos, std::make_index_sequence()); } - template + WINRT_EXPORT template constexpr auto make_buffer(std::array const& remaining_buffer) noexcept { constexpr auto message_length = (RemainderSize + 8 <= 64) ? 64 : 64 * 2; @@ -386,7 +386,7 @@ WINRT_EXPORT namespace winrt::impl return combine(remaining_buffer, padding_buffer, length_buffer); } - template + WINRT_EXPORT template constexpr std::array finalize_remaining_buffer(std::array const& input, std::array const& intermediate_hash) noexcept { if constexpr (Size == 64) @@ -399,18 +399,18 @@ WINRT_EXPORT namespace winrt::impl } } - template + WINRT_EXPORT template constexpr std::array get_result(std::array const& intermediate_hash, std::index_sequence) noexcept { return { static_cast(intermediate_hash[Index >> 2] >> (8 * (3 - (Index & 0x03))))... }; } - constexpr auto get_result(std::array const& intermediate_hash) noexcept + WINRT_EXPORT constexpr auto get_result(std::array const& intermediate_hash) noexcept { return get_result(intermediate_hash, std::make_index_sequence<20>{}); } - template + WINRT_EXPORT template constexpr auto calculate_sha1(std::array const& input) noexcept { std::array intermediate_hash{ 0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0 }; @@ -426,7 +426,7 @@ WINRT_EXPORT namespace winrt::impl return get_result(intermediate_hash); } - template + WINRT_EXPORT template constexpr guid generate_guid(std::array const& value) noexcept { guid namespace_guid = { 0xd57af411, 0x737b, 0xc042,{ 0xab, 0xae, 0x87, 0x8b, 0x1e, 0x16, 0xad, 0xee } }; @@ -438,7 +438,7 @@ WINRT_EXPORT namespace winrt::impl return set_named_guid_fields(little_endian_guid); } - template + WINRT_EXPORT template struct arg_collection { constexpr static auto data{ combine(to_array(signature::data), ";", arg_collection::data) }; @@ -450,7 +450,7 @@ WINRT_EXPORT namespace winrt::impl constexpr static auto data{ to_array(signature::data) }; }; - template + WINRT_EXPORT template struct pinterface_guid { #ifdef _MSC_VER // T @@ -459,7 +459,7 @@ WINRT_EXPORT namespace winrt::impl static constexpr guid value{ generate_guid(signature::data) }; }; - template + WINRT_EXPORT template #ifdef _MSC_VER // T #pragma warning(suppress: 4307) #endif @@ -472,7 +472,7 @@ WINRT_EXPORT namespace winrt::impl ) }; - constexpr std::size_t to_utf8_size(wchar_t const value) noexcept + WINRT_EXPORT constexpr std::size_t to_utf8_size(wchar_t const value) noexcept { if (value <= 0x7F) { @@ -487,7 +487,7 @@ WINRT_EXPORT namespace winrt::impl return 3; } - constexpr std::size_t to_utf8(wchar_t const value, char* buffer) noexcept + WINRT_EXPORT constexpr std::size_t to_utf8(wchar_t const value, char* buffer) noexcept { if (value <= 0x7F) { @@ -508,7 +508,7 @@ WINRT_EXPORT namespace winrt::impl return 3; } - template + WINRT_EXPORT template constexpr std::size_t to_utf8_size() noexcept { auto input = to_array(name_v); @@ -522,7 +522,7 @@ WINRT_EXPORT namespace winrt::impl return length; } - template + WINRT_EXPORT template constexpr auto to_utf8() noexcept { auto input = to_array(name_v); @@ -537,10 +537,10 @@ WINRT_EXPORT namespace winrt::impl return output; } - template + WINRT_EXPORT template constexpr guid generic_guid_v{}; - template + WINRT_EXPORT template constexpr auto& basic_signature_v = ""; template <> inline constexpr auto& basic_signature_v = "b1"; @@ -642,22 +642,22 @@ WINRT_EXPORT namespace winrt::impl constexpr static auto data{ combine("delegate(", to_array(guid_of()), ")") }; }; - template + WINRT_EXPORT template constexpr std::wstring_view to_wstring_view(std::array const& value) noexcept { return { value.data(), Size - 1 }; } - template + WINRT_EXPORT template constexpr std::wstring_view to_wstring_view(wchar_t const (&value)[Size]) noexcept { return { value, Size - 1 }; } } -WINRT_EXPORT namespace winrt +extern "C++" namespace winrt { - template + WINRT_EXPORT template constexpr auto name_of() noexcept { return impl::to_wstring_view(impl::name_v); diff --git a/strings/base_implements.h b/strings/base_implements.h index c2c514132..4a90ae154 100644 --- a/strings/base_implements.h +++ b/strings/base_implements.h @@ -1,3 +1,4 @@ + #if defined(_MSC_VER) #if defined(_DEBUG) && !defined(WINRT_NO_MAKE_DETECTION) #pragma detect_mismatch("C++/WinRT WINRT_NO_MAKE_DETECTION", "make detection enabled (DEBUG and !WINRT_NO_MAKE_DETECTION)") @@ -6,51 +7,51 @@ #endif #endif -WINRT_EXPORT namespace winrt::impl +extern "C++" namespace winrt::impl { - struct marker + WINRT_EXPORT struct marker { marker() = delete; }; } -WINRT_EXPORT namespace winrt +extern "C++" namespace winrt { - struct non_agile : impl::marker {}; - struct no_weak_ref : impl::marker {}; - struct composing : impl::marker {}; - struct composable : impl::marker {}; - struct no_module_lock : impl::marker {}; - struct static_lifetime : impl::marker {}; - - template + WINRT_EXPORT struct non_agile : impl::marker {}; + WINRT_EXPORT struct no_weak_ref : impl::marker {}; + WINRT_EXPORT struct composing : impl::marker {}; + WINRT_EXPORT struct composable : impl::marker {}; + WINRT_EXPORT struct no_module_lock : impl::marker {}; + WINRT_EXPORT struct static_lifetime : impl::marker {}; + + WINRT_EXPORT template struct cloaked : Interface {}; - template + WINRT_EXPORT template struct implements; } -WINRT_EXPORT namespace winrt::impl +extern "C++" namespace winrt::impl { - template + WINRT_EXPORT template using tuple_cat_t = decltype(std::tuple_cat(std::declval()...)); - template