Hasty Briefsbeta

Bilingual

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

12 hours ago
  • RoGetAgileReference fails for objects implementing INoMarshal, causing CO_E_NOT_SUPPORTED exceptions even if marshaling is unnecessary.
  • A wrapper delegate is created that checks if the invocation context matches the original context; if so, it calls the delegate directly, otherwise throws the exception.
  • The implementation captures the original context using IContextCallback and compares it at invoke time.
  • Using a universal reference (Delegate&&) allows moving the delegate when passed as an rvalue, improving performance.
  • The first try is presented with a note that a further optimization will be discussed next time.