Exa
Exa

Reputation: 4110

CMapStringToString can't handle Unicode?

I have a CMapStringToString that I fill with unicode characters.

m_oMap.SetAt( CString(bstrID), CString(bstrText));

bstrText is a BSTR containing unicode characters that are actually stored correctly (Cyrillic symbols, Japanese symbols, etc.). At this point bstrText contains e.g. "Калибровка".

However, if I try to retrieve the symbols the unicode encoding seems to be lost:

BOOL b = m_oMap.Lookup((LPCTSTR)key, rValue); // key and value are CString&

After this line rValue e.g. only contains "??????????" instead of "Калибровка".

What is happening here?

Upvotes: 1

Views: 317

Answers (1)

Mr.C64
Mr.C64

Reputation: 42944

I've created a simple MFC dialog-based application with VS2015, added a string resource IDS_TEST_UNICODE containing your Unicode string, and the following MFC code works fine:

void CTestMfcApp1Dlg::OnBnClickedButtonTest1()
{
    CMapStringToString m;

    CString value(MAKEINTRESOURCE(IDS_TEST_UNICODE));
    m.SetAt(CString(L"MyKey"), value);

    CString readValue;
    VERIFY( m.Lookup(L"MyKey", readValue) );
    VERIFY(readValue == value);
}

as you can note from the screenshot at the bottom.

May it be just possible that CMapStringToString works fine in your case as well, and instead you are having problems just visualizing the content of the value string retrieved from the map?

Screenshot

Upvotes: 1

Related Questions