Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CString to BSTR

Status
Not open for further replies.

sumedha77

Programmer
Joined
Sep 1, 2000
Messages
7
Location
LK
Hi,
anyone know how to convert a CString into BSTR in VC++6?
Sumedha 77
 
I would extract the data from the CString using the GetBuffer() function, then create a BSTR using the _bstr_t wrapper class like in this pseudo-code example:

function convert (CString input)
{
char temp[80];
temp = input.GetBuffer();
_bstr_t temp2((const char*)temp);
BSTR final = (BSTR)temp2;
}

Hope that helps! [sig]<p>Pat Gleason<br><a href=mailto:gleason@megsinet.net>gleason@megsinet.net</a><br><a href= > </a><br> [/sig]
 
Use CString::AllocSysString()
Look in MSDN for details
 
Thanks manish!

MSDN says that you can use CString::AllocSysString() to allocate a BSTR from CString data, and you can also use CString::SetSysString() to set an existing BSTR object with data from a CString object.

Much better! [sig]<p>Pat Gleason<br><a href=mailto:gleason@megsinet.net>gleason@megsinet.net</a><br><a href= > </a><br> [/sig]
 
Use AllocSysString ( ). this is the fuction in CString class .It returns the BSTR [sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top