covert char * to BSTR *

I have a Unicode string which i defined like this:
BSTR str1=sysAllocStringLen(L"Hello",5);

But now I need to convert it from (char *)
(Simple casting isn't good enough)
gshrikiAsked:
Who is Participating?
 
ducphamCommented:
you can use _bstr_t object as follows:

#include <comdef.h>
....
{
...
    char* s = "Hello";
    _bstr_t t(s);
    BSTR bs = t.copy();
....
}

Regards,
:)
0
 
jlsjlsCommented:
You could use the API-function : WideCharToMultiByte : this function maps a wide character string (BSTR) to a multibyte character string (char*).
0
 
gshrikiAuthor Commented:
I need the exact opposite:
I need to convert char* to BSTR
A code example will be appreciated.
0
 
ccaprarCommented:
another nice way for performing conversions:

BSTR method x(char* sz) {
  USES_CONVERSION;

  return A2BSTR(sz);
}

You might take a look at the following MSDN article:

http://msdn.microsoft.com/library/en-us/wceatl/htm/atlapi2_42.asp

0
 
gshrikiAuthor Commented:
can u plz give me the BSTR to char* conversion?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.