CsWinRT
CsWinRT copied to clipboard
Support for exception handling from unmanaged caller
Closes #1571
Codegen example:
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })]
private static unsafe int Do_Abi_GetPoint_2(IntPtr thisPtr, global::Windows.Foundation.Point* __return_value__)
{
global::AuthoringTest.BasicClass __this__ = default;
global::Windows.Foundation.Point ____return_value__ = default;
*__return_value__ = default;
try
{
____return_value__ = (__this__ = global::WinRT.ComWrappersSupport.FindObject<global::AuthoringTest.BasicClass>(thisPtr)).GetPoint();
*__return_value__ = ____return_value__;
}
catch (Exception __exception__)
{
if (global::WinRT.ExceptionHelpers.TryHandleWinRTServerException(__this__, __exception__))
{
return 0;
}
global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__);
return global::WinRT.ExceptionHelpers.GetHRForException(__exception__);
}
return 0;
}
if (global::WinRT.ExceptionHelpers.TryHandleWinRTServerException(__this__, __exception__))
{
return 0;
}
global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__);
return global::WinRT.ExceptionHelpers.GetHRForException(__exception__);
I assume that this block is repeated a lot. You may want to turn into an API or a per-assembly helper to make the code smaller.