Solved

compare BSTR

Posted on 2000-02-26
7
3,868 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

708 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

14 Experts available now in Live!

Get 1:1 Help Now