diff --git a/WinRT.Runtime/ComWrappersSupport.net5.cs b/WinRT.Runtime/ComWrappersSupport.net5.cs index bd048a4bb..1197be275 100644 --- a/WinRT.Runtime/ComWrappersSupport.net5.cs +++ b/WinRT.Runtime/ComWrappersSupport.net5.cs @@ -46,7 +46,7 @@ internal static unsafe InspectableInfo GetInspectableInfo(IntPtr pThis) public static IObjectReference CreateCCWForObject(object obj) { - IntPtr ccw = ComWrappers.GetOrCreateComInterfaceForObject(obj, CreateComInterfaceFlags.CallerDefinedIUnknown | CreateComInterfaceFlags.TrackerSupport); + IntPtr ccw = ComWrappers.GetOrCreateComInterfaceForObject(obj, CreateComInterfaceFlags.TrackerSupport); return ObjectReference.Attach(ref ccw); } diff --git a/WinRT.Runtime/ComWrappersSupport.netstandard2.0.cs b/WinRT.Runtime/ComWrappersSupport.netstandard2.0.cs index 2900687f8..4d92b9401 100644 --- a/WinRT.Runtime/ComWrappersSupport.netstandard2.0.cs +++ b/WinRT.Runtime/ComWrappersSupport.netstandard2.0.cs @@ -286,6 +286,13 @@ internal uint Release() internal int QueryInterface(Guid iid, out IntPtr ptr) { const int E_NOINTERFACE = unchecked((int)0x80004002); + if (ManagedObject is ICustomQueryInterface customQI) + { + if (customQI.GetInterface(ref iid, out ptr) == CustomQueryInterfaceResult.Handled) + { + return 0; + } + } if (_managedQITable.TryGetValue(iid, out ptr)) { AddRef(); diff --git a/WinRT.Runtime/ExceptionHelpers.cs b/WinRT.Runtime/ExceptionHelpers.cs index bb21b7ae1..653505b6a 100644 --- a/WinRT.Runtime/ExceptionHelpers.cs +++ b/WinRT.Runtime/ExceptionHelpers.cs @@ -71,7 +71,7 @@ public static void ThrowExceptionForHR(int hr) private static Exception GetExceptionForHR(int hr, bool useGlobalErrorState, out bool restoredExceptionFromGlobalState) { restoredExceptionFromGlobalState = false; - if (hr == 0) + if (hr >= 0) { return null; } diff --git a/WinRT.Runtime/Projections/Type.cs b/WinRT.Runtime/Projections/Type.cs index 7dc6d6029..f99068d3e 100644 --- a/WinRT.Runtime/Projections/Type.cs +++ b/WinRT.Runtime/Projections/Type.cs @@ -72,11 +72,7 @@ public static Type GetAbi(Marshaler m) { return null; } - if (value.Kind != TypeKind.Custom) - { - return TypeNameSupport.FindTypeByName(name.AsSpan()).type; - } - return global::System.Type.GetType(name, throwOnError: true); + return TypeNameSupport.FindTypeByName(name.AsSpan()).type; } public static unsafe void CopyAbi(Marshaler arg, IntPtr dest) => diff --git a/WinUI/WinUIDesktopSample.Package/NoBuild.Targets b/WinUI/WinUIDesktopSample.Package/NoBuild.Targets new file mode 100644 index 000000000..35c6b94d9 --- /dev/null +++ b/WinUI/WinUIDesktopSample.Package/NoBuild.Targets @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/WinUI/WinUIDesktopSample.Package/WinUIDesktopSample.Package.wapproj b/WinUI/WinUIDesktopSample.Package/WinUIDesktopSample.Package.wapproj index 69a206bf9..c09c19468 100644 --- a/WinUI/WinUIDesktopSample.Package/WinUIDesktopSample.Package.wapproj +++ b/WinUI/WinUIDesktopSample.Package/WinUIDesktopSample.Package.wapproj @@ -85,6 +85,5 @@ - - + \ No newline at end of file diff --git a/WinUI/WinUIDesktopSample/App.xaml.cs b/WinUI/WinUIDesktopSample/App.xaml.cs index 23c160b57..2f4623f6d 100644 --- a/WinUI/WinUIDesktopSample/App.xaml.cs +++ b/WinUI/WinUIDesktopSample/App.xaml.cs @@ -19,23 +19,29 @@ public App() { } + Window myWindow; protected override void OnLaunched(LaunchActivatedEventArgs args) { + var button = new Button + { + Content = "Click me to load MainPage", + HorizontalAlignment = HorizontalAlignment.Center, + VerticalAlignment = VerticalAlignment.Center + }; + button.Click += Button_Click; var window = new Microsoft.UI.Xaml.Window { - // This will cause the InvalidCast exception. Once that is fixed, this can - // be removed and just use the new MainPage() line below for setting content - Content = new Microsoft.UI.Xaml.Shapes.Rectangle() - { - Fill = new SolidColorBrush(Windows.UI.Colors.Red), - Width = 200, - Height = 200 - } + Content = button }; - window.Content = new MainPage(); - window.Activate(); + + myWindow = window; + } + + private void Button_Click(object sender, RoutedEventArgs e) + { + myWindow.Content = new MainPage(); } } diff --git a/WinUI/WinUIDesktopSample/MainPage.xaml.cs b/WinUI/WinUIDesktopSample/MainPage.xaml.cs index 4272f85e1..c6ae880d0 100644 --- a/WinUI/WinUIDesktopSample/MainPage.xaml.cs +++ b/WinUI/WinUIDesktopSample/MainPage.xaml.cs @@ -15,6 +15,7 @@ public partial class MainPage : Page { public MainPage() { + InitializeComponent(); } } } diff --git a/WinUI/WinUIDesktopSample/WinUIDesktopSample.csproj b/WinUI/WinUIDesktopSample/WinUIDesktopSample.csproj index ca51dedc9..cf59fcaef 100644 --- a/WinUI/WinUIDesktopSample/WinUIDesktopSample.csproj +++ b/WinUI/WinUIDesktopSample/WinUIDesktopSample.csproj @@ -5,7 +5,6 @@ netcoreapp5.0 10.0.18362.0 DISABLE_XAML_GENERATED_MAIN - true WinUIDesktopSample.exe.manifest