Solved

covert char * to BSTR *

Posted on 2001-07-15
5
548 Views
Last Modified: 2008-02-26
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
Comment
Question by:gshriki
5 Comments
 
LVL 3

Expert Comment

by:jlsjls
Comment Utility
You could use the API-function : WideCharToMultiByte : this function maps a wide character string (BSTR) to a multibyte character string (char*).
0
 

Author Comment

by:gshriki
Comment Utility
I need the exact opposite:
I need to convert char* to BSTR
A code example will be appreciated.
0
 

Accepted Solution

by:
ducpham earned 200 total points
Comment Utility
you can use _bstr_t object as follows:

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

Regards,
:)
0
 
LVL 1

Expert Comment

by:ccaprar
Comment Utility
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
 

Author Comment

by:gshriki
Comment Utility
can u plz give me the BSTR to char* conversion?
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now