Connecting Tech Pros Worldwide Forums | Help | Site Map

Convert BSTR(OLECHAR*) to LPWSTR (WCHAR)???

Member
 
Join Date: Mar 2008
Posts: 34
#1: Mar 14 '08
I want to convert in my COM server a BSTR var into LPWSTR

please help!!!

Moderator
 
Join Date: Mar 2007
Location: North Bend Washington USA
Posts: 5,366
#2: Mar 14 '08

re: Convert BSTR(OLECHAR*) to LPWSTR (WCHAR)???


Have you tried WideCharToMultiByte() ?
Member
 
Join Date: Mar 2008
Posts: 34
#3: Mar 19 '08

re: Convert BSTR(OLECHAR*) to LPWSTR (WCHAR)???


well sorry it's so simple to convert it

just I used this code

USES_CONVERSION;

lpwstr wchar = T2W(bstrvar);

;)
Moderator
 
Join Date: Mar 2007
Location: North Bend Washington USA
Posts: 5,366
#4: Mar 19 '08

re: Convert BSTR(OLECHAR*) to LPWSTR (WCHAR)???


Quote:

Originally Posted by nabil035

lpwstr wchar = T2W(bstrvar);

That's an ATL macro.

Here's a quote from Microsoft:
Quote:

Originally Posted by MSDN

Note The recommended way of converting to and from BSTR strings is to use the CComBSTR class. To convert to a BSTR, pass the existing string to the constructor of CComBSTR. To convert from a BSTR, use COLE2[C]DestinationType[EX], such as COLE2T.

That is, do not use the macros.

More here: http://msdn2.microsoft.com/en-us/lib...a3(VS.71).aspx.
Reply