Re: Converting BSTR to char*
- From: David Wilkinson <no-reply@xxxxxxxxxxxx>
- Date: Fri, 13 Oct 2006 09:11:23 -0400
Aidal wrote:
Hi NG.
First of, I'm new to VC++ and C++ in general, so don't bite my head of for asking noob questions please :)
I'm trying to build a rather simple DLL and I need to convert a BSTR to char*.
First, you should realize that a BSTR is a (special kind of) wide character string (16-bit), whereas char* is a narrow (8-bit) string.
Second, you may not really be wanting a char*. If you are in a Unicode build (a wise choice, usually) then you probably want a wchar_t*. Learn to use TCHAR, LPTSTR, etc, which are narrow in ANSI builds and wide in UNICODE builds.
Third, you probably really want a const char* (or const wchar_t*).
Fourth, use of BSTR is much easier if you use the _bstr_t wrapper. This actually maintains both a narrow and wide string internally, and has cast operators for both const char* and const wchar_t*.
C++ string handling in Windows is not easy. Good luck!
David Wilkinson
.
- References:
- Converting BSTR to char*
- From: Aidal
- Converting BSTR to char*
- Prev by Date: Re: Divide by 0 - exception thrown?
- Next by Date: Re: Divide by 0 - exception thrown?
- Previous by thread: Converting BSTR to char*
- Next by thread: Re: Converting BSTR to char*
- Index(es):
Relevant Pages
|