Click here to Skip to main content
15,892,697 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Can anyone please guide me how to compare BSTR variable with const char*.
I searched net but didn't found a good solution.

i did like this:-
BSTR var=L"element";

if(var=="a")
{
printf("they are equal\n");//here i get error operands are incompatible i tryed strcmp also
}
Posted
Comments
Richard MacCutchan 17-Oct-12 9:04am    
You asked me to reply on this, but there is nothing much to say, except to ask why you are not using proper string comparison functions. Also, why do you think that the strings "element" and "a" could ever be equal?

A BSTR is just a pointer to a wide character string. So you must compare with a wide string and use a string compare function:
C++
if (0 == wcscmp(var, L"a"))
    printf("they are equal\n");
 
Share this answer
 
C++
if(0== wcscmp(var, L"a"))
  {
printf("they are equal\n")
                       
 }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900