public static void ThrowIf(this HResult result) { if (result.IsError()) { throw Marshal.GetExceptionForHR((int)result); } }