The error is probably in this line
CMenu *pSub = menu.GetSubMenu(1);
When the menu loaded from the resources contains only one popup menu (which is a common case)
GetSubMenu()
returns
NULL
.
So pass the position
0
instead.
[EDIT]
When using
TrackPopupMenu[Ex]
, the menu must be a popup menu retrieved by calling
CMenu::GetSubMenu()
or having been created using
CMenu::CreatePopupMenu
. Using a normal menu will not work.
[/EDIT]