Solved

How to convert from CString to BSTR

Posted on 2004-04-16
2
1,185 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
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
  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 tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

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

11 Experts available now in Live!

Get 1:1 Help Now