Click here to Skip to main content
11,428,876 members (62,375 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ C Visual-Studio BSTR
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 17-Oct-12 0:58am
Comments
Richard MacCutchan at 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?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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:
if (0 == wcscmp(var, L"a"))
    printf("they are equal\n");
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

if(0== wcscmp(var, L"a"))
  {
printf("they are equal\n")
                       
 }
  Permalink  

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



Advertise | Privacy | Mobile
Web03 | 2.8.150428.2 | Last Updated 17 Oct 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100