[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1005
  • Last Modified:

convert char** to BSTR

how to convert char** to BSTR
0
Sohela
Asked:
Sohela
  • 2
1 Solution
 
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
 
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now