-
Notifications
You must be signed in to change notification settings - Fork 971
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
Test AxHost ICustomTypeDescriptor implementation #3366
Conversation
f908216
to
1895219
Compare
src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AxHostTests.cs
Outdated
Show resolved
Hide resolved
...ystem.Windows.Forms/tests/UnitTests/System/Windows/Forms/AxHost.AxPropertyDescriptorTests.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms/src/System/Windows/Forms/AxHost.AxPropertyDescriptor.cs
Show resolved
Hide resolved
src/System.Windows.Forms/src/System/Windows/Forms/AxHost.AxPropertyDescriptor.cs
Show resolved
Hide resolved
src/System.Windows.Forms/src/System/Windows/Forms/AxHost.AxPropertyDescriptor.cs
Show resolved
Hide resolved
Codecov Report
@@ Coverage Diff @@
## master #3366 +/- ##
====================================================
- Coverage 64.68320% 34.27647% -30.40673%
====================================================
Files 1318 890 -428
Lines 484169 253833 -230336
Branches 39912 36794 -3118
====================================================
- Hits 313176 87005 -226171
+ Misses 165621 162049 -3572
+ Partials 5372 4779 -593
|
Hey you guys I'm trying to test AxHost a little more and its interactions with native interfaces/com objects. I have a self-contained here https://github.com/hughbe/AxHost-tests (run Basically in a separate assembly ( <PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<EnableComHosting>true</EnableComHosting>
<EnableRegFreeCom>true</EnableRegFreeCom>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<NoWarn>CS0649;$(NoWarn)</NoWarn>
</PropertyGroup> This has a class Then I have a separate test project ( [STAThread]
static void Main()
{
try
{
var o = Activator.CreateInstance(Type.GetTypeFromCLSID(typeof(Server).GUID));
Console.WriteLine(o.GetType());
Guid clsid = typeof(Server).GUID;
Guid iid = new Guid("{00000000-0000-0000-C000-000000000046}");
HRESULT hr = CoCreateInstance(
ref clsid,
IntPtr.Zero,
Ole32.CLSCTX.INPROC_SERVER,
ref iid,
out object res);
Console.WriteLine(res.GetType());
var control = new SubAxHost(typeof(Server).GUID.ToString());
Assert.NotEqual(IntPtr.Zero, control.Handle);
int invalidatedCallCount = 0;
control.Invalidated += (sender, e) => invalidatedCallCount++;
int styleChangedCallCount = 0;
control.StyleChanged += (sender, e) => styleChangedCallCount++;
int createdCallCount = 0;
control.HandleCreated += (sender, e) => createdCallCount++;
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
Console.WriteLine("Please Love Me");
}
private class SubAxHost : AxHost
{
public SubAxHost(string clsidString) : base(clsidString)
{
}
}
}
private class SubAxHost : AxHost
{
public SubAxHost(string clsidString) : base(clsidString)
{
}
} First things first there appears a bug if we don't manually copy
and
The error When I do copy the
It seems like in the following code
Is there a way to force this behaviour? Am I misunderstanding COM a bit. I would have expected that if you create a COM class (defined in C# in this case) using Also, separately I found a bug in X System.Windows.Forms.Tests.AxHostTests.AxHost_Handle_GetNotIOleObject_ThrowsInvalidCastException [9ms]
Error Message:
System.ArgumentException : The object's type must be __ComObject or derived from __ComObject. (Parameter 'o')
Stack Trace:
at System.Runtime.InteropServices.Marshal.FinalReleaseComObject(Object o)
at System.Windows.Forms.AxHost.ReleaseAxControl()
at System.Windows.Forms.AxHost.TransitionDownTo(Int32 state)
at System.Windows.Forms.AxHost.Dispose(Boolean disposing)
at System.ComponentModel.Component.Dispose()
at System.Windows.Forms.Tests.AxHostTests.<>c.<AxHost_Handle_GetNotIOleObject_ThrowsInvalidCastException>b__3_0() in C:\Users\hughbe\source\repos\AxHost\System.Windows.Forms.Tests\AxHostTests.cs:line 62
at System.Windows.Forms.Tests.ActivationContext.UsingManifestDo(String manifest, Action action) in C:\Users\hughbe\source\repos\AxHost\System.Windows.Forms.Tests\ActivationContext.cs:line 41
at System.Windows.Forms.Tests.AxHostTests.AxHost_Handle_GetNotIOleObject_ThrowsInvalidCastException() in C:\Users\hughbe\source\repos\AxHost\System.Windows.Forms.Tests\AxHostTests.cs:line 57 The fix would be to guard the call to |
|
:( I guess i could write these tests against a native implementation. Or I could do some dodgy Got to really really really get #1932 working haha |
If you want to implement something to put into an AxHost your best bet is using ATL/MFC. The MFC wizards for creating ActiveX controls may still be functional and clicking through the wizard may create a basic control you can put in an AxHost. |
Probably not worth it, I'd rather fail earlier before the instance gets into a bad state. Trying to properly dispose a bad state is not something you should bother doing. |
Also be warned that if you try going that route, the default VS project settings are to register the build output globally. The first thing I do with new projects is turn that off (unsetting "Register output" in "Linker" category of project settings) and then use regfree COM manifests in the consuming application instead. Feel free to ping me on gitter btw. if you want to chat about this, its pretty hard to get started with this kind of stuff if you don't know anything about it. |
Don't know if it helps you, but created a sample repo with an MFC ActiveX control hosted in Desktop/Core WinForms projects. The wizard creates a simple control which draws a circle. You can start from there and add properties to the control which will be settable in the AxHost design time. steps taken
|
I'll do that in another PR then. I've managed to find a good way to make it work with cmake |
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
6d5bc84
to
55cff33
Compare
Codecov Report
@@ Coverage Diff @@
## master #3366 +/- ##
====================================================
- Coverage 66.58991% 35.44950% -31.14042%
====================================================
Files 1338 895 -443
Lines 501564 253524 -248040
Branches 40847 36761 -4086
====================================================
- Hits 333991 89873 -244118
+ Misses 162033 158803 -3230
+ Partials 5540 4848 -692
|
|
||
namespace System.Windows.Forms.Tests | ||
{ | ||
public class AxHostPropertyDescriptorTests : IClassFixture<ThreadExceptionFixture> |
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 would have needed [Collection("Sequential")]
since otherwise WebBrowser currently is corrupting memory. I'm getting crashes locally again after this PR was merged, will extend the workaround by adding the attribute.
@hughbe @RussKie please keep this in mind if there are more AxHost tests coming.
Proposed Changes
Microsoft Reviewers: Open in CodeFlow