Skip to content

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

Closed
Lamparter wants to merge 1 commit into
files-community:mainfrom
Lamparter:cswin32/vanara-hmenu
Closed

Lamparter wants to merge 1 commit into
files-community:mainfrom
Lamparter:cswin32/vanara-hmenu

Conversation

@Lamparter

Copy link
Copy Markdown
Contributor

Resolved / Related Issues

Steps used to test these changes

WIP

@0x5bfa 0x5bfa left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
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?

@0x5bfa 0x5bfa May 21, 2025 •

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
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

0x5bfa commented May 21, 2025

Copy link
Copy Markdown
Member

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.

@yair100
yair100 force-pushed the main branch 2 times, most recently from 42c8207 to 4c7493f Compare July 6, 2025 15:16
@yair100 yair100 closed this Jul 29, 2025
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.

3 participants