On Jun 19, 4:16 am, "Angus" <nos...@gmail.comwrote:
Sorry about the platform specific code here, but I include to show what I am
doing. I am trying to create a char* directory listing.
If I compile the code below as Unicode then I get memory addresses in
strResponse. But it works fine if not compiled with Unicode. How would I
edit the code to work under Unicode?
WIN32_FIND_DATA stData;
//do first find call
HANDLE hReturn = ::FindFirstFile(TEXT("C:\\*.*"), &stData);
if (hReturn == INVALID_HANDLE_VALUE) return -1;
Microsoft pushes the idea that _T and and their TEXT macros is all the
difference that you need for Windows Unicode and Windows narrow
character support. Unfortunately it isn't true (although it was more
nearly so before they started to use the standard C++ libraries).
>
std::ostringstream ss;
std::ostringstream is for char. If you want to compiler for both
Unicode and narrow characters then you'll need to use conditional
compilation to determine the correct type. For wchar_t this needs to
be std::wostringstream.
ss << stData.cFileName << "\r\n";
You will also need to use the TEXT or _T macros here (can't remember
which does what as I don't use them I'm afraid).
ss << ... << _T( "\r\n" );
>
while (::FindNextFile( hReturn, &stData))
{
ss << stData.cFileName << "\r\n";
}
FindClose(hReturn);
std::string strResponse = ss.str();
stData.cFileName is a char buffer.
This will need to change between char and wchar_t depending on how
you're compiling it.
This is all very fidlly. Why are you even bothering with narrow
character support? On Windows it seems pointless these days. If you're
going to the bother of supporting Unicode compilation then just use
that throughout and forget about narrow character support.
You can still use narrow characters where you need to interact with
legacy systems and to handle formats that are specified as 7/8 bit
characters.
K