I'm trying to build a menu dynamically in run-time, based on available video resolutions.
The MENUITEMINFO struct needs a LPWSTR for its dwTypeData. Not a LPCWSTR, but LPWSTR.
I have a line of strings and ints that I can turn into a wstring without hassle, but from there I'm just not sure.
cout << i << ": " << painterBBSizes.cx << "x" << painterBBSizes.cy << endl; MENUITEMINFO mitemInfo; std::wstringstream labelStream; std::wstring label; labelStream << painterBBSizes.cx << " x " << painterBBSizes.cy; label = labelStream.str(); LPTSTR dest = CT2W(label.c_str()); ERRORPOP(label.c_str()); // Outputs correctly. ERRORPOP(dest); // Outputs gibberish. mitemInfo.cbSize = sizeof(MENUITEMINFO); mitemInfo.fMask = MIIM_TYPE|MIIM_ID|MIIM_DATA; mitemInfo.fType = MFT_STRING; mitemInfo.fState = NULL; mitemInfo.wID = ID_END_THEGREATESTID + 1 + i; mitemInfo.hSubMenu = NULL; mitemInfo.hbmpChecked = NULL; mitemInfo.hbmpUnchecked = NULL; mitemInfo.dwItemData = NULL; mitemInfo.dwTypeData = dest; // Outputs the same gibberish. mitemInfo.cch = sizeof(dest); InsertMenuItem(g_menu, ID_END_THEGREATESTID, false, &mitemInfo);
The result is gibberish.
ERRORPOP() requires a LPCWSTR.
Anyone see the problem? Cheers.