Skip to content

Commit

Permalink
Update SplashScreen to use CsWin32 and shared library
Browse files Browse the repository at this point in the history
This updates SplashScreen to use direct interop built on CsWin32. It also uses the shared `System.Private.Windows.Core` library built in Windows Forms.

This makes SplashScreen trim-friendly and improves the performance as it will no longer need to generate the rather extensive interop it used to at startup.

This also introduces a bottom level assembly for WPF: `System.Windows.Primitives` where there are no other dependencies other than the WinForms/WPF base assembly: `System.Private.Windows.Core`.

`PInvokeCore` is the static class that comes from `System.Private.Windows.Core`. `PInvoke` is the static class from `System.Windows.Primitives`. When C# adds something akin to extension types (currently in the design phase) we'll be able to unify to a single `PInvoke`. Generated types (such as `HWND`) are in the namespaces as specified by the Windows metdata and don't have the same problem with conflicts as CsWin32 won't generate types that already exist.

CsWin32 uses `System.Drawing` types where they match Win32 types. `Point` is an example of this. These interchange `System.Drawing` types are in-box with .NET.

`System.Private.Windows.Core` provides a lot of useful support functionality, particularly when it comes to interop. The various scope types in this PR are an example. OLE code will come from this assembly after the new APIs are merged in WinForms.

I've also deleted a large swath of unused interop.

It leverages dotnet#10023, which leverages dotnet#9914 (the first commit), and will be updated when those are merged.

This is an update of dotnet#7929.
  • Loading branch information
JeremyKuhne committed Nov 10, 2024
1 parent cfbfa60 commit ab5d209
Show file tree
Hide file tree
Showing 15 changed files with 404 additions and 4,608 deletions.
1 change: 1 addition & 0 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
<!-- These versions are specified in global.json -->
<StrawberryPerlVersion>5.38.0.1</StrawberryPerlVersion>
<NetFramework48RefAssembliesVersion>0.0.0.1</NetFramework48RefAssembliesVersion>
<MicrosoftWindowsCsWin32PackageVersion>0.3.106</MicrosoftWindowsCsWin32PackageVersion>
</PropertyGroup>
<!-- External Analyzers -->
<PropertyGroup>
Expand Down
13 changes: 12 additions & 1 deletion eng/WpfArcadeSdk/tools/SdkReferences.targets
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@
</ItemGroup>
</Target>

<Target Name="SplitTargetFramework">
<PropertyGroup>
<!-- Split out the target framework. "net10.0-windows" is an example. -->
<_targetFrameworkIdentifier>$([MSBuild]::GetTargetFrameworkIdentifier($(TargetFramework)))</_targetFrameworkIdentifier>
<_targetFrameworkIdentifier Condition="'$(_targetFrameworkIdentifier)' == '.NETCoreApp'">net</_targetFrameworkIdentifier>
<_targetFrameworkVersion>$([MSBuild]::GetTargetFrameworkVersion($(TargetFramework)))</_targetFrameworkVersion>
<_targetFrameworkRoot>$(_targetFrameworkIdentifier)$(_targetFrameworkVersion)</_targetFrameworkRoot>
</PropertyGroup>
</Target>

<!--
In your project, Add a references to WinForms transport package like this:
<ItemGroup>
Expand All @@ -109,11 +119,12 @@
</ItemGroup>
-->
<Target Name="ResolveWinFormsReferences"
DependsOnTargets="SplitTargetFramework"
Condition="'@(MicrosoftPrivateWinFormsReference)'!=''
And '$(TargetFrameworkIdentifier)' == '.NETCoreApp'
And $([MSBuild]::VersionGreaterThanOrEquals('$(TargetFrameworkVersion)', '3.0')) ">
<PropertyGroup>
<_WinFormsTargetFrameworkVersion Condition="'$(_WinFormsTargetFrameworkVersion)' == ''">$(TargetFramework)</_WinFormsTargetFrameworkVersion>
<_WinFormsTargetFrameworkVersion Condition="'$(_WinFormsTargetFrameworkVersion)' == ''">$(_targetFrameworkRoot)</_WinFormsTargetFrameworkVersion>
</PropertyGroup>
<ItemGroup>
<Reference Include="$(PkgMicrosoft_Private_Winforms)\lib\$(_WinFormsTargetFrameworkVersion)\%(MicrosoftPrivateWinFormsReference.Identity).dll"
Expand Down
1 change: 1 addition & 0 deletions eng/WpfArcadeSdk/tools/WpfProjectReference.targets
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

</ItemGroup>
<ItemGroup>
<WpfProjectPath Include="System.Windows.Primitives" ProjectPath="$(WpfSourceDir)System.Windows.Primitives\System.Windows.Primitives.csproj" />
<WpfProjectPath Include="System.Xaml" ProjectPath="$(WpfSourceDir)System.Xaml\System.Xaml.csproj" />
<WpfProjectPath Include="WindowsBase" ProjectPath="$(WpfSourceDir)WindowsBase\WindowsBase.csproj" />
<WpfProjectPath Include="DirectWriteForwarder" ProjectPath="$(WpfSourceDir)DirectWriteForwarder\DirectWriteForwarder.vcxproj">
Expand Down
Loading

0 comments on commit ab5d209

Please sign in to comment.