-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 stab at ComWrappers usage in the WPF #6606
base: main
Are you sure you want to change the base?
Conversation
This is minimal change which replace usage built-in COM for IThThreadMgr instance. Having ComWrappers is important to make dotnet#3811 works.
src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/Dispatcher.cs
Show resolved
Hide resolved
src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/WpfComWrappers.TfThreadMgrWrapper.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/WpfComWrappers.TfThreadMgrWrapper.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/WpfComWrappers.TfThreadMgrWrapper.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/WpfComWrappers.TfThreadMgrWrapper.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/WpfComWrappers.TfThreadMgrWrapper.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/WpfComWrappers.TfThreadMgrWrapper.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/WpfComWrappers.TfThreadMgrWrapper.cs
Outdated
Show resolved
Hide resolved
|
||
public void AdviseKeyEventSink(int clientId, [MarshalAs(UnmanagedType.Interface)] object obj, [MarshalAs(UnmanagedType.Bool)] bool fForeground) | ||
{ | ||
IntPtr unknownPtr = Marshal.GetIUnknownForObject(obj); |
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.
Leaking QI.
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.
How it is leaking here? Are you mean in case of any failures inside unmanaged part, we should release unknownPtr
?
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.
Or do you mean, once we pass COM pointer to unamanged side we can safely release all instances from unmanaged part?
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.
The Marshal.GetIUnknownForObject
and Marshal.QueryInterface
APIs both should perform an AddRef
. If the API being called with the IUnknown
instances needs to retain ownership it should call its own AddRef
. Which means unless it can be confirmed that the calling API takes over ownership of the IUnknown
and will call Release
it is a leak.
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.
Then I would say I take care of issues. At least I think so
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.
Should this be this?
IntPtr unknownPtr = default;
try
{
unknownPtr = Marshal.GetIUnknownForObject(obj);
....
src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/WpfComWrappers.TfThreadMgrWrapper.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/WpfComWrappers.TfThreadMgrWrapper.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextEditor.cs
Show resolved
Hide resolved
|
||
public void AdviseKeyEventSink(int clientId, [MarshalAs(UnmanagedType.Interface)] object obj, [MarshalAs(UnmanagedType.Bool)] bool fForeground) | ||
{ | ||
IntPtr unknownPtr = Marshal.GetIUnknownForObject(obj); |
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.
Should this be this?
IntPtr unknownPtr = default;
try
{
unknownPtr = Marshal.GetIUnknownForObject(obj);
....
src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/WpfComWrappers.TfThreadMgrWrapper.cs
Outdated
Show resolved
Hide resolved
Any movement on this? |
Description
This is minimal change which replace usage built-in COM for IThThreadMgr instance.
Having ComWrappers is important to make #3811 works.
Additionally I remove sharing headers from
UnsafeNativeMethodsTextServices.cs
since this file used just inWindowsBase.csproj
.Customer Impact
Less chance to have trimming inside WPF
Testing
Manually testing by opening/closing WPF application and doing actions
Risk
Potentially can introduce some new bugs if RCW written incorrectly. Given that I already have some experience making this kind of changes for WinForms I have doubts. I always can try ask @RussKie or @AaronRobinsonMSFT review this as additional safeguard. Hopefully they would agree, and their help is welcome.
Microsoft Reviewers: Open in CodeFlow