@NGen:
And why not? In most cases ANSI is supported on the OS anyways.
Code portability.
|
Hmm, you can't embed quotes...
Yes, but in this case
george135 is being his usual soap-box thumper with irrational gut responses. You cannot break "code portability" by using OS-specific APIs. There is absolutely nothing wrong with calling an ANSI or Unicode API directly when it is the Right Thing to do.
The STL doesn't play nicely with Unicode. And it certainly wasn't designed to work with Microsoft's existing UNICODE stuff. When you ask for a
std::
string from the STL, you are explicitly asking for non-unicode entities -- a flaw in the STL, perhaps, but that's the way things stand.
If you then compile with the UNICODE flags enabled, calling the
MessageBox() macro with the standard string will definitely be the
wrong thing to do, and your application will produce garbage and/or fail.
The
correct thing to do is exactly as
NGen reported: Use
MessageBoxA() with
std::
string, and in so doing completely obviate all problems.
The MS Unicode handling is very robust and capable, and it is possible to combine the STL with it. You just have to use your mind about it. There are plenty of articles on the internet dealing with these very problems and the can of worms it opens. This is one of the best:
http://www.codeproject.com/KB/stl/upgradingstlappstounicode.aspx
(Hmm, there's also an old MS magazine article about this stuff I can't find...)
Further, there is nothing to fear when using the ANSI versions of functions over the wchar_t versions. In modern kernels, the worst is simply that the ANSI versions are stubs that call the wide versions. Boo hoo.