Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert BSTR to LPCWSTR

Tags:

c++

com

atl

Here is my need

BSTR l_strArgs;
LPCWSTR  sth;
//----
//---
OutputDebugStringW(sth);

How to convert BSTR to LPCWSTR ?

Is there any header only library that coverts any string type(microsoft) to LPCWSTR type ?

like image 323
asit_dhal Avatar asked Feb 14 '26 06:02

asit_dhal


1 Answers

Just cover NULL scenario and you're good to go

BSTR l_strArgs;
LPCWSTR sth = strArgs ? strArgs : L"";

As you mentioned ATL in the tag, here is ATL-style one-liner:

OutputDebugString(CString(l_strArgs));

or, to make sure you are staying in Unicode domain:

OutputDebugStringW(CStringW(l_strArgs));
like image 180
Roman R. Avatar answered Feb 15 '26 20:02

Roman R.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!