-
Notifications
You must be signed in to change notification settings - Fork 1k
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
CA1838 Avoid 'StringBuilder' parameters for P/Invokes #8113
Conversation
src/System.Windows.Forms.Primitives/src/Windows/Win32/PInvoke.MAX_PATH.cs
Outdated
Show resolved
Hide resolved
@@ -10791,12 +10791,15 @@ public new bool ResizeRedraw | |||
public new void WndProc(ref Message m) => base.WndProc(ref m); | |||
} | |||
|
|||
private static string GetClassName(IntPtr hWnd) | |||
private static unsafe string GetClassName(HWND hWnd) |
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 move to the PInvoke namespace?
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.
I believe there is another place where we call PInvoke.GetClassName
in our codebase. If this is the case, we should move this to PInvoke namespace and call to this method in the other places we are using PInvoke.GetClassName
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.
I didn't move this because its a wrapper and isn't used in the other calls. I am happy to still move it. The other uses avoid string allocations.
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.
If you think this is a dup, feel free to remove this. I can't recall exact reasons why I copied it here.
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.
Since its a wrapper of the pinvoke and we don't reuse it, I think it can stay here.
src/System.Windows.Forms.Primitives/src/Windows/Win32/PInvoke.MAX_CLASS_NAME.cs
Outdated
Show resolved
Hide resolved
I don't think the vb.net PInvokes are able to avoid stringbuilder. We would have to pull it into the PInvoke class and then have a wrapper that returns the needed information. |
src/System.Windows.Forms.Primitives/src/Windows/Win32/PInvoke.GetModuleFileNameLongPath.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms/src/System/Windows/Forms/Application.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms/src/System/Windows/Forms/TaskDialog.cs
Outdated
Show resolved
Hide resolved
@@ -10791,12 +10791,15 @@ public new bool ResizeRedraw | |||
public new void WndProc(ref Message m) => base.WndProc(ref m); | |||
} | |||
|
|||
private static string GetClassName(IntPtr hWnd) | |||
private static unsafe string GetClassName(HWND hWnd) |
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.
I believe there is another place where we call PInvoke.GetClassName
in our codebase. If this is the case, we should move this to PInvoke namespace and call to this method in the other places we are using PInvoke.GetClassName
src/System.Windows.Forms.Primitives/src/Windows/Win32/PInvoke.MAX_PATH.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms.Primitives/src/Windows/Win32/PInvoke.MAX_PATH.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms.Primitives/src/Windows/Win32/PInvoke.MAX_PATH.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms.Primitives/src/Windows/Win32/PInvoke.GetModuleFileNameLongPath.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms.Primitives/src/Windows/Win32/PInvoke.GetModuleFileNameLongPath.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms.Primitives/src/Windows/Win32/PInvoke.GetModuleFileNameLongPath.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms.Primitives/src/Windows/Win32/PInvoke.GetModuleFileNameLongPath.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms.Primitives/src/Windows/Win32/PInvoke.GetModuleFileNameLongPath.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms.Primitives/src/Windows/Win32/PInvoke.GetModuleFileNameLongPath.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/RichTextBoxTests.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/RichTextBoxTests.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/RichTextBoxTests.cs
Outdated
Show resolved
Hide resolved
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.
Left a number of comments. Biggest thing is not to try and guess what the exact max allowable path will be (outside of constraining to not go over 32K characters for sanity).
src/System.Windows.Forms.Primitives/src/Windows/Win32/PInvoke.GetModuleFileNameLongPath.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms.Primitives/src/Windows/Win32/PInvoke.GetModuleFileNameLongPath.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms.Primitives/src/Windows/Win32/PInvoke.GetModuleFileNameLongPath.cs
Show resolved
Hide resolved
src/System.Windows.Forms.Primitives/src/Windows/Win32/PInvoke.GetModuleFileNameLongPath.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms.Primitives/src/Windows/Win32/PInvoke.GetModuleFileNameLongPath.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms.Primitives/src/Windows/Win32/PInvoke.GetWindowText.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms.Primitives/src/Windows/Win32/PInvoke.GetWindowText.cs
Outdated
Show resolved
Hide resolved
@@ -6,6 +6,7 @@ | |||
|
|||
[assembly: System.Runtime.InteropServices.ComVisible(false)] | |||
|
|||
[assembly: InternalsVisibleTo("Microsoft.VisualBasic.Forms, PublicKey=00000000000000000400000000000000")] |
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 should have worked but we are still getting build errors. I don't know why.
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 build is failing for other reasons:
##[error]src\System.Windows.Forms.Primitives\src\Windows\Win32\PInvoke.GetModuleFileNameLongPath.cs(6,1): error IDE0005: (NETCORE_ENGINEERING_TELEMETRY=Build) Using directive is unnecessary.
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.
Now it has the failures:
error BC30389: (NETCORE_ENGINEERING_TELEMETRY=Build) 'Windows.Win32.PInvoke' is not accessible in this context because it is 'Friend'.
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.
Microsoft.VisualBasic.Forms doesn't reference System.Windows.Forms.Primitives project directly.
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.
...and I personally don't think it should.
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.
IVT is not transitive.
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.
@RussKie Did you want me to remove the Microsoft.VisualBasic.Forms
changes and we can work out what to do for it in a separate PR?
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.
I defer the decision to @lonitra and @JeremyKuhne.
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.
@Elachan it's probably better to do the VB stuff separately for clarity.
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.
Removed it.
src/System.Windows.Forms.Primitives/src/Windows/Win32/PInvoke.GetModuleFileNameLongPath.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms.Primitives/src/Windows/Win32/PInvoke.GetModuleFileNameLongPath.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms.Primitives/src/Windows/Win32/PInvoke.GetModuleFileNameLongPath.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms.Primitives/src/Windows/Win32/PInvoke.GetModuleFileNameLongPath.cs
Outdated
Show resolved
Hide resolved
/azp run |
Azure Pipelines successfully started running 2 pipeline(s). |
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.
Thanks for your effort and patience here!
Fixes #3983
Analyzer:
Work based on:
TODO:
winforms/src/Microsoft.VisualBasic.Forms/src/Microsoft/VisualBasic/Helpers/NativeMethods.vb
Lines 30 to 33 in 15ab89b
Related: #7887
Microsoft Reviewers: Open in CodeFlow