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

NativeWindow AssignHandle/ReleaseHandle should use Set/RemoveWindowSubclass #2380

Open
schoedl opened this issue Nov 18, 2019 · 1 comment
Open
Labels
enhancement Product code improvement that does NOT require public API changes/additions
Milestone

Comments

@schoedl
Copy link

schoedl commented Nov 18, 2019

NativeWindow AssignHandle/ReleaseHandle use SetWindowLongPtr to subclass windows. This is particularly problematic if multiple independent components subclass the same window, as described here:

https://blogs.msdn.microsoft.com/anandgeorge/2010/04/10/usage-of-nativewindow-assignhandlereleasehandle-when-unmanaged-code-is-involved/

Our Office add-in coexists with other .NET add-ins and frequently runs into this problem. To solve it, NativeWindow should use the COMCTL32 SetWindowSubclass/RemoveWindowSubclass API.

@weltkante
Copy link
Contributor

weltkante commented Nov 18, 2019

Adding some context - manual subclassing via SetWindowLong is possible and supported but really hard to get right, the link from OP seems to indicate WinForms has gotten wrong some edge cases.

For what its worth the source code acknowledges that the WinForms implementation doesn't correctly implement unsubclassing, so in general I approve moving to the native implementation which is designed to handle this case correctly.

Our Office add-in coexists with other .NET add-ins and frequently runs into this problem.

.NET Core WinForms currently doesn't even support running inside Office (see #247 and #1763), so fixing it here won't help your case, if you were considering moving to .NET Core with your addin.

@merriemcgaw merriemcgaw added this to the Future milestone Feb 18, 2020
@elachlan elachlan added the enhancement Product code improvement that does NOT require public API changes/additions label Nov 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Product code improvement that does NOT require public API changes/additions
Projects
None yet
Development

No branches or pull requests

4 participants