-
Notifications
You must be signed in to change notification settings - Fork 955
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use ComWrappers for IErrorInfo (#6743)
* Use ComWrappers for IErrorInfo * Cleanup RCW instance after use * Oops * Fix issue * Add test case for IErrorInfo handling Rely on the MXXMLWriter60 ProgID which implement IDispath and error handling * Add second test which cover actual wrapper * Initialize VsVarsAll when building tests project * Attempt to fix * One more stupid try * Use reg-free COM for tests * Add ARM64 platform * Add configuration * Ignore copying XML files for native projects * Probably I was too smart for ARM64 changes. Attempt to mimic System.Windows.Forms.Interop.Tests * Apply suggestions from code review Co-authored-by: Igor Velikorossov <RussKie@users.noreply.github.com> * Add explanation about project file and cleanup of tests * Use IID_IUnknown from Primitives * Apply suggestions from code review Co-authored-by: Igor Velikorossov <RussKie@users.noreply.github.com> * Hide GetErrorInfo overload * Add explanation * Reuse CoCreateInstace from Primitives * Apply PR feedback * Bug, stupid bug! * Move tests to Interop.Tests project * Remove not needed file * Remove not used Import * Remove leftovers * Format code Co-authored-by: Igor Velikorossov <RussKie@users.noreply.github.com>
- Loading branch information
Showing
25 changed files
with
1,143 additions
and
45 deletions.
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 | ||
{ | ||
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.