Skip to content

Code Quality: Replaced Vanara with CsWin32 in ContextMenu class #17136

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Lamparter
Copy link
Contributor

Resolved / Related Issues

Steps used to test these changes

WIP

Copy link
Member

@0x5bfa 0x5bfa left a comment

Choose a reason for hiding this comment

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

ContextMenu will retire in favor of my new group of helper tho.

{
fixed (byte* p = global::System.Text.Encoding.UTF8.GetBytes(value))
{
return new PCSTR(p);
Copy link
Member

Choose a reason for hiding this comment

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

I have no idea what you doing. Once getting out of fixed, the p won't be guaranteed to be fixed any longer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How do I then construct the struct from a string/int value?

Copy link
Member

@0x5bfa 0x5bfa May 21, 2025

Choose a reason for hiding this comment

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

You have to pin the address until the method you want to call is returned.

fixed (char* pName = name)
{
    // PInvoke.Method(..., pName, ...);
}

So, this case you can't create a helper like that.


public static unsafe PCSTR FromInt(int value)
{
return new PCSTR((byte*)&value);
Copy link
Member

Choose a reason for hiding this comment

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

Here too, taking pointer of an int value? For what.

@Lamparter
Copy link
Contributor Author

ContextMenu will retire in favor of my new group of helper tho.

Will it not reuse the code here?
If not, I'll close this PR.

@0x5bfa
Copy link
Member

0x5bfa commented May 21, 2025

I don't think so, I'll create a static ContextMenuManager along with JumpListManager, TrayIconManager, etc, all of which are AoT-safe.

That said, I don't think I'd be against this PR as far as this works and because I don't think mine will be implemented any time soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants