Solved

How to convert from CString to BSTR

Posted on 2004-04-16
2
1,243 Views
Last Modified: 2010-08-05
I need to pass a CString varaible to a BSTR variable. How do I do that?

The old line was:
BSTR bstr = SysAllocString(L"some text string");

How can I replace the old value to my CString value:
CString str = "abc";
BSTR bstr = ???
0
Comment
Question by:sungenwang
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 125 total points
ID: 10846151
You could eithre use

CString str = "abc";
BSTR bstr = str.AllocSysString ();

or

CString str = "abc";
BSTR bstr;

str.SetSysString ( &bstr);
0
 
LVL 14

Author Comment

by:sungenwang
ID: 10846230
That was quick!
I knew this is child play for some of you folks... Thanks!
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

624 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