From: Chris Little (cslittle_at_[hidden])
Date: 2002-02-23 11:46:31
on 2/23/02 10:31 AM, Beman Dawes at bdawes_at_[hidden] wrote:
> I'm working on more file system functionality (to be packaged with
> Dietmar's directory iterators).
> At 07:48 AM 1/30/2002, Ken Hagan wrote:
>> ... at least in the Windows world, a mounted filesystem will either
>> store names on the disc in "the current code page" (MS-DOS and early
>> Windows) or as "Unicode" (FAT32 and NTFS). For this reason, semi-
>> serious manipulation of files and file systems on NT/2K/XP is done
>> with wchar_t rather than char. The latter is simply blind to a range
>> of names that might exist. (There's another reason too, since the
>> char-based APIs can't handle paths longer than 260 characters, and
>> this limit can be exceeded by UNC-style names.)
> How does this work? The Win32 API traffics mostly in character strings.
> For example, say we have a function template:
> template< typename CharT >
> bool exists( const std::basic_string<CharT> & path );
> The Win32 char implementation might look like this:
> template<> // specialization for char
> bool exists<char>( const std::basic_string<char> & path )
> return GetFileAttributes( path.c_str() ) != 0xFFFFFFFF;
> What does the wchar_t implementation look like? There isn't a
> GetFileAttributes overloaded for wchar_t; GetFileAttributes itself is
> apparently Unicode enabled. I guess that means the wstring path argument
> has to be converted somehow before calling GetFileAttributes().
> I'd appreciate seeing the preferred code from someone who has actual
> experience with Unicode path names.
I haven't done much work with this but I can give you the background.
The file apis provide a unicode and non-unicode version. The function name
is suffixed with W for unicode and A for non-unicode. The unsuffixed name
is just a define that is set to either the W or A function depending on
whether UNICODE is defined.
I.e. GetFileAttributes is either GetFileAttributesW or GetFileAttributesA.
The A version takes an LPCSTR (const char*) and the W version takes an
LPCWSTR (const wchar_t *)
You can specifically call either version. On Windows 95/98/Me you need to
add Microsoft's unicode layer to your project to access the W version of the
As Ken mentioned, the A versions are limited by MAX_PATH but the W versions
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk