Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement ICustomQueryInterface to support aggregation and hidden interfaces #128

Merged
merged 16 commits into from
Apr 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
e798f3a
Implement ICustomQueryInterface and limited interface inheritance to …
jkoritzinsky Apr 9, 2020
035bff0
Streamline ICustomQI.GetInterface implementation.
jkoritzinsky Apr 10, 2020
10afa7e
Merge branch 'master' of https://github.com/microsoft/cswinrt into jk…
jkoritzinsky Apr 10, 2020
957c982
Merge branch 'master' of https://github.com/microsoft/cswinrt into jk…
jkoritzinsky Apr 14, 2020
3907e7c
Fix interface ABI types with new limited code-gen inheritance. Fixed …
jkoritzinsky Apr 14, 2020
a5f0e83
Fix ICustomQI handling of overrride interfaces.
jkoritzinsky Apr 14, 2020
b9b4883
fix sample project
Apr 14, 2020
5e3f218
Keep around the inner for QI purposes (otherwise we end up in a stack…
jkoritzinsky Apr 15, 2020
6cb712a
Clean up App.xaml.cs and add InitializeComponent call in MainPage.xam…
jkoritzinsky Apr 15, 2020
4b2199b
Fix System.Type mapping to be able to find types in assemblies other …
jkoritzinsky Apr 15, 2020
3e601d3
Merge branch 'jkoritzinsky/custom-qi' of https://github.com/microsoft…
jkoritzinsky Apr 15, 2020
df3158b
Merge branch 'master' into jkoritzinsky/custom-qi
jkoritzinsky Apr 15, 2020
912b249
Fix calling overridden and non-overridden interface methods on types …
jkoritzinsky Apr 15, 2020
5a6d5d2
Don't try to throw an exception for S_FALSE hresult.
jkoritzinsky Apr 15, 2020
f214b58
Merge branch 'jkoritzinsky/custom-qi' of https://github.com/microsoft…
jkoritzinsky Apr 15, 2020
debb39c
Fix RCW caching. Fixes #143
jkoritzinsky Apr 16, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion WinRT.Runtime/ComWrappersSupport.net5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IUnknownVftbl>.Attach(ref ccw);
}

Expand Down
7 changes: 7 additions & 0 deletions WinRT.Runtime/ComWrappersSupport.netstandard2.0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion WinRT.Runtime/ExceptionHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 1 addition & 5 deletions WinRT.Runtime/Projections/Type.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down
8 changes: 8 additions & 0 deletions WinUI/WinUIDesktopSample.Package/NoBuild.Targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project>
<!--
This target is only imported when building from the command line.
It defines an empty Build target because we skip building the
project from the command line.
-->
<Target Name="Build" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,5 @@
</ProjectReference>
</ItemGroup>
<Import Project="$(WapProjPath)\Microsoft.DesktopBridge.targets" Condition="'$(BuildingInsideVisualStudio)'=='true'" />
<Target Name="Build" Condition="'$(BuildingInsideVisualStudio)'!='true'" />
<Target Name="Clean" />
<Import Project="$(MSBuildThisFileDirectory)NoBuild.targets" Condition="'$(BuildingInsideVisualStudio)'!='true'" />
</Project>
26 changes: 16 additions & 10 deletions WinUI/WinUIDesktopSample/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down
1 change: 1 addition & 0 deletions WinUI/WinUIDesktopSample/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public partial class MainPage : Page
{
public MainPage()
{
InitializeComponent();
}
}
}
1 change: 0 additions & 1 deletion WinUI/WinUIDesktopSample/WinUIDesktopSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<TargetFramework>netcoreapp5.0</TargetFramework>
<TargetPlatformVersion>10.0.18362.0</TargetPlatformVersion>
<DefineConstants>DISABLE_XAML_GENERATED_MAIN</DefineConstants>
<GenerateTestProjection>true</GenerateTestProjection>
<ApplicationManifest>WinUIDesktopSample.exe.manifest</ApplicationManifest>
<!--
There seems to be a codegen bug when referencing the cswinrt interop assembly of the Win32XamlHost
Expand Down
Loading