Hasty Briefsbeta

Bilingual

Making an agile version of a Windows Runtime delegate in C++/WinRT, part 5 - The Old New Thing

12 hours ago
  • Non-marshalable delegates must be destructed in their original context to avoid threading issues (non-thread-safe reference counting, wrong thread destruction).
  • A custom deleter (in_context_deleter) captures the original context and uses IContextCallback::ContextCallback to switch contexts before releasing the delegate.
  • The make_agile_delegate function handles three cases: agile objects, non-marshal (with the custom deleter), and others (using agile_ref).
  • The IContextCallback call can fail, so the deleter is not guaranteed infallible; further improvements are needed.