I am trying to initialize MENUITEMINFO for a call to InsertMenuItem. When trying to assign a const string to dwTypeData, I get an error. The code below is from MSDN samples.
I get an error for both types of assignment
mii.dwTypeData = "&Sample text";
mii.dwTypeData = L"&Sample text";
I am using Visual Studio 2019.
MENUITEMINFO mii = { sizeof(mii) };
mii.fMask = MIIM_STRING | MIIM_FTYPE | MIIM_ID | MIIM_STATE;
mii.wID = idCmdFirst + IDM_DISPLAY;
mii.fType = MFT_STRING;
mii.dwTypeData = L"&Sample Text";
mii.fState = MFS_ENABLED;
if (!InsertMenuItem(hMenu, indexMenu, TRUE, &mii))
{
return HRESULT_FROM_WIN32(GetLastError());
}
The error is Error (active) E0144 a value of type "const wchar_t *" cannot be used to initialize an entity of type "wchar_t *"
According Microsoft documentation, the second one should work. https://learn.microsoft.com/en-us/windows/win32/learnwin32/working-with-strings
Edit: This is not solved by I cannot initializate WCHAR because I cannot change the type as suggested in that answer.