Click here to Skip to main content
12,358,242 members (71,436 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C++ C Visual-Studio
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 16-Oct-12 23:58pm
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?
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160621.1 | Last Updated 17 Oct 2012
Copyright © CodeProject, 1999-2016
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