[Webinar] Streamline your web hosting managementRegister Today

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

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)
0
gshriki
Asked:
gshriki
1 Solution
 
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
 
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
 
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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

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