In article <f56vnt$tb$1$8300dec7@news.demon.co.uk>, nospam@gmail.com
says...
My advice would be to just switch entirely to a Unicode build, and be
done with it. When you get down to it, narrow character sets were
supported primarily because the Windows 3.x code base was never intended
to support wide character sets. All current versions of Windows are
based on Windows NT, which uses 16-bit characters internally. If you ask
Windows to do anything with an 8-bit character string, it just converts
that to 16-bit characters, and then operates on the result. Support for
8-bit characters was important when the Windows 3.x code base was still
in use (e.g. Windows 95, 98, etc.) but is now pretty pointless unless
you have customers who really still use those systems.
Looking at the technical side of things: Microsoft really has two
versions of most functions that deal with strings at all: one with a
'W' on the end and another with an 'A' on the end. Then they have a
(long) set of defininitions like:
#ifdef UNICODE
#define FindFirstFile FindFirstFileW
#else
#define FindFirstFile FindFirstFileA
#endif
Standard C++ provides narrow streams that work with narrow character
sets and wide streams that work with wide character sets:
std:
stringstream // narrow characters
std::wostringstream // wide characters
If you want to, it's pretty easy to provide yourself with a name that
switches from one to the other just like Microsoft does:
#ifdef UNICODE
#define tostringstream wostringstream
#else
#define tostringstream ostringstream
#endif
Then in your code, you use your new name, and it automatically switches
between the two as needed. You'll also need to use the TEXT or _T macro
on all the string literals.
#include "mystream" // has macros like the one above.
WIN32_FIND_DATA stData;
//do first find call
HANDLE hReturn = ::FindFirstFile(TEXT("C:\\*.*"), &stData);
if (hReturn == INVALID_HANDLE_VALUE) return -1;
std::tostringstream ss;
ss << stData.cFileName << TEXT("\r\n");
while (::FindNextFile( hReturn, &stData))
{
ss << stData.cFileName << TEXT("\r\n");
}
FindClose(hReturn);
std::string strResponse = ss.str();
As long as you don't try to get _too_ fancy in how you use your streams,
this should work most of the time. There are a few things that really
need to be aware of what manner of stream they're dealing with, but not
very many (and _very_ few people seem to use the things that care).
--
Later,
Jerry.
The universe is a figment of its own imagination.