Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions strings/base_implements.h
Original file line number Diff line number Diff line change
Expand Up @@ -1291,8 +1291,18 @@ WINRT_EXPORT namespace winrt
static_assert(std::is_destructible_v<D>, "C++/WinRT implementation types must have a public destructor");
static_assert(!std::is_final_v<D>, "C++/WinRT implementation types must not be final");
#endif

return { new impl::heap_implements<D>(std::forward<Args>(args)...), take_ownership_from_abi };
if constexpr (std::is_same_v<typename impl::implements_default_interface<D>::type, Windows::Foundation::IActivationFactory>)
{
static_assert(sizeof...(args) == 0);
auto temp = impl::make_factory<D>();
void* result = get_self<D>(temp);
detach_abi(temp);
return { result, take_ownership_from_abi };
}
else
{
return { new impl::heap_implements<D>(std::forward<Args>(args)...), take_ownership_from_abi };
}
}

template <typename D, typename... I>
Expand Down
2 changes: 2 additions & 0 deletions test/old_tests/Component/Component.idl
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ namespace Component
[eventadd] HRESULT StaticEvent([in] Windows.Foundation.EventHandler<int>* handler, [out][retval] EventRegistrationToken* cookie);
[eventremove] HRESULT StaticEvent([in] EventRegistrationToken cookie);
HRESULT RaiseStaticEvent([in] int value);

HRESULT TestStaticLifetime([out][retval] boolean* result);
};

[version(1.0), uuid(6ac35d2c-b2cf-4c36-995c-a9c0764636c9), exclusiveto(Events)]
Expand Down
20 changes: 20 additions & 0 deletions test/old_tests/Component/Events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,24 @@ namespace winrt::Component::factory_implementation
{
m_static(nullptr, value);
}

bool Events::TestStaticLifetime()
{
// Capture current reference count.
AddRef();
auto refcount = Release();

auto self = make_self<Events>();
if (self.get() != this)
{
return false;
}
self = nullptr;

// Refcount should be unchanged.
AddRef();
auto new_refcount = Release();

return refcount == new_refcount;
}
}
1 change: 1 addition & 0 deletions test/old_tests/Component/Events.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ namespace winrt::Component::factory_implementation
event_token StaticEvent(Windows::Foundation::EventHandler<int32_t> const& handler);
void StaticEvent(event_token const& cookie);
void RaiseStaticEvent(int value);
bool TestStaticLifetime();

private:
event<Windows::Foundation::EventHandler<int32_t>> m_static;
Expand Down
3 changes: 3 additions & 0 deletions test/old_tests/UnitTests/factory_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,7 @@ TEST_CASE("factory_cache")
// Make sure 'Events' is unique

REQUIRE(b != get_activation_factory<Component::Events>());

// Test some stuff that can only be done from within the implementation.
REQUIRE(Component::Events::TestStaticLifetime());
}