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

First round of converting System.Drawing.Common to COMWrappers #54636

Merged
merged 13 commits into from
Jun 28, 2021
2 changes: 1 addition & 1 deletion eng/testing/linker/project.csproj.template
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<WasmAppBuilderTasksAssemblyPath>{WasmAppBuilderTasksAssemblyPath}</WasmAppBuilderTasksAssemblyPath>
<MicrosoftNetCoreAppRuntimePackRidDir>{MicrosoftNetCoreAppRuntimePackRidDir}</MicrosoftNetCoreAppRuntimePackRidDir>
<RepositoryEngineeringDir>{RepositoryEngineeringDir}</RepositoryEngineeringDir>
<TargetFramework>{NetCoreAppCurrent}</TargetFramework>
<TargetFramework>{TestTargetFramework}</TargetFramework>
<RuntimeIdentifier>{RuntimeIdentifier}</RuntimeIdentifier>
<UseMonoRuntime>{UseMonoRuntime}</UseMonoRuntime>
<TargetingPackDir>{TargetingPackDir}</TargetingPackDir>
Expand Down
14 changes: 8 additions & 6 deletions eng/testing/linker/trimmingTests.targets
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@
<TestConsoleAppSourceFiles>
<ProjectDir>$([MSBuild]::NormalizeDirectory('$(TrimmingTestProjectsDir)', '$(MSBuildProjectName)', '%(Filename)', '$(PackageRID)'))</ProjectDir>
<TestRuntimeIdentifier>$(PackageRID)</TestRuntimeIdentifier>
<TestTargetFramework>$(NetCoreAppCurrent)</TestTargetFramework>
<TestTargetFramework Condition="'%(TestConsoleAppSourceFiles.TargetOS)' != ''">$(NetCoreAppCurrent)-%(TestConsoleAppSourceFiles.TargetOS)</TestTargetFramework>
</TestConsoleAppSourceFiles>
<!-- We need to separate Item metadata declaration in two in order to be able to use ProjectDir and TestRuntimeIdentifier bellow -->
<!-- We need to separate Item metadata declaration in two in order to be able to use ProjectDir and TestRuntimeIdentifier below -->
<TestConsoleAppSourceFiles>
<ProjectFile>%(ProjectDir)project.csproj</ProjectFile>
<TestCommand Condition="'$(TargetArchitecture)' != 'wasm' Or '$(TargetOs)' != 'browser'">$([MSBuild]::NormalizePath('%(ProjectDir)', 'bin', '$(Configuration)', '$(NetCoreAppCurrent)', '%(TestRuntimeIdentifier)', 'publish', 'project'))</TestCommand>
<TestCommand Condition="'$(TargetArchitecture)' == 'wasm' And '$(TargetOs)' == 'browser'">$([MSBuild]::NormalizePath('%(ProjectDir)', 'bin', '$(Configuration)', '$(NetCoreAppCurrent)', '%(TestRuntimeIdentifier)', 'AppBundle', 'run-v8.sh'))</TestCommand>
<TestExecutionDirectory Condition="'$(TargetArchitecture)' != 'wasm' Or '$(TargetOs)' != 'browser'">$([MSBuild]::NormalizeDirectory('%(ProjectDir)', 'bin', '$(Configuration)', '$(NetCoreAppCurrent)', '%(TestRuntimeIdentifier)', 'publish'))</TestExecutionDirectory>
<TestExecutionDirectory Condition="'$(TargetArchitecture)' == 'wasm' And '$(TargetOs)' == 'browser'">$([MSBuild]::NormalizeDirectory('%(ProjectDir)', 'bin', '$(Configuration)', '$(NetCoreAppCurrent)', '%(TestRuntimeIdentifier)', 'AppBundle'))</TestExecutionDirectory>
<TestCommand Condition="'$(TargetArchitecture)' != 'wasm' Or '$(TargetOs)' != 'browser'">$([MSBuild]::NormalizePath('%(ProjectDir)', 'bin', '$(Configuration)', '%(TestTargetFramework)', '%(TestRuntimeIdentifier)', 'publish', 'project'))</TestCommand>
<TestCommand Condition="'$(TargetArchitecture)' == 'wasm' And '$(TargetOs)' == 'browser'">$([MSBuild]::NormalizePath('%(ProjectDir)', 'bin', '$(Configuration)', '%(TestTargetFramework)', '%(TestRuntimeIdentifier)', 'AppBundle', 'run-v8.sh'))</TestCommand>
<TestExecutionDirectory Condition="'$(TargetArchitecture)' != 'wasm' Or '$(TargetOs)' != 'browser'">$([MSBuild]::NormalizeDirectory('%(ProjectDir)', 'bin', '$(Configuration)', '%(TestTargetFramework)', '%(TestRuntimeIdentifier)', 'publish'))</TestExecutionDirectory>
<TestExecutionDirectory Condition="'$(TargetArchitecture)' == 'wasm' And '$(TargetOs)' == 'browser'">$([MSBuild]::NormalizeDirectory('%(ProjectDir)', 'bin', '$(Configuration)', '%(TestTargetFramework)', '%(TestRuntimeIdentifier)', 'AppBundle'))</TestExecutionDirectory>
</TestConsoleAppSourceFiles>
</ItemGroup>

Expand Down Expand Up @@ -70,7 +72,7 @@
<WriteLinesToFile File="$(_projectFile)"
Lines="$([System.IO.File]::ReadAllText('$(ProjectTemplate)')
.Replace('{MicrosoftNETCoreAppVersion}', '$(MicrosoftNETCoreAppVersion)')
.Replace('{NetCoreAppCurrent}', '$(NetCoreAppCurrent)')
.Replace('{TestTargetFramework}', '%(TestConsoleApps.TestTargetFramework)')
.Replace('{NetCoreAppMaximumVersion}', '$(NetCoreAppMaximumVersion)')
.Replace('{TargetingPackDir}','$(MicrosoftNetCoreAppRefPackDir)')
.Replace('{RuntimeIdentifier}','%(TestConsoleApps.TestRuntimeIdentifier)')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ internal enum HRESULT : int
E_FAIL = unchecked((int)0x80004005),
E_UNEXPECTED = unchecked((int)0x8000FFFF),
STG_E_INVALIDFUNCTION = unchecked((int)0x80030001L),
STG_E_INVALIDPOINTER = unchecked((int)0x80030009),
STG_E_INVALIDPARAMETER = unchecked((int)0x80030057),
STG_E_INVALIDFLAG = unchecked((int)0x800300FF),
E_ACCESSDENIED = unchecked((int)0x80070005),
Expand Down
51 changes: 51 additions & 0 deletions src/libraries/Common/src/Interop/Windows/Ole32/Interop.IStream.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.IO;
using System.Runtime.InteropServices;

Expand Down Expand Up @@ -62,5 +63,55 @@ void Stat(

IStream Clone();
}

// This needs to be duplicated from IStream above because ComWrappers doesn't support re-using
// ComImport interfaces. The above interface can be deleted once all usages of the built-in COM support
eerhardt marked this conversation as resolved.
Show resolved Hide resolved
// are converted to use ComWrappers.
internal interface IStreamComWrapper
{
static readonly Guid IID = new Guid(0x0000000C, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);

// pcbRead is optional so it must be a pointer
unsafe void Read(byte* pv, uint cb, uint* pcbRead);

// pcbWritten is optional so it must be a pointer
unsafe void Write(byte* pv, uint cb, uint* pcbWritten);

// SeekOrgin matches the native values, plibNewPosition is optional
unsafe void Seek(long dlibMove, SeekOrigin dwOrigin, ulong* plibNewPosition);

void SetSize(ulong libNewSize);

// pcbRead and pcbWritten are optional
unsafe void CopyTo(
IStreamComWrapper pstm,
ulong cb,
ulong* pcbRead,
ulong* pcbWritten);

void Commit(uint grfCommitFlags);

void Revert();

// Using PreserveSig to allow explicitly returning the HRESULT for "not supported".

[PreserveSig]
eerhardt marked this conversation as resolved.
Show resolved Hide resolved
HRESULT LockRegion(
ulong libOffset,
ulong cb,
uint dwLockType);

[PreserveSig]
HRESULT UnlockRegion(
ulong libOffset,
ulong cb,
uint dwLockType);

void Stat(
out STATSTG pstatstg,
STATFLAG grfStatFlag);

IStreamComWrapper Clone();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<linker>
<assembly fullname="System.Drawing.Common, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51">
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
<argument>ILLink</argument>
<argument>IL2050</argument>
<property name="Scope">member</property>
<property name="Target">M:System.Drawing.Icon.OleCreatePictureIndirect(System.Drawing.Icon.PICTDESC,System.Guid@,System.Boolean)</property>
</attribute>
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
<argument>ILLink</argument>
<argument>IL2050</argument>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,13 @@
<Compile Include="$(CommonPath)Interop\Windows\Interop.HRESULT.cs"
Link="Common\Interop\Windows\Interop.HRESULT.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetsWindows)' == 'true' and $([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net5.0'))">
<Compile Include="System\Drawing\Icon.Windows.COMWrappers.cs" />
<Compile Include="System\Drawing\DrawingComWrappers.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetsWindows)' == 'true' and !$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net5.0'))">
<Compile Include="System\Drawing\Icon.Windows.NoCOMWrappers.cs" />
</ItemGroup>
<!-- Unix specific -->
<ItemGroup Condition="'$(TargetsUnix)' == 'true'">
<Compile Include="System\Drawing\Graphics.Unix.cs" />
Expand Down
Loading