-
Notifications
You must be signed in to change notification settings - Fork 955
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
Use ComWrappers for IErrorInfo #6743
Merged
+1,143
−45
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
ecbd807
Use ComWrappers for IErrorInfo
kant2002 43858e9
Cleanup RCW instance after use
kant2002 5693843
Oops
kant2002 04a9f21
Fix issue
kant2002 2e247a9
Add test case for IErrorInfo handling
kant2002 4d63a34
Add second test which cover actual wrapper
kant2002 e0fd4f5
Initialize VsVarsAll when building tests project
kant2002 8e9ee85
Attempt to fix
kant2002 a89b66b
One more stupid try
kant2002 7ce1a85
Use reg-free COM for tests
kant2002 0c26318
Add ARM64 platform
kant2002 d12ffc2
Add configuration
kant2002 845989e
Ignore copying XML files for native projects
kant2002 66337df
Probably I was too smart for ARM64 changes.
kant2002 7071825
Apply suggestions from code review
kant2002 f767d8e
Add explanation about project file and cleanup of tests
kant2002 49bcdaa
Use IID_IUnknown from Primitives
kant2002 bd3fd4c
Apply suggestions from code review
kant2002 4323c93
Hide GetErrorInfo overload
kant2002 7336ab9
Add explanation
kant2002 5d9d3bb
Reuse CoCreateInstace from Primitives
kant2002 05c61f7
Apply PR feedback
kant2002 eebb1c6
Bug, stupid bug!
kant2002 3e54922
Move tests to Interop.Tests project
kant2002 71d038e
Remove not needed file
kant2002 4c33480
Remove not used Import
kant2002 f4a54d0
Remove leftovers
kant2002 b1db619
Format code
kant2002 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
@if not defined _echo @echo off | ||
|
||
:: Initializes Visual Studio developer environment. If a build architecture is passed | ||
:: as an argument, it also initializes VC++ build environment and CMakePath. | ||
|
||
set "__VCBuildArch=" | ||
if /i "%~1" == "x86" (set __VCBuildArch=x86) | ||
if /i "%~1" == "x64" (set __VCBuildArch=x86_amd64) | ||
if /i "%~1" == "arm" (set __VCBuildArch=x86_arm) | ||
if /i "%~1" == "arm64" (set __VCBuildArch=x86_arm64) | ||
if /i "%~1" == "wasm" (set __VCBuildArch=x86_amd64) | ||
|
||
:: Default to highest Visual Studio version available that has Visual C++ tools. | ||
:: | ||
:: For VS2017 and later, multiple instances can be installed on the same box SxS and VS1*0COMNTOOLS | ||
:: is no longer set as a global environment variable and is instead only set if the user | ||
:: has launched the Visual Studio Developer Command Prompt. | ||
:: | ||
:: Following this logic, we will default to the Visual Studio toolset assocated with the active | ||
:: Developer Command Prompt. Otherwise, we will query VSWhere to locate the later version of | ||
:: Visual Studio available on the machine. Finally, we will fail the script if no supported | ||
:: instance can be found. | ||
|
||
if defined VisualStudioVersion goto :VSDetected | ||
|
||
set "__VSWhere=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" | ||
set "__VSCOMNTOOLS=" | ||
|
||
if exist "%__VSWhere%" ( | ||
for /f "tokens=*" %%p in ( | ||
'"%__VSWhere%" -latest -prerelease -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath' | ||
) do set __VSCOMNTOOLS=%%p\Common7\Tools | ||
) | ||
|
||
if not exist "%__VSCOMNTOOLS%" goto :VSMissing | ||
|
||
:: Make sure the current directory stays intact | ||
set "VSCMD_START_DIR=%CD%" | ||
|
||
call "%__VSCOMNTOOLS%\VsDevCmd.bat" -no_logo | ||
|
||
:: Clean up helper variables | ||
set "__VSWhere=" | ||
set "__VSCOMNTOOLS=" | ||
set "VSCMD_START_DIR=" | ||
|
||
:VSDetected | ||
if "%VisualStudioVersion%"=="16.0" ( | ||
set __VSVersion=vs2019 | ||
set __PlatformToolset=v142 | ||
goto :SetVCEnvironment | ||
) | ||
if "%VisualStudioVersion%"=="17.0" ( | ||
set __VSVersion=vs2022 | ||
set __PlatformToolset=v142 | ||
goto :SetVCEnvironment | ||
) | ||
|
||
:VSMissing | ||
echo %__MsgPrefix%Error: Visual Studio 2019 or 2022 with C++ tools required. ^ | ||
Please see https://github.com/dotnet/runtime/blob/main/docs/workflow/requirements/windows-requirements.md for build requirements. | ||
exit /b 1 | ||
|
||
:SetVCEnvironment | ||
|
||
if "%__VCBuildArch%"=="" exit /b 0 | ||
|
||
:: Set the environment for the native build | ||
call "%VCINSTALLDIR%Auxiliary\Build\vcvarsall.bat" %__VCBuildArch% | ||
if not "%ErrorLevel%"=="0" exit /b 1 | ||
|
||
set "__VCBuildArch=" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 0 additions & 37 deletions
37
src/System.Windows.Forms.Primitives/src/Interop/OleAut32/Interop.IErrorInfo.cs
This file was deleted.
Oops, something went wrong.
49 changes: 49 additions & 0 deletions
49
src/System.Windows.Forms.Primitives/src/Interop/WinFormsComWrappers.ErrorInfoWrapper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Diagnostics.CodeAnalysis; | ||
using System.Runtime.InteropServices; | ||
using System.Windows.Forms; | ||
|
||
internal partial class Interop | ||
{ | ||
internal unsafe partial class WinFormsComWrappers | ||
{ | ||
internal class ErrorInfoWrapper | ||
JeremyKuhne marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
private IntPtr _wrappedInstance; | ||
|
||
public ErrorInfoWrapper(IntPtr wrappedInstance) | ||
{ | ||
_wrappedInstance = wrappedInstance.OrThrowIfZero(); | ||
} | ||
|
||
internal IntPtr Instance => _wrappedInstance; | ||
|
||
public void Dispose() | ||
{ | ||
Marshal.Release(_wrappedInstance); | ||
_wrappedInstance = IntPtr.Zero; | ||
} | ||
|
||
public bool GetDescription([NotNullWhen(true)] out string? pBstrDescription) | ||
{ | ||
IntPtr descriptionPtr; | ||
var result = ((delegate* unmanaged<IntPtr, IntPtr*, HRESULT>)(*(*(void***)_wrappedInstance + 5 /* IErrorInfo.GetDescription */))) | ||
(_wrappedInstance, &descriptionPtr); | ||
if (result.Succeeded()) | ||
{ | ||
pBstrDescription = Marshal.PtrToStringUni(descriptionPtr); | ||
Marshal.FreeBSTR(descriptionPtr); | ||
} | ||
else | ||
{ | ||
pBstrDescription = null; | ||
} | ||
|
||
return result.Succeeded(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/System.Windows.Forms/tests/InteropTests/NativeTests/App.manifest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1"> | ||
<assemblyIdentity | ||
type="win32" | ||
name="System.Windows.Forms.Interop.Tests" | ||
version="1.0.0.0" /> | ||
|
||
<dependency> | ||
<dependentAssembly> | ||
<!-- RegFree COM --> | ||
<assemblyIdentity | ||
type="win32" | ||
name="NativeTests.X" | ||
version="1.0.0.0"/> | ||
</dependentAssembly> | ||
</dependency> | ||
|
||
</assembly> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please update https://github.com/dotnet/winforms/blob/main/docs/building.md and describe when this script should be run?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This script right now run as part of build. For the developer no need to do anything with this script.