title: IContextMenu::QueryContextMenu return not relevant menu
body: <p>Network connection shortcut (Ethernet, Wi-Fi, etc.) have different context menus depending on the connection state (connected/disconnected).
  I use the following code (Delphi) to retrieve and display this menu.</p>
  <pre><code>var pidl, child: PItemIdList;
      pFolder: IShellFolder;
      pMenu: IContextMenu;
      menu: HMENU;
  begin
    SHParseDisplayName(PChar('%USERPROFILE%\Desktop\eth0.lnk'), nil, pidl, 0, PDWORD(nil)^);
    SHBindToParent(pidl, IID_IShellFolder, Pointer(pFolder), child);
    CoTaskMemFree(pidl);
    pFolder.GetUIObjectOf(0, 1, child, IID_IContextMenu, nil, pMenu);
    menu := CreatePopupMenu;
    pMenu.QueryContextMenu(menu, 0, 0, $7fff, CMF_NORMAL);
    TrackPopupMenuEx(menu, TPM_LEFTBUTTON, 0, 0, Handle, nil);
    DestroyMenu(menu);
  end;
  </code></pre>
  <p>But after changing the connection state, I keep getting the old menu. After restarting the app I sometimes get the correct menu, however, most of the time I don't.</p>
  <p>Why it happens and how to fix it?</p>
  <p>OS: both 32- and 64-bit Windows 7/8/10</p>
  <p><strong>C++ code:</strong></p>
  <pre class="lang-cpp prettyprint-override"><code>PIDLIST_ABSOLUTE pidl;
  if SUCCEEDED(SHParseDisplayName(L&quot;%USERPROFILE%\\Desktop\\eth0.lnk&quot;, NULL, &amp;pidl, 0, NULL))
  {
    PCUITEMID_CHILD child;
    CComQIPtr&lt;IShellFolder&gt; pFolder;
    if SUCCEEDED(SHBindToParent(pidl, IID_IShellFolder, (void**)&amp;pFolder, &amp;child))
    {
      CComQIPtr&lt;IContextMenu&gt; pMenu;
      if SUCCEEDED(pFolder-&gt;GetUIObjectOf(0, 1, &amp;child, IID_IContextMenu, NULL, (void**)&amp;pMenu))
      {
        HMENU menu = CreatePopupMenu();
        if SUCCEEDED(pMenu-&gt;QueryContextMenu(menu, 0, 0, 0x7fff, CMF_NORMAL))
          TrackPopupMenuEx(menu, TPM_LEFTBUTTON, 0, 0, hWnd, NULL);
        DestroyMenu(menu);
      }
    }
    CoTaskMemFree(pidl);
  }
  </code></pre>
  <p><strong>add:</strong>
  Maybe it Windows bug. Any examples from internet and file managers like Explorer (XYPlorer, Explorer++, etc.) have the same problem. Now i see the same problem on Windows 10 Explorer. If you make a shortcut, by Drag&amp;Drop, to a network connection from &quot;Control Panel\All Control Panel Items\Network and Sharing Center\Change adapter settings\adapter_name&quot; on your Desktop, you'll see the same problem.</p>