"Aidal" wrote:
Quote
First of, I'm new to VC++ and C++ in general, so don't
bite my head of for asking noob questions please :)
No, we're not feed on human brains, I promise. :)
Quote
I'm trying to build a rather simple DLL and I need to
convert a BSTR to char*.
I've searched and found a lot of examples where people use
ATL macros or functions, but whenever I try to write
anything ATL related, my compiler starts to whine as if it
had never heared of ATL.
Probably, it really hadn't. So, you will need to tell him
about ATL a little bit.
Quote
My qyestions are:
-----------------
1) if my project doesn't have ATL enabled or whatever, how
do I inport/include somthing to enable/access ATL stuff?
All you need to do is to include correct header file. When
you're looking up for function/class in MSDN, then always
pay attention to "Requirements" section in the bottom of
page. You'll find there everything you need in order to use
this function/class: headers, libs, OS versions, etc..
However, if your intent is to create COM object with help of
ATL, then including header file won't be enough. In that
case I suggest you to go through ATL tutorial to get the
whole picture:
"ATL Tutorial"
msdn.microsoft.com/library/en-us/vcmfc98/html/_atl_atl_tutorial.asp">
msdn.microsoft.com/library/en-us/vcmfc98/html/_atl_atl_tutorial.asp
Quote
2) how do I make this conversion with and without ATL
stuff?
String conversion can be achived without ATL, too. The
easiest way is to use `_bstr_t' class. It's part of COM
compiler support, i.e. set of C++ classes provided by
compiler vendor in order to alleviate COM harshness.
[Note: _bstr_t conversion (BSTR->const char*) in VC++ 6.0
is performed in memory allocated on stack, so if you have
really large string to convert, you can cause stack
overflow. In further version of VS it was changed so _bstr_t
always allocates memory on heap for conversion.]
Basically, conversion between wide character string
(wchar_t) and narrow character strings (char) performed with
Win32 API functons: MultiByteToWideChar and
WideCharToMultiByte. All other classes, frameworks etc. use
these functions internally hiding from developer nasty
details of conversion: buffer allocations, error checking
and so on.
I strongly suggest you to read following article:
"Chapter 6: Strings"
msdn.microsoft.com/library/en-us/dnw32dev/html/ora_apiprog6_topic1.asp">
msdn.microsoft.com/library/en-us/dnw32dev/html/ora_apiprog6_topic1.asp
This is excerpt from VB programming book. However, this
chapter gives excellent overview on existing strings in
Windows world and how to convert between different kinds of
strings.
HTH
Alex
-