Working with the Shell and an object in a virtual folder
-
I am trying to enable and disable a network adapter (not release and renew). It seems the only way to do this is through the shell object. I have been grinding on this problem for over a week. Currently I am stuck trying to apply a 'verb' to an contextmenu object. Here are two relevent code snippets:
// Now loop through the menu and see if we see the enalbed menu item. bool FoundOne = false; bool ContextMenuLoop = true; CString MenuItemName; CMenu MyMenu; MyMenu.CreatePopupMenu(); MENUITEMINFO MenuItemInfo; ZeroMemory(&MenuItemInfo, sizeof(MenuItemInfo)); MenuItemInfo.cbSize = sizeof(MenuItemInfo); MenuItemInfo.fMask = MIIM_ID | MIIM_TYPE; char Buff[50]; ZeroMemory(Buff, sizeof(Buff)); MenuItemInfo.cch =49; MenuItemInfo.dwTypeData = Buff; MenuItemInfo.fType = MFT_STRING; int Offset = (int)ContextMenu->QueryContextMenu(MyMenu, 0, 1, 30000, CMF_EXPLORE); unsigned int J; // Loop through all menu items and see if it has a Disable option for (J = 0; J < MyMenu.GetMenuItemCount(); J++) { int T; T = MyMenu.GetMenuItemID(J); if (T > 0) { MyMenu.GetMenuString(T, MenuItemName, MF_BYCOMMAND); MyMenu.GetMenuItemInfo(T, &MenuItemInfo); if (DISABLE_VERB == MenuItemName) { FoundOne = true; break; } } }
At this point I have the context menu object, and actually found the DISABLE_VERB. I also MenuItemInfo for this particular menu item. So far so good...// Now that we found one, we need to cycle it if (true == FoundOne) { HRESULT Hr = NULL; CMINVOKECOMMANDINFO Cmd; ZeroMemory(&Cmd, sizeof(Cmd)); Cmd.cbSize = sizeof(CMINVOKECOMMANDINFO); **Cmd.lpVerb = MAKEINTRESOURCE(MenuItemInfo.wID);** Hr = ContextMenu->InvokeCommand(&Cmd); int L = GetLastError(); Sleep(100); Cmd.lpVerb = ENABLE_VERB; // Hr = ContextMenu->InvokeCommand(&Cmd); }
The line in bold is the key line. Its where I set my verb. If I use the DISABLE_VERB, which I just found, it gives me an invalid parameter error (80030057). I set the verb directly, such like Cmd.lpVerb = DISABLE_VERB; when I get this error. I have no idea why since I searched for it and found it. Next I tried using the wID (as it is done in this code snippet) and while it accepted the parameter, it did the wrong thing (It tried to bridge network connections). I thought the index might be off by +/- 1, but that didn't help. Can anyone tell me what I