convert char** to BSTR

how to convert char** to BSTR
SohelaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ZoppoCommented:
Hi Sohela,

there's a function 'BSTR SysAllocString( const OLECHAR *sz );' which can be used for this.

To use it you need a OLECHAR* - to convert a 'char*' to 'const OLECHAR*' you can use the macro 'A2COLE'

So, if you have a 'char** pChar' (which is a pointer to a pointer of chars) it should be possible to do it like this:

const OLECHAR* pOleChar = A2COLE( *pChar );
BSTR str = SysAllocString( pOleChar );
// do something with the 'str'
SysFreeString( str ); // need to cleanup the allocated BSTR

Hope that helps,

ZOPPO
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SohelaAuthor Commented:
hey thanks a lot got it
0
ZoppoCommented:
Fine, that's great.
0
waysideCommented:
You could also use one of the BSTR wrapper classes such as CComBSTR or _bstr_t, both of which can take a char* in the constructor:

char ** ppChar;

...

CComBSTR myComBSTR(*ppChar);

_bstr_t my_bstr_t(*ppChar);

Then you get all of the other functionality of the classes, including the ability to detach the underlying BSTR if you need it.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.