Article

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

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

This article discusses the implementation of a fake agile wrapper in C++ that utilizes the global interface table. It explores the concept of moving non-marshalable COM objects rather than copying them.

From the article

Last time, we successfully our plan to use the global interface table to hold created a fake agile wrapper that is technically agile, even though it isn’t useful outside its home apartment . I noted that there are opportunities for fine-tuning.

One thing we can do is move the non-marshalable COM object rather than copying it. This means forwarding the reference all the way into the force_ marshal wrapper.

template<typename Smart> struct force_marshal : winrt::implements<force_marshal<Smart>, IUnknown, winrt::non_agile> { template<typename Arg> force_marshal(Arg&& arg) : m_p(std::forward<Arg>(arg)) {} Smart m_p; }; The force_ marshal<Smart> now takes anything and forwards it into the smart pointer. This means that if the inbound parameter is an rvalue reference to a smart pointer, the…


Share this resource


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