What does Windows error code 1401 (ERROR_INVALID_MENU_HANDLE) mean?

 
Previous Next
ERROR_INVALID_WINDOW_HANDLE ERROR_INVALID_CURSOR_HANDLE

ERROR_INVALID_MENU_HANDLE

The HMENU is not a valid menu object

Menu handles are a distinct USER32 object type. A value that is valid as an HWND, child-control ID, or arbitrary integer does not become a menu merely because those fields sometimes share the HMENU-sized parameter type in Win32 APIs.

The most common diagnostic mistake is at window creation. For an overlapped or pop-up window, the hMenu argument of CreateWindowEx is a menu handle; for a child window, the same parameter is the child-window identifier. Passing a control ID later to a menu API can therefore look superficially plausible while representing the wrong object class.

What to check

  • Trace where the value was obtained: CreateMenu, LoadMenu, GetMenu, or a child ID.
  • Check destruction order and calls to DestroyMenu.
  • Do not cast a control identifier or command ID into HMENU for menu-management functions.
  • For menu lookup failures after a valid handle is established, inspect item identifiers separately.

Use ERROR_MENU_ITEM_NOT_FOUND for a valid menu where a requested item is missing; this code says the menu handle itself is invalid.

References


Looking for a different code? Search another status or error code.