Link to home
Start Free TrialLog in
Avatar of alex_registry
alex_registry

asked on

BSTR <-> char* conversions using C++ class

Hi all,

I tried to find the article where Don Box discusses many variations of
BSTR <-> char* conversion. I desperately need it.

Can any one send me that article from MSJ August 1995 Interfaces and the Registry/GetActiveObject Vs. MFC?

Anybody has code (C++ class) on this topic?

Thanks a lot.  

 
Avatar of chensu
chensu
Flag of Canada image

You may use the W2A macro.

String Conversion Macros
http://msdn.microsoft.com/library/default.asp?URL=/library/devprods/vs6/visualc/vcmfc/_atl_string_conversion_macros.htm

TN059: Using MFC MBCS/Unicode Conversion Macros
http://msdn.microsoft.com/library/default.asp?URL=/library/devprods/vs6/visualc/vcmfc/_mfcnotes_tn059.htm

You may also use the _bstr_t class that has the _bstr_t::wchar_t* and _bstr_t::char* operators if you are using Visual C++ 5.0 or later.

The MSJ August 1995 source code can be downloaded at
http://www.microsoft.com/msj/code1993to1997/MSJAUG95.EXE
Avatar of mnewton022700
mnewton022700

The article:
   MSJ August, 1995 - Interface Enumeration/GetActiveObject vs. MFC

Can be found at:
   http://www.microsoft.com/MSJ/0895/activex0895.htm
Avatar of alex_registry

ASKER

I had visited all links you posted. I would like to see C++ functions that deal with these conversions.

Anyway, I really appreciate your effort. Thanks a lot.

Alex
The actual function to do the conversion is the Win32 API function WideCharToMultiByte.
Alex,

I guess that you must be debating who to award the points to.

You should award them to the person who best answered your question. If that person was Chensu, then award them to him. If it was me, then reject Chensu's answer and accept my comment.

If you aren't sure, then just give them to Chensu since he answered first.
Does any one has a class solution?
Adjusted points from 200 to 245
char* <-> BSTR
wchar_t* <-> BSTR
char* <-> wchar_t*

So, there should be 6 conversions covered be this class(es).

alex_registry
The _bstr_t class is exactly what you want. The source code is in the comutil.h file.
Adjusted points from 245 to 440
I wanna a class. Class please.
ASKER CERTIFIED SOLUTION
Avatar of aljehin
aljehin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Answer accepted