From 47647bf28485980830eb2b7d50dac5771447645a Mon Sep 17 00:00:00 2001 From: YexuanXiao Date: Sun, 26 Apr 2026 04:45:50 +0800 Subject: [PATCH 1/2] Cleanup WINRT_EXPORT --- cppwinrt/code_writers.h | 13 +++- cppwinrt/file_writers.h | 64 +++++++++++++++++-- strings/base_abi.h | 2 +- strings/base_activation.h | 31 +++++++-- strings/base_agile_ref.h | 14 +++- strings/base_array.h | 19 +++++- strings/base_chrono.h | 10 ++- strings/base_collections.h | 2 +- strings/base_collections_base.h | 12 +++- strings/base_collections_input_iterable.h | 12 +++- strings/base_collections_input_map.h | 11 +++- strings/base_collections_input_map_view.h | 12 +++- strings/base_collections_input_vector.h | 11 +++- strings/base_collections_input_vector_view.h | 12 +++- strings/base_collections_map.h | 19 +++++- strings/base_collections_vector.h | 14 +++- strings/base_com_ptr.h | 18 ++++-- strings/base_composable.h | 10 ++- strings/base_coroutine_foundation.h | 14 ++-- strings/base_coroutine_threadpool.h | 32 +++++++--- strings/base_deferral.h | 9 ++- strings/base_delegate.h | 16 ++++- strings/base_error.h | 42 +++++++++++- strings/base_events.h | 22 ++++++- strings/base_extern.h | 8 +-- strings/base_foundation.h | 13 +++- strings/base_handle.h | 11 +++- strings/base_identity.h | 16 ++++- strings/base_implements.h | 38 +++++++++-- strings/base_iterator.h | 2 +- strings/base_lock.h | 12 +++- strings/base_macros.h | 6 +- strings/base_marshaler.h | 2 +- strings/base_meta.h | 24 ++++++- strings/base_natvis.h | 2 +- strings/base_reference_produce.h | 26 ++++++-- strings/base_reference_produce_1.h | 2 +- strings/base_security.h | 9 ++- strings/base_source_location.h | 2 +- strings/base_std_hash.h | 9 ++- strings/base_string.h | 21 ++++-- strings/base_string_input.h | 16 ++++- strings/base_string_operators.h | 14 +++- strings/base_stringable_streams.h | 18 +++++- strings/base_stringable_to_hstring.h | 9 ++- strings/base_types.h | 22 +++++-- strings/base_version.h | 9 ++- strings/base_weak_ref.h | 10 ++- strings/base_windows.h | 33 ++++++++-- strings/base_xaml_component_connector.h | 9 ++- strings/base_xaml_component_connector_winui.h | 9 ++- strings/base_xaml_typename.h | 17 ++++- 52 files changed, 663 insertions(+), 127 deletions(-) diff --git a/cppwinrt/code_writers.h b/cppwinrt/code_writers.h index f419d97b5..6e31d72ee 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"(namespace std { )"); diff --git a/cppwinrt/file_writers.h b/cppwinrt/file_writers.h index 6f9b4db5d..a06d25037 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 @@ -53,6 +58,11 @@ namespace cppwinrt w.write(strings::base_includes); } + if (settings.modules) + { + w.write("extern \"C++\"\n{\n"); + } + w.write(strings::base_macros); w.write(strings::base_types); w.write(strings::base_extern); @@ -85,8 +95,19 @@ namespace cppwinrt w.write(strings::base_coroutine_threadpool); w.write(strings::base_natvis); w.write(strings::base_version); + + if (settings.modules) + { + w.write("} // extern \"C++\"\n"); + } + + if (settings.modules) + { + w.write("#endif\n"); + } } w.flush_to_file(settings.output_folder + "winrt/base.h"); + } static void write_module_h() @@ -142,7 +163,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,10 +186,14 @@ 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) { get_namespace_module_imports(c, ns, w, module_imports); @@ -353,29 +378,36 @@ export import winrt.numerics; write_module_global_fragment(w); w.write(R"( +// Include in advance so that all of numerics's dependencies can be in the global module fragment +#if __has_include() && __has_include() +#include +#include +#include +#endif + export module winrt.numerics; // Module dependencies: // - (none) -#if __has_include() #ifdef _MSC_VER #pragma warning(push) #pragma warning(disable : 5244) #endif -#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_END_NAMESPACE_ +#if __has_include() && __has_include() #include +#endif #undef _WINDOWS_NUMERICS_NAMESPACE_ #undef _WINDOWS_NUMERICS_BEGIN_NAMESPACE_ #undef _WINDOWS_NUMERICS_END_NAMESPACE_ + #ifdef _MSC_VER #pragma warning(pop) #endif -#endif )"); w.flush_to_file(settings.output_folder + "winrt/winrt.numerics.ixx"); @@ -622,6 +654,11 @@ export import winrt.base; module_imports.clear(); } + if (settings.modules) + { + w.write("} // extern \"C++\"\n"); + } + if (settings.modules) { w.write("#endif\n"); @@ -641,6 +678,12 @@ export import winrt.base; auto wrap_includes_guard = wrap_module_aware_includes_guard(w, settings.modules); write_version_assert(w); + + if (settings.modules) + { + w.write("extern \"C++\"\n{\n"); + } + write_parent_depends(w, c, ns); for (auto&& depends : w.depends) @@ -649,6 +692,17 @@ export import winrt.base; } w.write_depends(w.type_namespace, '2'); + + if (settings.modules) + { + w.write("} // extern \"C++\"\n"); + } + + } + + if (settings.modules) + { + w.write("extern \"C++\"\n{\n"); } w.save_header(); diff --git a/strings/base_abi.h b/strings/base_abi.h index 4b7b8f77f..72946a3fa 100644 --- a/strings/base_abi.h +++ b/strings/base_abi.h @@ -1,5 +1,5 @@ -WINRT_EXPORT namespace winrt::impl +namespace winrt::impl { template <> struct abi { diff --git a/strings/base_activation.h b/strings/base_activation.h index ec4a3e82a..c8d86966c 100644 --- a/strings/base_activation.h +++ b/strings/base_activation.h @@ -1,5 +1,5 @@ -WINRT_EXPORT namespace winrt::impl +namespace winrt::impl { struct library_traits { @@ -103,7 +103,7 @@ WINRT_EXPORT namespace winrt::impl } } -WINRT_EXPORT namespace winrt +namespace winrt { template impl::com_ref get_activation_factory(param::hstring const& name) @@ -114,7 +114,7 @@ WINRT_EXPORT namespace winrt } } -WINRT_EXPORT namespace winrt::impl +namespace winrt::impl { #ifdef __clang__ @@ -422,7 +422,7 @@ WINRT_EXPORT namespace winrt::impl }; } -WINRT_EXPORT namespace winrt +namespace winrt { enum class apartment_type : std::int32_t { @@ -516,7 +516,7 @@ WINRT_EXPORT namespace winrt } } -WINRT_EXPORT namespace winrt::impl +namespace winrt::impl { template T fast_activate(Windows::Foundation::IActivationFactory const& factory) @@ -526,3 +526,24 @@ WINRT_EXPORT namespace winrt::impl return{ result, take_ownership_from_abi }; } } + +#ifdef WINRT_MODULE +export namespace winrt +{ + using winrt::apartment_type; + using winrt::get_activation_factory; + using winrt::try_get_activation_factory; + using winrt::try_create_instance; + using winrt::create_instance; + using winrt::init_apartment; + using winrt::uninit_apartment; + using winrt::clear_factory_cache; +} + +export namespace winrt::impl +{ + using winrt::impl::call_factory; + using winrt::impl::call_factory_cast; + using winrt::impl::fast_activate; +} +#endif diff --git a/strings/base_agile_ref.h b/strings/base_agile_ref.h index af8345037..0f0917d1c 100644 --- a/strings/base_agile_ref.h +++ b/strings/base_agile_ref.h @@ -1,5 +1,5 @@ -WINRT_EXPORT namespace winrt +namespace winrt { #if defined(WINRT_NO_MODULE_LOCK) @@ -47,7 +47,7 @@ WINRT_EXPORT namespace winrt #endif } -WINRT_EXPORT namespace winrt::impl +namespace winrt::impl { template struct module_lock_updater; @@ -82,7 +82,7 @@ WINRT_EXPORT namespace winrt::impl } } -WINRT_EXPORT namespace winrt +namespace winrt { template struct agile_ref @@ -127,3 +127,11 @@ WINRT_EXPORT namespace winrt return object; } } + +#ifdef WINRT_MODULE +export namespace winrt +{ + using winrt::agile_ref; + using winrt::make_agile; +} +#endif diff --git a/strings/base_array.h b/strings/base_array.h index ce536d807..faced65c2 100644 --- a/strings/base_array.h +++ b/strings/base_array.h @@ -1,5 +1,5 @@ -WINRT_EXPORT namespace winrt +namespace winrt { template struct array_view @@ -465,7 +465,7 @@ WINRT_EXPORT namespace winrt } } -WINRT_EXPORT namespace winrt::impl +namespace winrt::impl { template struct array_size_proxy @@ -533,7 +533,7 @@ WINRT_EXPORT namespace winrt::impl }; } -WINRT_EXPORT namespace winrt +namespace winrt { template auto detach_abi(std::uint32_t* __valueSize, impl::arg_out* value) noexcept @@ -562,3 +562,16 @@ WINRT_EXPORT namespace winrt return value; } } + +#ifdef WINRT_MODULE +export namespace winrt +{ + using winrt::array_view; + using winrt::com_array; +} + +export namespace winrt::impl +{ + using winrt::impl::put_size_abi; +} +#endif diff --git a/strings/base_chrono.h b/strings/base_chrono.h index 7934ac5b2..4f4445f40 100644 --- a/strings/base_chrono.h +++ b/strings/base_chrono.h @@ -1,5 +1,5 @@ -WINRT_EXPORT namespace winrt +namespace winrt { struct file_time { @@ -92,3 +92,11 @@ WINRT_EXPORT namespace winrt static constexpr std::chrono::time_point epoch{ std::chrono::seconds{ -11644473600 } }; }; } + +#ifdef WINRT_MODULE +export namespace winrt +{ + using winrt::file_time; + using winrt::clock; +} +#endif diff --git a/strings/base_collections.h b/strings/base_collections.h index 7d8dc2e77..4e1af51eb 100644 --- a/strings/base_collections.h +++ b/strings/base_collections.h @@ -1,5 +1,5 @@ -WINRT_EXPORT namespace winrt::impl +namespace winrt::impl { namespace wfc = Windows::Foundation::Collections; diff --git a/strings/base_collections_base.h b/strings/base_collections_base.h index d107c633e..62b2af4eb 100644 --- a/strings/base_collections_base.h +++ b/strings/base_collections_base.h @@ -1,4 +1,4 @@ -WINRT_EXPORT namespace winrt::impl +namespace winrt::impl { struct nop_lock_guard {}; @@ -79,7 +79,7 @@ WINRT_EXPORT namespace winrt::impl }; } -WINRT_EXPORT namespace winrt +namespace winrt { template struct iterable_base : Version @@ -672,3 +672,11 @@ WINRT_EXPORT namespace winrt }; }; } + +#ifdef WINRT_MODULE +export namespace winrt +{ + using winrt::vector_view_base; + using winrt::iterable_base; +} +#endif \ No newline at end of file diff --git a/strings/base_collections_input_iterable.h b/strings/base_collections_input_iterable.h index 302d403b7..90dbe7127 100644 --- a/strings/base_collections_input_iterable.h +++ b/strings/base_collections_input_iterable.h @@ -1,5 +1,5 @@ -WINRT_EXPORT namespace winrt::impl +namespace winrt::impl { template struct input_iterable : @@ -72,7 +72,7 @@ WINRT_EXPORT namespace winrt::impl } } -WINRT_EXPORT namespace winrt::param +namespace winrt::param { template struct iterable @@ -354,3 +354,11 @@ WINRT_EXPORT namespace winrt::param return *impl::abi_cast(object); } } + +#ifdef WINRT_MODULE +export namespace winrt::param +{ + using winrt::param::iterable; + using winrt::param::async_iterable; +} +#endif diff --git a/strings/base_collections_input_map.h b/strings/base_collections_input_map.h index 7cc8cca9c..929da5faf 100644 --- a/strings/base_collections_input_map.h +++ b/strings/base_collections_input_map.h @@ -1,5 +1,5 @@ -WINRT_EXPORT namespace winrt::impl +namespace winrt::impl { template struct map_impl : @@ -41,7 +41,7 @@ WINRT_EXPORT namespace winrt::impl } } -WINRT_EXPORT namespace winrt::param +namespace winrt::param { template struct map @@ -110,3 +110,10 @@ WINRT_EXPORT namespace winrt::param return *impl::abi_cast(object); } } + +#ifdef WINRT_MODULE +export namespace winrt::param +{ + using winrt::param::map; +} +#endif diff --git a/strings/base_collections_input_map_view.h b/strings/base_collections_input_map_view.h index 43262300f..3b10dcdda 100644 --- a/strings/base_collections_input_map_view.h +++ b/strings/base_collections_input_map_view.h @@ -1,5 +1,5 @@ -WINRT_EXPORT namespace winrt::impl +namespace winrt::impl { template struct input_map_view : @@ -71,7 +71,7 @@ WINRT_EXPORT namespace winrt::impl } } -WINRT_EXPORT namespace winrt::param +namespace winrt::param { template struct map_view @@ -219,3 +219,11 @@ WINRT_EXPORT namespace winrt::param return *impl::abi_cast(object); } } + +#ifdef WINRT_MODULE +export namespace winrt::param +{ + using winrt::param::map_view; + using winrt::param::async_map_view; +} +#endif diff --git a/strings/base_collections_input_vector.h b/strings/base_collections_input_vector.h index 412e591a8..572719c78 100644 --- a/strings/base_collections_input_vector.h +++ b/strings/base_collections_input_vector.h @@ -1,5 +1,5 @@ -WINRT_EXPORT namespace winrt::impl +namespace winrt::impl { template struct vector_impl : @@ -35,7 +35,7 @@ WINRT_EXPORT namespace winrt::impl using input_vector = vector_impl; } -WINRT_EXPORT namespace winrt::param +namespace winrt::param { template struct vector @@ -98,3 +98,10 @@ WINRT_EXPORT namespace winrt::param return *impl::abi_cast(object); } } + +#ifdef WINRT_MODULE +export namespace winrt::param +{ + using winrt::param::vector; +} +#endif diff --git a/strings/base_collections_input_vector_view.h b/strings/base_collections_input_vector_view.h index 0674f384b..d133c05b0 100644 --- a/strings/base_collections_input_vector_view.h +++ b/strings/base_collections_input_vector_view.h @@ -1,5 +1,5 @@ -WINRT_EXPORT namespace winrt::impl +namespace winrt::impl { template struct input_vector_view : @@ -66,7 +66,7 @@ WINRT_EXPORT namespace winrt::impl } } -WINRT_EXPORT namespace winrt::param +namespace winrt::param { template struct vector_view @@ -209,3 +209,11 @@ WINRT_EXPORT namespace winrt::param return *impl::abi_cast(object); } } + +#ifdef WINRT_MODULE +export namespace winrt::param +{ + using winrt::param::vector_view; + using winrt::param::async_vector_view; +} +#endif diff --git a/strings/base_collections_map.h b/strings/base_collections_map.h index b40247dab..6afb6a039 100644 --- a/strings/base_collections_map.h +++ b/strings/base_collections_map.h @@ -1,5 +1,5 @@ -WINRT_EXPORT namespace winrt::impl +namespace winrt::impl { template using multi_threaded_map = map_impl; @@ -41,7 +41,7 @@ WINRT_EXPORT namespace winrt::impl using multi_threaded_observable_map = observable_map_impl; } -WINRT_EXPORT namespace winrt +namespace winrt { template , typename Allocator = std::allocator>> Windows::Foundation::Collections::IMap single_threaded_map() @@ -148,3 +148,18 @@ namespace winrt::Windows::Foundation::Collections } } } + +#ifdef WINRT_MODULE +export namespace winrt +{ + using winrt::single_threaded_map; + using winrt::multi_threaded_map; + using winrt::single_threaded_observable_map; + using winrt::multi_threaded_observable_map; +} + +export namespace winrt::Windows::Foundation::Collections +{ + using winrt::Windows::Foundation::Collections::get; +} +#endif diff --git a/strings/base_collections_vector.h b/strings/base_collections_vector.h index 3388806af..eef6f5fac 100644 --- a/strings/base_collections_vector.h +++ b/strings/base_collections_vector.h @@ -1,5 +1,5 @@ -WINRT_EXPORT namespace winrt::impl +namespace winrt::impl { template using multi_threaded_vector = vector_impl; @@ -297,7 +297,7 @@ WINRT_EXPORT namespace winrt::impl using multi_threaded_convertible_observable_vector = convertible_observable_vector; } -WINRT_EXPORT namespace winrt +namespace winrt { template > Windows::Foundation::Collections::IVector single_threaded_vector(std::vector&& values = {}) @@ -337,3 +337,13 @@ WINRT_EXPORT namespace winrt } } } + +#ifdef WINRT_MODULE +export namespace winrt +{ + using winrt::single_threaded_vector; + using winrt::multi_threaded_vector; + using winrt::single_threaded_observable_vector; + using winrt::multi_threaded_observable_vector; +} +#endif diff --git a/strings/base_com_ptr.h b/strings/base_com_ptr.h index 1925bf5df..96ece251a 100644 --- a/strings/base_com_ptr.h +++ b/strings/base_com_ptr.h @@ -1,11 +1,11 @@ -WINRT_EXPORT namespace winrt +namespace winrt { template struct com_ptr; } -WINRT_EXPORT namespace winrt::impl +namespace winrt::impl { struct capture_decay { @@ -35,7 +35,7 @@ WINRT_EXPORT namespace winrt::impl std::int32_t capture_to(void** result, com_ptr const& object, M method, Args&& ...args); } -WINRT_EXPORT namespace winrt +namespace winrt { template struct com_ptr @@ -303,7 +303,7 @@ WINRT_EXPORT namespace winrt } } -WINRT_EXPORT namespace winrt::impl +namespace winrt::impl { template std::int32_t capture_to(void** result, com_ptr const& object, M method, Args&& ...args) @@ -317,3 +317,13 @@ void** IID_PPV_ARGS_Helper(winrt::com_ptr* ptr) noexcept { return winrt::put_abi(*ptr); } + +#ifdef WINRT_MODULE +export namespace winrt +{ + using winrt::com_ptr; + using winrt::capture; + using winrt::try_capture; + using winrt::get_self; +} +#endif diff --git a/strings/base_composable.h b/strings/base_composable.h index a6d5da179..aee82a030 100644 --- a/strings/base_composable.h +++ b/strings/base_composable.h @@ -1,5 +1,5 @@ -WINRT_EXPORT namespace winrt::impl +namespace winrt::impl { template struct composable_factory @@ -85,3 +85,11 @@ WINRT_EXPORT namespace winrt::impl } }; } + +#ifdef WINRT_MODULE +export namespace winrt::impl +{ + using winrt::impl::composable_factory; + using winrt::impl::dispatch_to_overridable; +} +#endif diff --git a/strings/base_coroutine_foundation.h b/strings/base_coroutine_foundation.h index db8e299a4..564c07dee 100644 --- a/strings/base_coroutine_foundation.h +++ b/strings/base_coroutine_foundation.h @@ -1,5 +1,5 @@ -WINRT_EXPORT namespace winrt::impl +namespace winrt::impl { template struct async_completed_handler; @@ -257,7 +257,7 @@ WINRT_EXPORT namespace winrt::impl } } -WINRT_EXPORT namespace winrt +namespace winrt { template requires std::convertible_to @@ -267,7 +267,7 @@ WINRT_EXPORT namespace winrt }; } -WINRT_EXPORT namespace winrt::Windows::Foundation +namespace winrt::Windows::Foundation { inline impl::await_adapter operator co_await(IAsyncAction const& async) { @@ -293,7 +293,7 @@ WINRT_EXPORT namespace winrt::Windows::Foundation } } -WINRT_EXPORT namespace winrt +namespace winrt { struct get_progress_token_t {}; @@ -310,7 +310,7 @@ WINRT_EXPORT namespace winrt } } -WINRT_EXPORT namespace winrt::impl +namespace winrt::impl { template struct cancellation_token @@ -702,7 +702,7 @@ WINRT_EXPORT namespace winrt::impl }; } -WINRT_EXPORT namespace std +namespace std { template struct coroutine_traits @@ -835,7 +835,7 @@ WINRT_EXPORT namespace std }; } -WINRT_EXPORT namespace winrt +namespace winrt { template Windows::Foundation::IAsyncAction when_all(T... async) diff --git a/strings/base_coroutine_threadpool.h b/strings/base_coroutine_threadpool.h index 6daba71ef..b269abe22 100644 --- a/strings/base_coroutine_threadpool.h +++ b/strings/base_coroutine_threadpool.h @@ -1,5 +1,5 @@ -WINRT_EXPORT namespace winrt::impl +namespace winrt::impl { inline auto submit_threadpool_callback(void(__stdcall* callback)(void*, void* context), void* context) { @@ -144,7 +144,7 @@ WINRT_EXPORT namespace winrt::impl }; } -WINRT_EXPORT namespace winrt +namespace winrt { struct cancellable_promise { @@ -242,7 +242,7 @@ WINRT_EXPORT namespace winrt }; } -WINRT_EXPORT namespace winrt +namespace winrt { [[nodiscard]] inline auto resume_background() noexcept { @@ -322,7 +322,7 @@ WINRT_EXPORT namespace winrt }; } -WINRT_EXPORT namespace winrt::impl +namespace winrt::impl { struct apartment_awaiter { @@ -567,7 +567,7 @@ WINRT_EXPORT namespace winrt::impl }; } -WINRT_EXPORT namespace winrt +namespace winrt { inline impl::apartment_awaiter operator co_await(apartment_context const& context) { @@ -672,7 +672,7 @@ WINRT_EXPORT namespace winrt struct fire_and_forget {}; } -WINRT_EXPORT namespace std +namespace std { template struct coroutine_traits @@ -706,7 +706,7 @@ WINRT_EXPORT namespace std }; } -WINRT_EXPORT namespace winrt::impl +namespace winrt::impl { struct dispatched_handler_state { @@ -756,7 +756,7 @@ WINRT_EXPORT namespace winrt::impl }; } -WINRT_EXPORT namespace winrt +namespace winrt { template struct dispatcher_traits; @@ -820,3 +820,19 @@ WINRT_EXPORT namespace winrt return resume_foreground(dispatcher); } } + +#ifdef WINRT_MODULE +export namespace winrt +{ + using winrt::apartment_context; + using winrt::thread_pool; + using winrt::fire_and_forget; + using winrt::cancellable_promise; + using winrt::cancellable_awaiter; + using winrt::dispatcher_traits; + using winrt::resume_background; + using winrt::resume_after; + using winrt::resume_on_signal; + using winrt::resume_foreground; +} +#endif diff --git a/strings/base_deferral.h b/strings/base_deferral.h index 702cf3a32..7399d2961 100644 --- a/strings/base_deferral.h +++ b/strings/base_deferral.h @@ -1,5 +1,5 @@ -WINRT_EXPORT namespace winrt +namespace winrt { template struct deferrable_event_args @@ -71,3 +71,10 @@ WINRT_EXPORT namespace winrt std::coroutine_handle<> m_handle = nullptr; }; } + +#ifdef WINRT_MODULE +export namespace winrt +{ + using winrt::deferrable_event_args; +} +#endif \ No newline at end of file diff --git a/strings/base_delegate.h b/strings/base_delegate.h index 5d3c1b722..5dc8e3bee 100644 --- a/strings/base_delegate.h +++ b/strings/base_delegate.h @@ -1,5 +1,5 @@ -WINRT_EXPORT namespace winrt::impl +namespace winrt::impl { #if defined(_MSC_VER) && !defined(__clang__) #pragma warning(push) @@ -220,7 +220,7 @@ WINRT_EXPORT namespace winrt::impl #endif } -WINRT_EXPORT namespace winrt +namespace winrt { template struct WINRT_IMPL_EMPTY_BASES delegate : impl::delegate_base @@ -234,3 +234,15 @@ WINRT_EXPORT namespace winrt using impl::delegate_base::delegate_base; }; } + +#ifdef WINRT_MODULE +export namespace winrt +{ + using winrt::delegate; +} + +export namespace winrt::impl +{ + using winrt::impl::make_delegate; +} +#endif diff --git a/strings/base_error.h b/strings/base_error.h index 54e4ebc97..d73e8fbea 100644 --- a/strings/base_error.h +++ b/strings/base_error.h @@ -7,7 +7,7 @@ #define WINRT_IMPL_RETURNADDRESS() nullptr #endif -WINRT_EXPORT namespace winrt::impl +namespace winrt::impl { struct heap_traits { @@ -80,7 +80,7 @@ WINRT_EXPORT namespace winrt::impl } } -WINRT_EXPORT namespace winrt +namespace winrt { struct hresult_error { @@ -548,7 +548,7 @@ WINRT_EXPORT namespace winrt } } -WINRT_EXPORT namespace winrt::impl +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()) { @@ -561,3 +561,39 @@ WINRT_EXPORT namespace winrt::impl } #undef WINRT_IMPL_RETURNADDRESS + +#ifdef WINRT_MODULE +export namespace winrt +{ + using winrt::hresult_error; + using winrt::hresult_access_denied; + using winrt::hresult_wrong_thread; + using winrt::hresult_not_implemented; + using winrt::hresult_invalid_argument; + using winrt::hresult_out_of_bounds; + using winrt::hresult_no_interface; + using winrt::hresult_class_not_available; + using winrt::hresult_class_not_registered; + using winrt::hresult_changed_state; + using winrt::hresult_illegal_method_call; + using winrt::hresult_illegal_state_change; + using winrt::hresult_illegal_delegate_assignment; + using winrt::hresult_no_task_queue; + using winrt::hresult_canceled; + using winrt::check_hresult; + using winrt::to_hresult; + using winrt::to_message; + using winrt::throw_hresult; + using winrt::throw_last_error; + using winrt::terminate; + using winrt::check_nt; + using winrt::check_win32; + using winrt::check_bool; + using winrt::check_pointer; +} + +export namespace winrt::impl +{ + using winrt::impl::check_hresult_allow_bounds; +} +#endif diff --git a/strings/base_events.h b/strings/base_events.h index 0855f4614..b018202b4 100644 --- a/strings/base_events.h +++ b/strings/base_events.h @@ -1,5 +1,5 @@ -WINRT_EXPORT namespace winrt +namespace winrt { struct event_token { @@ -127,7 +127,7 @@ WINRT_EXPORT namespace winrt }; } -WINRT_EXPORT namespace winrt::impl +namespace winrt::impl { template struct event_revoker @@ -365,7 +365,7 @@ WINRT_EXPORT namespace winrt::impl } } -WINRT_EXPORT namespace winrt +namespace winrt { template struct event @@ -523,3 +523,19 @@ WINRT_EXPORT namespace winrt slim_mutex m_change; }; } + +#ifdef WINRT_MODULE +export namespace winrt +{ + using winrt::event_token; + using winrt::auto_revoke_t; + using winrt::auto_revoke; + using winrt::event_revoker; + using winrt::factory_event_revoker; + using winrt::event; +} +export namespace winrt::impl +{ + using winrt::impl::make_event_revoker; +} +#endif diff --git a/strings/base_extern.h b/strings/base_extern.h index 25c25e9d2..84e2943c4 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 {}; +__declspec(selectany) std::int32_t(__stdcall* winrt_to_hresult_handler)(void* address) noexcept {}; +__declspec(selectany) winrt::hstring(__stdcall* winrt_to_message_handler)(void* address) {}; +__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 {}; +__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_foundation.h b/strings/base_foundation.h index 52a02ecd7..3d7239d40 100644 --- a/strings/base_foundation.h +++ b/strings/base_foundation.h @@ -1,5 +1,5 @@ -WINRT_EXPORT namespace winrt::Windows::Foundation +namespace winrt::Windows::Foundation { struct Point { @@ -76,7 +76,7 @@ WINRT_EXPORT namespace winrt::Windows::Foundation }; } -WINRT_EXPORT namespace winrt::impl +namespace winrt::impl { template <> inline constexpr auto& name_v = L"Windows.Foundation.Point"; template <> inline constexpr auto& name_v = L"Windows.Foundation.Size"; @@ -149,3 +149,12 @@ WINRT_EXPORT namespace winrt::impl #endif } + +#ifdef WINRT_MODULE +export namespace winrt::Windows::Foundation +{ + using winrt::Windows::Foundation::Point; + using winrt::Windows::Foundation::Size; + using winrt::Windows::Foundation::Rect; +} +#endif diff --git a/strings/base_handle.h b/strings/base_handle.h index 7a65af7b3..e58c4d6eb 100644 --- a/strings/base_handle.h +++ b/strings/base_handle.h @@ -1,5 +1,5 @@ -WINRT_EXPORT namespace winrt +namespace winrt { template struct handle_type @@ -113,3 +113,12 @@ WINRT_EXPORT namespace winrt using file_handle = handle_type; } + +#ifdef WINRT_MODULE +export namespace winrt +{ + using winrt::handle_type; + using winrt::handle; + using winrt::file_handle; +} +#endif diff --git a/strings/base_identity.h b/strings/base_identity.h index 8120a2fbf..f38f93242 100644 --- a/strings/base_identity.h +++ b/strings/base_identity.h @@ -1,5 +1,5 @@ -WINRT_EXPORT namespace winrt +namespace winrt { template using default_interface = typename impl::default_interface::type; @@ -17,7 +17,7 @@ WINRT_EXPORT namespace winrt } } -WINRT_EXPORT namespace winrt::impl +namespace winrt::impl { template constexpr std::array to_array(T const* value, std::index_sequence const) noexcept @@ -655,7 +655,7 @@ WINRT_EXPORT namespace winrt::impl } } -WINRT_EXPORT namespace winrt +namespace winrt { template constexpr auto name_of() noexcept @@ -663,3 +663,13 @@ WINRT_EXPORT namespace winrt return impl::to_wstring_view(impl::name_v); } } + +#ifdef WINRT_MODULE +export namespace winrt +{ + using winrt::default_interface; + using winrt::guid_of; + using winrt::is_guid_of; + using winrt::name_of; +} +#endif diff --git a/strings/base_implements.h b/strings/base_implements.h index c2c514132..0d62097a2 100644 --- a/strings/base_implements.h +++ b/strings/base_implements.h @@ -6,7 +6,7 @@ #endif #endif -WINRT_EXPORT namespace winrt::impl +namespace winrt::impl { struct marker { @@ -14,7 +14,7 @@ WINRT_EXPORT namespace winrt::impl }; } -WINRT_EXPORT namespace winrt +namespace winrt { struct non_agile : impl::marker {}; struct no_weak_ref : impl::marker {}; @@ -30,7 +30,7 @@ WINRT_EXPORT namespace winrt struct implements; } -WINRT_EXPORT namespace winrt::impl +namespace winrt::impl { template using tuple_cat_t = decltype(std::tuple_cat(std::declval()...)); @@ -238,7 +238,7 @@ WINRT_EXPORT namespace winrt::impl } } -WINRT_EXPORT namespace winrt +namespace winrt { template D* get_self(I const& from) noexcept @@ -271,7 +271,7 @@ WINRT_EXPORT namespace winrt } } -WINRT_EXPORT namespace winrt::impl +namespace winrt::impl { template struct interface_list; @@ -1397,7 +1397,7 @@ WINRT_EXPORT namespace winrt::impl } } -WINRT_EXPORT namespace winrt +namespace winrt { #if defined(_MSC_VER) && !defined(__clang__) #pragma warning(push) @@ -1592,3 +1592,29 @@ WINRT_EXPORT namespace winrt friend struct weak_ref; }; } + +#ifdef WINRT_MODULE +export namespace winrt +{ + using winrt::non_agile; + using winrt::no_weak_ref; + using winrt::composing; + using winrt::composable; + using winrt::no_module_lock; + using winrt::static_lifetime; + using winrt::implements; + using winrt::cloaked; + using winrt::make; + using winrt::make_self; + using winrt::from_abi; + using winrt::to_abi; + using winrt::clear_factory_static_lifetime; +} + +export namespace winrt::impl +{ + using winrt::impl::produce; + using winrt::impl::producer_ref; + using winrt::impl::base; +} +#endif diff --git a/strings/base_iterator.h b/strings/base_iterator.h index 9cc37252a..e04d0fb41 100644 --- a/strings/base_iterator.h +++ b/strings/base_iterator.h @@ -1,5 +1,5 @@ -WINRT_EXPORT namespace winrt::impl +namespace winrt::impl { template struct fast_iterator diff --git a/strings/base_lock.h b/strings/base_lock.h index a0d6261e4..049aa8ccb 100644 --- a/strings/base_lock.h +++ b/strings/base_lock.h @@ -1,5 +1,5 @@ -WINRT_EXPORT namespace winrt +namespace winrt { struct slim_condition_variable; @@ -140,3 +140,13 @@ WINRT_EXPORT namespace winrt impl::condition_variable m_cv{}; }; } + +#ifdef WINRT_MODULE +export namespace winrt +{ + using winrt::slim_mutex; + using winrt::slim_lock_guard; + using winrt::slim_shared_lock_guard; + using winrt::slim_condition_variable; +} +#endif diff --git a/strings/base_macros.h b/strings/base_macros.h index 612e2beb9..baae26dca 100644 --- a/strings/base_macros.h +++ b/strings/base_macros.h @@ -27,13 +27,11 @@ #pragma warning(disable : 4630) #endif -#ifndef WINRT_EXPORT #ifdef WINRT_MODULE -#define WINRT_EXPORT export extern "C++" +#define WINRT_EXPORT export #else #define WINRT_EXPORT #endif -#endif // pulls in large, hard-to-control legacy headers. In header builds we keep the // existing behavior, but in module builds it's provided by the winrt.numerics module. @@ -41,7 +39,7 @@ #ifdef WINRT_IMPL_NUMERICS #define _WINDOWS_NUMERICS_NAMESPACE_ winrt::Windows::Foundation::Numerics -#define _WINDOWS_NUMERICS_BEGIN_NAMESPACE_ WINRT_EXPORT namespace winrt::Windows::Foundation::Numerics +#define _WINDOWS_NUMERICS_BEGIN_NAMESPACE_ extern "C++" namespace winrt::Windows::Foundation::Numerics #define _WINDOWS_NUMERICS_END_NAMESPACE_ #include #undef _WINDOWS_NUMERICS_NAMESPACE_ diff --git a/strings/base_marshaler.h b/strings/base_marshaler.h index 9be6959c9..526f4d4c3 100644 --- a/strings/base_marshaler.h +++ b/strings/base_marshaler.h @@ -1,5 +1,5 @@ -WINRT_EXPORT namespace winrt::impl +namespace winrt::impl { inline std::int32_t make_marshaler(unknown_abi* outer, void** result) noexcept { diff --git a/strings/base_meta.h b/strings/base_meta.h index fea443041..c080e425f 100644 --- a/strings/base_meta.h +++ b/strings/base_meta.h @@ -1,5 +1,5 @@ -WINRT_EXPORT namespace winrt +namespace winrt { hresult check_hresult(hresult const result, winrt::impl::slim_source_location const& sourceInformation = winrt::impl::slim_source_location::current()); hresult to_hresult() noexcept; @@ -48,7 +48,7 @@ WINRT_EXPORT namespace winrt } } -WINRT_EXPORT namespace winrt::impl +namespace winrt::impl { using namespace std::literals; @@ -324,3 +324,23 @@ WINRT_EXPORT namespace winrt::impl template inline constexpr bool has_TryLookup_v = has_TryLookup::value; } + +#ifdef WINRT_MODULE +export namespace winrt +{ + using winrt::take_ownership_from_abi_t; + using winrt::take_ownership_from_abi; + using winrt::trylookup_from_abi_t; + using winrt::trylookup_from_abi; +} + +export namespace winrt::impl +{ + using winrt::impl::abi_t; + using winrt::impl::consume_t; + using winrt::impl::has_category_v; + using winrt::impl::require; + using winrt::impl::require_one; + using winrt::impl::to_underlying_type; +} +#endif diff --git a/strings/base_natvis.h b/strings/base_natvis.h index 8ae69b2d6..aaebf2f98 100644 --- a/strings/base_natvis.h +++ b/strings/base_natvis.h @@ -5,7 +5,7 @@ #ifdef WINRT_NATVIS -WINRT_EXPORT namespace winrt::impl +namespace winrt::impl { struct natvis { diff --git a/strings/base_reference_produce.h b/strings/base_reference_produce.h index d13262449..29ed80f75 100644 --- a/strings/base_reference_produce.h +++ b/strings/base_reference_produce.h @@ -1,5 +1,5 @@ -WINRT_EXPORT namespace winrt::impl +namespace winrt::impl { template struct reference : implements, Windows::Foundation::IReference, Windows::Foundation::IPropertyValue> @@ -114,6 +114,10 @@ WINRT_EXPORT namespace winrt::impl using itf = Windows::Foundation::IReference; }; +} + +namespace winrt::impl +{ template <> struct reference_traits { @@ -395,7 +399,7 @@ WINRT_EXPORT namespace winrt::impl }; } -WINRT_EXPORT namespace winrt::Windows::Foundation +namespace winrt::Windows::Foundation { template bool operator==(IReference const& left, IReference const& right) @@ -414,7 +418,7 @@ WINRT_EXPORT namespace winrt::Windows::Foundation } } -WINRT_EXPORT namespace winrt::impl +namespace winrt::impl { template T unbox_value_type(From&& value) @@ -503,7 +507,7 @@ WINRT_EXPORT namespace winrt::impl } } -WINRT_EXPORT namespace winrt +namespace winrt { inline Windows::Foundation::IInspectable box_value(param::hstring const& value) { @@ -576,3 +580,17 @@ WINRT_EXPORT namespace winrt template using optional = typename impl::reference_traits::itf; } + +#ifdef WINRT_MODULE +export namespace winrt +{ + using winrt::box_value; + using winrt::unbox_value; + using winrt::unbox_value_or; + using winrt::optional; +} +namespace winrt::impl +{ + using winrt::impl::reference_traits; +} +#endif diff --git a/strings/base_reference_produce_1.h b/strings/base_reference_produce_1.h index db857446e..d738d7aa4 100644 --- a/strings/base_reference_produce_1.h +++ b/strings/base_reference_produce_1.h @@ -1,5 +1,5 @@ -WINRT_EXPORT namespace winrt::Windows::Foundation +namespace winrt::Windows::Foundation { template bool operator==(IReference const& left, IReference const& right); diff --git a/strings/base_security.h b/strings/base_security.h index a912487e4..a6ee5e6af 100644 --- a/strings/base_security.h +++ b/strings/base_security.h @@ -1,5 +1,5 @@ -WINRT_EXPORT namespace winrt +namespace winrt { struct access_token : handle { @@ -97,3 +97,10 @@ WINRT_EXPORT namespace winrt } }; } + +#ifdef WINRT_MODULE +export namespace winrt +{ + using winrt::access_token; +} +#endif \ No newline at end of file diff --git a/strings/base_source_location.h b/strings/base_source_location.h index 58c93efd2..72e652cb4 100644 --- a/strings/base_source_location.h +++ b/strings/base_source_location.h @@ -43,7 +43,7 @@ #define WINRT_IMPL_BUILTIN_FUNCTION nullptr #endif -WINRT_EXPORT namespace winrt::impl +namespace winrt::impl { // This struct is intended to be highly similar to std::source_location. The key difference is // that function_name is NOT included. Function names do not fold to identical strings and can diff --git a/strings/base_std_hash.h b/strings/base_std_hash.h index 42ff52e59..0774e18dc 100644 --- a/strings/base_std_hash.h +++ b/strings/base_std_hash.h @@ -1,5 +1,5 @@ -WINRT_EXPORT namespace winrt::impl +namespace winrt::impl { inline std::size_t hash_data(void const* ptr, std::size_t const bytes) noexcept { @@ -54,3 +54,10 @@ namespace std } }; } + +#ifdef WINRT_MODULE +export namespace winrt::impl +{ + using winrt::impl::hash_base; +} +#endif diff --git a/strings/base_string.h b/strings/base_string.h index e2c01b9b5..859b5a849 100644 --- a/strings/base_string.h +++ b/strings/base_string.h @@ -1,5 +1,5 @@ -WINRT_EXPORT namespace winrt::impl +namespace winrt::impl { struct atomic_ref_count { @@ -157,7 +157,7 @@ WINRT_EXPORT namespace winrt::impl }; } -WINRT_EXPORT namespace winrt +namespace winrt { struct hstring { @@ -472,7 +472,7 @@ WINRT_EXPORT namespace winrt template<> struct std::formatter : std::formatter {}; -WINRT_EXPORT namespace winrt::impl +namespace winrt::impl { template <> struct abi { @@ -614,7 +614,7 @@ WINRT_EXPORT namespace winrt::impl #endif } -WINRT_EXPORT namespace winrt +namespace winrt { #if __cpp_lib_format >= 202207L template @@ -756,3 +756,16 @@ WINRT_EXPORT namespace winrt return result; } } + +#ifdef WINRT_MODULE +export namespace winrt +{ + using winrt::hstring; +} + +export namespace winrt::impl +{ + using winrt::impl::bind_in; + using winrt::impl::bind_out; +} +#endif \ No newline at end of file diff --git a/strings/base_string_input.h b/strings/base_string_input.h index f992076e6..0e52d07a7 100644 --- a/strings/base_string_input.h +++ b/strings/base_string_input.h @@ -1,5 +1,5 @@ -WINRT_EXPORT namespace winrt::param +namespace winrt::param { struct hstring { @@ -65,8 +65,20 @@ WINRT_EXPORT namespace winrt::param } } -WINRT_EXPORT namespace winrt::impl +namespace winrt::impl { template using param_type = std::conditional_t, param::hstring, T>; } + +#ifdef WINRT_MODULE +export namespace winrt::param +{ + using winrt::param::hstring; +} + +export namespace winrt::impl +{ + using winrt::impl::param_type; +} +#endif diff --git a/strings/base_string_operators.h b/strings/base_string_operators.h index 7e237866d..9af7951f6 100644 --- a/strings/base_string_operators.h +++ b/strings/base_string_operators.h @@ -1,4 +1,4 @@ -WINRT_EXPORT namespace winrt::impl +namespace winrt::impl { inline hstring concat_hstring(std::wstring_view const& left, std::wstring_view const& right) { @@ -14,7 +14,7 @@ WINRT_EXPORT namespace winrt::impl } } -WINRT_EXPORT namespace winrt +namespace winrt { inline hstring operator+(hstring const& left, hstring const& right) { @@ -73,3 +73,13 @@ WINRT_EXPORT namespace winrt } #endif } + +#ifdef WINRT_MODULE +export namespace winrt +{ + using winrt::operator+; +#ifndef WINRT_LEAN_AND_MEAN + using winrt::operator<<; +#endif +} +#endif \ No newline at end of file diff --git a/strings/base_stringable_streams.h b/strings/base_stringable_streams.h index 52b481d6f..b1c6f3341 100644 --- a/strings/base_stringable_streams.h +++ b/strings/base_stringable_streams.h @@ -1,8 +1,20 @@ #ifndef WINRT_LEAN_AND_MEAN -inline std::wostream& operator<<(std::wostream& stream, winrt::Windows::Foundation::IStringable const& stringable) +namespace winrt::Windows::Foundation { - stream << stringable.ToString(); - return stream; + inline std::wostream& operator<<(std::wostream& stream, winrt::Windows::Foundation::IStringable const& stringable) + { + stream << stringable.ToString(); + return stream; + } } #endif + +#ifdef WINRT_MODULE +#ifndef WINRT_LEAN_AND_MEAN +export namespace winrt::Windows::Foundation +{ + using winrt::Windows::Foundation::operator<<; +} +#endif +#endif diff --git a/strings/base_stringable_to_hstring.h b/strings/base_stringable_to_hstring.h index f92da965b..cd9e71aea 100644 --- a/strings/base_stringable_to_hstring.h +++ b/strings/base_stringable_to_hstring.h @@ -1,8 +1,15 @@ -WINRT_EXPORT namespace winrt +namespace winrt { inline hstring to_hstring(Windows::Foundation::IStringable const& stringable) { return stringable.ToString(); } } + +#ifdef WINRT_MODULE +export namespace winrt +{ + using winrt::to_hstring; +} +#endif diff --git a/strings/base_types.h b/strings/base_types.h index f31452d84..c6750c035 100644 --- a/strings/base_types.h +++ b/strings/base_types.h @@ -1,5 +1,5 @@ -WINRT_EXPORT namespace winrt::impl +namespace winrt::impl { using ptp_io = struct tp_io*; using ptp_timer = struct tp_timer*; @@ -58,7 +58,7 @@ WINRT_EXPORT namespace winrt::impl } } -WINRT_EXPORT namespace winrt +namespace winrt { struct event_token; struct hstring; @@ -200,7 +200,7 @@ WINRT_EXPORT namespace winrt }; } -WINRT_EXPORT namespace winrt::Windows::Foundation +namespace winrt::Windows::Foundation { enum class TrustLevel : std::int32_t { @@ -216,7 +216,7 @@ WINRT_EXPORT namespace winrt::Windows::Foundation using DateTime = std::chrono::time_point; } -WINRT_EXPORT namespace winrt::impl +namespace winrt::impl { #ifdef WINRT_IMPL_IUNKNOWN_DEFINED using hresult_type = long; @@ -256,3 +256,17 @@ WINRT_EXPORT namespace winrt::impl inline constexpr hresult error_file_not_found{ static_cast(0x80070002) }; // HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) inline constexpr hresult error_no_task_queue{ static_cast(0x800701AB) }; // HRESULT_FROM_WIN32(ERROR_NO_TASK_QUEUE) } + +#ifdef WINRT_MODULE +export namespace winrt +{ + using winrt::hresult; + using winrt::guid; +} + +export namespace winrt::impl +{ + using winrt::impl::error_no_interface; + using winrt::impl::error_out_of_bounds; +} +#endif diff --git a/strings/base_version.h b/strings/base_version.h index 4a6b68e66..411e666c5 100644 --- a/strings/base_version.h +++ b/strings/base_version.h @@ -14,7 +14,7 @@ char const * const WINRT_version = "C++/WinRT version:" CPPWINRT_VERSION; #pragma detect_mismatch("C++/WinRT version", CPPWINRT_VERSION) #endif -WINRT_EXPORT namespace winrt +namespace winrt { template constexpr bool check_version(char const(&base)[BaseSize], char const(&component)[ComponentSize]) noexcept @@ -35,3 +35,10 @@ WINRT_EXPORT namespace winrt return true; } } + +#ifdef WINRT_MODULE +export namespace winrt +{ + using winrt::check_version; +} +#endif diff --git a/strings/base_weak_ref.h b/strings/base_weak_ref.h index 5f124045a..855fdc398 100644 --- a/strings/base_weak_ref.h +++ b/strings/base_weak_ref.h @@ -1,5 +1,5 @@ -WINRT_EXPORT namespace winrt +namespace winrt { template struct weak_ref @@ -97,3 +97,11 @@ WINRT_EXPORT namespace winrt return object; } } + +#ifdef WINRT_MODULE +export namespace winrt +{ + using winrt::weak_ref; + using winrt::make_weak; +} +#endif diff --git a/strings/base_windows.h b/strings/base_windows.h index baa90e9e3..e7c751526 100644 --- a/strings/base_windows.h +++ b/strings/base_windows.h @@ -1,5 +1,5 @@ -WINRT_EXPORT namespace winrt::impl +namespace winrt::impl { #ifdef WINRT_DIAGNOSTICS @@ -164,7 +164,7 @@ WINRT_EXPORT namespace winrt::impl } } -WINRT_EXPORT namespace winrt::Windows::Foundation +namespace winrt::Windows::Foundation { struct IUnknown { @@ -346,7 +346,7 @@ WINRT_EXPORT namespace winrt::Windows::Foundation }; } -WINRT_EXPORT namespace winrt::impl +namespace winrt::impl { template void** abi_cast(T const& object) noexcept @@ -355,7 +355,7 @@ WINRT_EXPORT namespace winrt::impl } } -WINRT_EXPORT namespace winrt +namespace winrt { template requires (!std::is_base_of_v) @@ -463,7 +463,7 @@ WINRT_EXPORT namespace winrt } } -WINRT_EXPORT namespace winrt::Windows::Foundation +namespace winrt::Windows::Foundation { struct IInspectable : IUnknown { @@ -472,7 +472,7 @@ WINRT_EXPORT namespace winrt::Windows::Foundation }; } -WINRT_EXPORT namespace winrt::impl +namespace winrt::impl { template void consume_noexcept_remove_overload(Derive const* d, MemberPointer mptr, Args&&... args) noexcept @@ -528,3 +528,24 @@ WINRT_EXPORT namespace winrt::impl } } } + +#ifdef WINRT_MODULE +export namespace winrt +{ + using winrt::get_abi; + using winrt::put_abi; + using winrt::attach_abi; + using winrt::detach_abi; + using winrt::copy_from_abi; + using winrt::copy_to_abi; + using winrt::get_unknown; +} + +export namespace winrt::impl +{ + using winrt::impl::abi_cast; + using winrt::impl::consume_noexcept_remove_overload; + using winrt::impl::consume_noexcept; + using winrt::impl::consume_general; +} +#endif diff --git a/strings/base_xaml_component_connector.h b/strings/base_xaml_component_connector.h index 092944613..f9df93309 100644 --- a/strings/base_xaml_component_connector.h +++ b/strings/base_xaml_component_connector.h @@ -1,5 +1,5 @@ -WINRT_EXPORT namespace winrt::Windows::UI::Xaml::Markup +namespace winrt::Windows::UI::Xaml::Markup { template struct ComponentConnectorT : D @@ -51,3 +51,10 @@ WINRT_EXPORT namespace winrt::Windows::UI::Xaml::Markup bool m_dispatch_base{}; }; } + +#ifdef WINRT_MODULE +export namespace winrt::Windows::UI::Xaml::Markup +{ + using winrt::Windows::UI::Xaml::Markup::ComponentConnectorT; +} +#endif diff --git a/strings/base_xaml_component_connector_winui.h b/strings/base_xaml_component_connector_winui.h index 312f5af29..3aac3fc12 100644 --- a/strings/base_xaml_component_connector_winui.h +++ b/strings/base_xaml_component_connector_winui.h @@ -1,5 +1,5 @@ -WINRT_EXPORT namespace winrt::Microsoft::UI::Xaml::Markup +namespace winrt::Microsoft::UI::Xaml::Markup { template struct ComponentConnectorT : D @@ -50,3 +50,10 @@ WINRT_EXPORT namespace winrt::Microsoft::UI::Xaml::Markup bool m_dispatch_base{}; }; } + +#ifdef WINRT_MODULE +export namespace winrt::Microsoft::UI::Xaml::Markup +{ + using winrt::Microsoft::UI::Xaml::Markup::ComponentConnectorT; +} +#endif diff --git a/strings/base_xaml_typename.h b/strings/base_xaml_typename.h index 2cc45b0bb..488d71f3b 100644 --- a/strings/base_xaml_typename.h +++ b/strings/base_xaml_typename.h @@ -1,5 +1,5 @@ -WINRT_EXPORT namespace winrt::impl +namespace winrt::impl { template struct xaml_typename_name @@ -138,7 +138,7 @@ WINRT_EXPORT namespace winrt::impl } } -WINRT_EXPORT namespace winrt +namespace winrt { template inline Windows::UI::Xaml::Interop::TypeName xaml_typename() @@ -148,3 +148,16 @@ WINRT_EXPORT namespace winrt return name; } } + +#ifdef WINRT_MODULE +export namespace winrt::impl +{ + using winrt::impl::xaml_typename_name; + using winrt::impl::xaml_typename_kind; +} + +export namespace winrt +{ + using winrt::xaml_typename; +} +#endif From 4e02554e9298d6ea7d710286ee1b4bb1ed7b0798 Mon Sep 17 00:00:00 2001 From: YexuanXiao Date: Sun, 26 Apr 2026 07:43:39 +0800 Subject: [PATCH 2/2] Fix extern "C++" --- cppwinrt/code_writers.h | 17 ++++++++++- cppwinrt/file_writers.h | 67 +++++++++++++++++++++++++++-------------- 2 files changed, 61 insertions(+), 23 deletions(-) diff --git a/cppwinrt/code_writers.h b/cppwinrt/code_writers.h index 6e31d72ee..ceca9dbe2 100644 --- a/cppwinrt/code_writers.h +++ b/cppwinrt/code_writers.h @@ -151,6 +151,21 @@ namespace cppwinrt return { w, write_nothing }; } + static void write_extern_cxx_start(writer& w) + { + w.write(R"( +extern "C++" +{ +)"); + } + + static void write_extern_cxx_end(writer& w) + { + w.write(R"( +} // extern "C++" +)"); + } + static void write_parent_depends(writer& w, cache const& c, std::string_view const& type_namespace) { auto pos = type_namespace.rfind('.'); @@ -205,7 +220,7 @@ namespace cppwinrt [[nodiscard]] static finish_with wrap_impl_namespace_without_export(writer& w) { - auto format = R"(extern "C++" namespace winrt::impl + auto format = R"(namespace winrt::impl { )"; diff --git a/cppwinrt/file_writers.h b/cppwinrt/file_writers.h index a06d25037..a8a91fa4b 100644 --- a/cppwinrt/file_writers.h +++ b/cppwinrt/file_writers.h @@ -60,7 +60,7 @@ namespace cppwinrt if (settings.modules) { - w.write("extern \"C++\"\n{\n"); + write_extern_cxx_start(w); } w.write(strings::base_macros); @@ -98,7 +98,7 @@ namespace cppwinrt if (settings.modules) { - w.write("} // extern \"C++\"\n"); + write_extern_cxx_end(w); } if (settings.modules) @@ -194,6 +194,11 @@ namespace cppwinrt w.write_each(members.interfaces); } + if (settings.modules) + { + write_extern_cxx_end(w); + } + if (settings.modules) { get_namespace_module_imports(c, ns, w, module_imports); @@ -217,6 +222,11 @@ namespace cppwinrt } } + if (settings.modules) + { + write_extern_cxx_start(w); + } + w.save_header('0'); } @@ -242,6 +252,11 @@ namespace cppwinrt module_imports.clear(); } + if (settings.modules) + { + write_extern_cxx_end(w); + } + write_close_file_guard(w); w.swap(); write_preamble(w); @@ -258,6 +273,11 @@ namespace cppwinrt w.write_depends(w.type_namespace, '0'); } + if (settings.modules) + { + write_extern_cxx_start(w); + } + w.save_header('1'); } @@ -286,6 +306,11 @@ namespace cppwinrt module_imports.clear(); } + if (settings.modules) + { + write_extern_cxx_end(w); + } + write_close_file_guard(w); w.swap(); write_preamble(w); @@ -304,6 +329,11 @@ namespace cppwinrt w.write_depends(w.type_namespace, '1'); } + if (settings.modules) + { + write_extern_cxx_start(w); + } + w.save_header('2'); } @@ -612,6 +642,12 @@ export import winrt.base; writer w; w.type_namespace = ns; + + if (settings.modules) + { + write_extern_cxx_start(w); + } + { auto wrap_impl = wrap_impl_namespace(w); w.write_each(members.interfaces); @@ -643,6 +679,13 @@ export import winrt.base; } } + + if (settings.modules) + { + write_extern_cxx_end(w); + } + + write_namespace_special(w, ns); if (settings.modules) @@ -654,11 +697,6 @@ export import winrt.base; module_imports.clear(); } - if (settings.modules) - { - w.write("} // extern \"C++\"\n"); - } - if (settings.modules) { w.write("#endif\n"); @@ -679,11 +717,6 @@ export import winrt.base; write_version_assert(w); - if (settings.modules) - { - w.write("extern \"C++\"\n{\n"); - } - write_parent_depends(w, c, ns); for (auto&& depends : w.depends) @@ -693,16 +726,6 @@ export import winrt.base; w.write_depends(w.type_namespace, '2'); - if (settings.modules) - { - w.write("} // extern \"C++\"\n"); - } - - } - - if (settings.modules) - { - w.write("extern \"C++\"\n{\n"); } w.save_header();