Article

Making an agile version of a Windows Runtime delegate in C++/WinRT, part 3

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

This article discusses optimizations for creating agile versions of Windows Runtime delegates in C++/WinRT, particularly focusing on handling objects that implement the INoMarshal interface. It explains how to manage exceptions when invoking wrappers across different contexts.

From the article

Last time, we made a small but significant optimization to making an agile version of a Windows Runtime delegate . But there’s another case we missed.

That case is an object that implements the INo­Marshal interface, which means “Do not marshal this object.” For these objects, the Ro­Get­Agile­Reference function fails to create an agile reference and returns CO_ E_ NOT_ SUPPORTED . This function is what powers the agile_ ref class, so if you ask for an agile_ ref to an object that refuses to be marshaled, you get an CO_ E_ NOT_ SUPPORTED exception.

The catch is that this error is produced at the creation of the agile reference. If in practice all your uses of the agile reference are from the original context, you never actually needed to marshal the object, but too bad, you get the…


Share this resource


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