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

Fix inversion of conditional #4685

Merged
merged 9 commits into from
Aug 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
41 changes: 41 additions & 0 deletions Winforms.sln
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Windows.Forms.Analyz
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Windows.Forms.Analyzers.CSharp.Tests", "src\System.Windows.Forms.Analyzers.CSharp\tests\UnitTests\System.Windows.Forms.Analyzers.CSharp.Tests.csproj", "{714EC82C-D4E0-4E14-9C34-4F270774D384}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NativeHost", "src\System.Windows.Forms\tests\IntegrationTests\NativeHost\NativeHost.vcxproj", "{B68FD1FC-EA37-40F2-BBBD-77577A0A1815}"
ProjectSection(ProjectDependencies) = postProject
{3129970B-A4EB-46AC-B163-18A5557B11BD} = {3129970B-A4EB-46AC-B163-18A5557B11BD}
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NativeHost.ManagedControl", "src\System.Windows.Forms\tests\IntegrationTests\NativeHost.ManagedControl\NativeHost.ManagedControl.csproj", "{3129970B-A4EB-46AC-B163-18A5557B11BD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -1019,6 +1026,38 @@ Global
{714EC82C-D4E0-4E14-9C34-4F270774D384}.Release|x64.Build.0 = Release|Any CPU
{714EC82C-D4E0-4E14-9C34-4F270774D384}.Release|x86.ActiveCfg = Release|Any CPU
{714EC82C-D4E0-4E14-9C34-4F270774D384}.Release|x86.Build.0 = Release|Any CPU
{B68FD1FC-EA37-40F2-BBBD-77577A0A1815}.Debug|Any CPU.ActiveCfg = Debug|x64
{B68FD1FC-EA37-40F2-BBBD-77577A0A1815}.Debug|Any CPU.Build.0 = Debug|x64
{B68FD1FC-EA37-40F2-BBBD-77577A0A1815}.Debug|arm64.ActiveCfg = Debug|x64
{B68FD1FC-EA37-40F2-BBBD-77577A0A1815}.Debug|arm64.Build.0 = Debug|x64
{B68FD1FC-EA37-40F2-BBBD-77577A0A1815}.Debug|x64.ActiveCfg = Debug|x64
{B68FD1FC-EA37-40F2-BBBD-77577A0A1815}.Debug|x64.Build.0 = Debug|x64
{B68FD1FC-EA37-40F2-BBBD-77577A0A1815}.Debug|x86.ActiveCfg = Debug|Win32
{B68FD1FC-EA37-40F2-BBBD-77577A0A1815}.Debug|x86.Build.0 = Debug|Win32
{B68FD1FC-EA37-40F2-BBBD-77577A0A1815}.Release|Any CPU.ActiveCfg = Release|x64
{B68FD1FC-EA37-40F2-BBBD-77577A0A1815}.Release|Any CPU.Build.0 = Release|x64
{B68FD1FC-EA37-40F2-BBBD-77577A0A1815}.Release|arm64.ActiveCfg = Release|x64
{B68FD1FC-EA37-40F2-BBBD-77577A0A1815}.Release|arm64.Build.0 = Release|x64
{B68FD1FC-EA37-40F2-BBBD-77577A0A1815}.Release|x64.ActiveCfg = Release|x64
{B68FD1FC-EA37-40F2-BBBD-77577A0A1815}.Release|x64.Build.0 = Release|x64
{B68FD1FC-EA37-40F2-BBBD-77577A0A1815}.Release|x86.ActiveCfg = Release|Win32
{B68FD1FC-EA37-40F2-BBBD-77577A0A1815}.Release|x86.Build.0 = Release|Win32
{3129970B-A4EB-46AC-B163-18A5557B11BD}.Debug|Any CPU.ActiveCfg = Debug|x64
{3129970B-A4EB-46AC-B163-18A5557B11BD}.Debug|Any CPU.Build.0 = Debug|x64
{3129970B-A4EB-46AC-B163-18A5557B11BD}.Debug|arm64.ActiveCfg = Debug|x64
{3129970B-A4EB-46AC-B163-18A5557B11BD}.Debug|arm64.Build.0 = Debug|x64
Comment on lines +1045 to +1048
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is weird but consistent with the other native project you're building

{3129970B-A4EB-46AC-B163-18A5557B11BD}.Debug|x64.ActiveCfg = Debug|x64
{3129970B-A4EB-46AC-B163-18A5557B11BD}.Debug|x64.Build.0 = Debug|x64
{3129970B-A4EB-46AC-B163-18A5557B11BD}.Debug|x86.ActiveCfg = Debug|x86
{3129970B-A4EB-46AC-B163-18A5557B11BD}.Debug|x86.Build.0 = Debug|x86
{3129970B-A4EB-46AC-B163-18A5557B11BD}.Release|Any CPU.ActiveCfg = Release|x64
{3129970B-A4EB-46AC-B163-18A5557B11BD}.Release|Any CPU.Build.0 = Release|x64
{3129970B-A4EB-46AC-B163-18A5557B11BD}.Release|arm64.ActiveCfg = Release|x64
{3129970B-A4EB-46AC-B163-18A5557B11BD}.Release|arm64.Build.0 = Release|x64
{3129970B-A4EB-46AC-B163-18A5557B11BD}.Release|x64.ActiveCfg = Release|x64
{3129970B-A4EB-46AC-B163-18A5557B11BD}.Release|x64.Build.0 = Release|x64
{3129970B-A4EB-46AC-B163-18A5557B11BD}.Release|x86.ActiveCfg = Release|x86
{3129970B-A4EB-46AC-B163-18A5557B11BD}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -1086,6 +1125,8 @@ Global
{D3AD0BF9-F5E2-4913-9AE3-9C4998F95EA1} = {DF68A171-D27B-4E6A-8A7E-63A651622355}
{5025D7FF-EB6D-4250-B9C5-887ADFBBD952} = {E4C6C5F5-46E9-4C63-9628-26752B4D9C11}
{714EC82C-D4E0-4E14-9C34-4F270774D384} = {D3AD0BF9-F5E2-4913-9AE3-9C4998F95EA1}
{B68FD1FC-EA37-40F2-BBBD-77577A0A1815} = {680FB14C-7B0C-4D63-9F1A-18ACCDB0F52A}
{3129970B-A4EB-46AC-B163-18A5557B11BD} = {680FB14C-7B0C-4D63-9F1A-18ACCDB0F52A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7B1B0433-F612-4E5A-BE7E-FCF5B9F6E136}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
[assembly: InternalsVisibleTo("MauiRichTextBoxTests, PublicKey=00000000000000000400000000000000")]
[assembly: InternalsVisibleTo("MauiTestsHelper, PublicKey=00000000000000000400000000000000")]
[assembly: InternalsVisibleTo("MauiTabControlTests, PublicKey=00000000000000000400000000000000")]
[assembly: InternalsVisibleTo("NativeHost.ManagedControl, PublicKey=00000000000000000400000000000000")]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only necessary because I don't know how to set CompModSwitches via configuration settings

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

App.config did not work? winforms removed dependency but the functionality should be there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it was removed entirely, I'll try if it works

Copy link
Contributor Author

@weltkante weltkante May 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, the instructions don't seem to work. I've tried several variations how to name the .config file, and I tried it in a standalone managed project instead of a native host, but neither seemed to work. If there are more up to date instructions I'm happy to try again. (And I made sure to also test the instructions on Desktop Framework, there they do indeed work.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strange. For this test project, we can keep as-is. I will play around with winforms projects to see if entire config is not working or some sections are not populated.


// This is needed in order to Moq internal interfaces for testing
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")]
Original file line number Diff line number Diff line change
Expand Up @@ -13834,7 +13834,7 @@ unsafe HRESULT Ole32.IOleObject.GetMiscStatus(Ole32.DVASPECT dwAspect, Ole32.OLE
return HRESULT.E_POINTER;
}

if ((dwAspect & Ole32.DVASPECT.CONTENT) != 0)
if ((dwAspect & Ole32.DVASPECT.CONTENT) == 0)
{
Debug.WriteLineIf(CompModSwitches.ActiveX.TraceInfo, "AxSource:GetMiscStatus. Status: ERROR, wrong aspect.");
Copy link
Contributor Author

@weltkante weltkante May 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug.WriteLineIf(CompModSwitches.ActiveX.TraceInfo, ...);

Note that observing this message without the above fix applied requires a debug build and running in a debugger. It can be tested by running the NativeHost from inside VS (flip the comparison back to test the original regression).

*pdwStatus = 0;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// 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.ComponentModel;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace NativeHost
{
[ComVisible(true)]
[Guid("54479E5D-EABC-448C-A767-EAFF17BC28C9")]
[ComDefaultInterface(typeof(IManagedControl))]
public partial class ManagedControl : UserControl, IManagedControl
{
public ManagedControl()
{
CompModSwitches.ActiveX.Level = System.Diagnostics.TraceLevel.Verbose;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be better to do this via some configuration, but how?


InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("Hello world from .NET");
}
}

[ComVisible(true)]
[Guid("3223D73E-286A-462C-AF8D-392D472673BF")]
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
public interface IManagedControl { }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<AssemblyName>NativeHost.ManagedControl</AssemblyName>
<Platforms>x86;x64</Platforms>
<EnableComHosting>true</EnableComHosting>

<EnableXlfLocalization>false</EnableXlfLocalization>
<UpdateXlfOnBuild>false</UpdateXlfOnBuild>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\..\System.Windows.Forms.Primitives\src\System.Windows.Forms.Primitives.csproj" />
<ProjectReference Include="..\..\..\src\System.Windows.Forms.csproj" />
</ItemGroup>

<PropertyGroup>
<!-- workaround for https://github.com/dotnet/sdk/pull/19764 -->
<EnableDynamicLoading>true</EnableDynamicLoading>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- provides minimum msbuild target stubs so we can reference the project in arcade without building it -->
<Target Name="_IsProjectRestoreSupported" Returns="@(_ValidProjectsForRestore)">
<ItemGroup>
<_ValidProjectsForRestore Include="$(MSBuildProjectFullPath)" />
</ItemGroup>
</Target>
<Target Name="Restore" />
<Target Name="Clean" />
<Target Name="Build" />
<Target Name="Rebuild" />
<Target Name="Pack" />
<Target Name="Test" />
<Target Name="IntegrationTest" />
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// 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.

#include "pch.h"

class CMainWindow : public CFrameWnd
{
public:
CWnd m_control;

BOOL Create()
{
CREATESTRUCT cs{};
cs.style = WS_OVERLAPPEDWINDOW;

if (!PreCreateWindow(cs))
return FALSE;

if (!CFrameWnd::Create(cs.lpszClass, m_strTitle))
return FALSE;

return TRUE;
}

afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;

CLSID clsid;
if (FAILED(IIDFromString(L"{54479E5D-EABC-448C-A767-EAFF17BC28C9}", &clsid)))
return -1;

if (!m_control.CreateControl(clsid, NULL, AFX_WS_DEFAULT_VIEW, CRect(), this, AFX_IDW_PANE_FIRST))
return -1;

return 0;
}

afx_msg void OnSize(UINT nType, int cx, int cy)
{
if (m_control)
m_control.SetWindowPos(NULL, 0, 0, cx, cy, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
}

afx_msg void OnSetFocus(CWnd* pOldWnd)
{
if (m_control)
m_control.SetFocus();
}

DECLARE_MESSAGE_MAP()
};

BEGIN_MESSAGE_MAP(CMainWindow, CFrameWnd)
ON_WM_CREATE()
ON_WM_SIZE()
ON_WM_SETFOCUS()
END_MESSAGE_MAP()

class CNativeHostApp : public CWinApp
{
public:
BOOL InitInstance() override
{
CWinApp::InitInstance();

AfxEnableControlContainer();

auto pWindow = new CMainWindow;
if (!pWindow)
return FALSE;

m_pMainWnd = pWindow;

pWindow->SetTitle(L"Native WinForms Host");

if (!pWindow->Create())
return FALSE;

pWindow->ShowWindow(SW_SHOW);
pWindow->UpdateWindow();

return TRUE;
}

int ExitInstance() override
{
// a clean exit is currently not possible, we would have to force a garbage collection
// to ensure WinForms had a chance to release its COM objects before MFC exits
TerminateProcess(GetCurrentProcess(), S_OK);
Comment on lines +90 to +92
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In debug builds MFC cannot cleanly shutdown due to hitting an assert, WinForms still has references to MFC. I assume forcing a GC might help, but thats not easily doable. As a workaround I just terminate the process.


return CWinApp::ExitInstance();
}
};

CNativeHostApp app;
Loading