Article

Creating a fake agile wrapper that is technically agile but is not useful outside its home apartment, part 5

The Old New Thing ·The Old New Thing ·Published 2026-08-07 ·5 min read

This article discusses the use of std::unique_ptr to manage a registration cookie in a Windows context. It explains how to smuggle an integer value inside a pointer and the implications of this technique.

From the article

Last time, I confessed that I lied when i said that we can’t use std:: unique_ptr to manage the registration cookie .

The trick here is that the registration cookie is of type DWORD , which fits in a pointer, so we can smuggle the integer value inside a pointer.

template<typename T> struct fake_agile_ref { private: using Smart = std::conditional_t< std::is_base_of_v<winrt::Windows::Foundation::IUnknown, T>, T, winrt::com_ptr<T>>; struct git_deleter { winrt::com_ptr<IGlobalInterfaceTable> m_git; void operator()(void* p) { m_git->RevokeInterfaceFromGlobal(static_cast<DWORD>(reinterpret_cast<uintptr_t>(p))); } }; winrt::com_ptr<IContextCallback> m_context; ULONG_PTR m_token = 0; std::unique_ptr<void, git_deleter> m_cookie; void* m_raw = nullptr; Our custom deleter holds a pointer to the…


Share this resource


Discovered 2026-08-10 Source The Old New Thing Archive 2026-08 →