Solved

compare BSTR

Posted on 2000-02-26
7
3,894 Views
Last Modified: 2008-08-26
Hi Folks,

what is your preferred way of comparing BSTRs - this is the only way i know:

int func1(BSTR val)
{
if(!strcmp((char *)val, "true")) return 1;
else return 0;
}

not surprising this doesn't work anyway...

thanks and regards.

0
Comment
Question by:meverest
  • 6
7 Comments
 
LVL 5

Expert Comment

by:Wyn
ID: 2560811


int func1(BSTR val)
{
wchar_t str[]=L"true";
wchar_t* temp=val;
if(!wcscmp(++temp, temp))
return 1;
else return 0;
}
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2560812


0
 
LVL 5

Expert Comment

by:Wyn
ID: 2560831
sorry,many typo:

int func1(BSTR val)
{
wchar_t str[]=L"true";
if(!wcscmp(val,str))
return 1;
else return 0;
}
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 5

Expert Comment

by:Wyn
ID: 2560832
sorry,many typo:

int func1(BSTR val)
{
wchar_t str[]=L"true";
if(!wcscmp((wchar_t*)val,str))
return 1;
else return 0;
}
0
 
LVL 5

Accepted Solution

by:
Wyn earned 50 total points
ID: 2560836
hmmm
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2560841
Here code again in case mess you up:)

int func1(BSTR val)
{
wchar_t str[]=L"true";
if(!wcscmp((wchar_t*)val, str))

//or simply use wcscmp((...),L"true")

return 1;
else return 0
}

Regards
W.Yinan
0
 
LVL 37

Author Comment

by:meverest
ID: 2562254
thanks, wcscmp() works fine.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now