Skip to content

TrackPopupMenu has the wrong return type in certain context #338

Description

@Craftplacer

Actual behavior

CsWin32 generates the function signature for TrackPopupMenu and TrackPopupMenuEx as bool, which is correct for using no parameters. The "Return value" section however states that the return value will be an UINT_PTR (IntPtr, int?) when TPM_RETURNCMD has been passed.

Expected behavior

Our function sig that we have written is this:

[DllImport(nameof(User32))]
internal static extern int TrackPopupMenuEx(IntPtr hmenu, uint fuFlags, int x, int y, IntPtr hwnd, IntPtr lptpm);

Repro steps

  1. NativeMethods.txt content:
TrackPopupMenu
TrackPopupMenuEx
  1. Any of your own code that should be shared?
unsafe
{
    // this turns into a type compiler error
    int clickedItemId = PInvoke.TrackPopupMenuEx(_hMenu, (uint)TRACK_POPUP_MENU_FLAGS.TPM_RETURNCMD, x, y, hWnd);
}

Context

  • CsWin32 version: 0.1.506-beta
  • Target Framework: net5.0-windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions