c++comparelpcstr

How to compare LPCSTR


I have already tried strcmp and lstrcmp. I even tried to get do it with strlen but didn't work either, here is what I have

void check(LPCSTR lpText)
{
    if( strmp(lpText, "test") == 0)
    {
        MessageBoxW(0, L"equal", 0, 0); 
    }
    else
    {
        MessageBoxW(0, L"not equal", 0, 0); 
    }
}

It always returns 1 no matter what, also charset in settings is set to Use Multi-Byte Character Set if it matters.


Solution

  • Try comparing it to a wide string literal if you're using wide strings:

    if (lstrcmp(lpText, L"test") == 0) {
        // stuff
    }
    

    Edit: it seems that you were using the wrong character encoding.