How to compare BSTR against a string in c/c++?

前端 未结 4 1592
名媛妹妹
名媛妹妹 2021-01-11 16:32
wprintf(L\"Selecting Audio Input Device: %s\\n\", 
                            varName.bstrVal);

if(0 == strcmp(varName.bstrVal, \"IP Camera [JPEG/MJPEG]\"))...
         


        
4条回答
  •  无人及你
    2021-01-11 16:57

    You have to use wcscmp instead:

    if(0 == wcscmp(varName.bstrVal, L"IP Camera [JPEG/MJPEG]"))
    {
    }
    

    Here is a description of the BSTR data type, it has a length prefix and a real string part which is just an array of WCHAR characters. It also has 2 NULL terminators.

    The only thing to look out for is that the BSTR data type can contain embedded NULLs in the string portion, so wcscmp will only work in the cases where the BSTR does not contain embedded NULLs (which is probably most cases).

提交回复
热议问题