|
Boost : |
From: Alan Bellingham (alan_at_[hidden])
Date: 2002-02-23 11:51:17
Beman Dawes <bdawes_at_[hidden]>:
>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().
Actually, there is, sort of:
<winbase.h>
WINBASEAPI DWORD WINAPI GetFileAttributesA(IN LPCSTR lpFileName);
WINBASEAPI DWORD WINAPI GetFileAttributesW(IN LPCWSTR lpFileName);
#ifdef UNICODE
# define GetFileAttributes GetFileAttributesW
#else
# define GetFileAttributes GetFileAttributesA
#endif // !UNICODE
So to use narrow or wide strings explicitly, you use the A/W variants,
or to use them implicitly you do what I do, which is to apply a C++
solution:
#undef GetFileAttributes
inline DWORD GetFileAttributes(char const* FileName)
{
return GetFileAttributesA(FileName) ;
}
inline DWORD GetFileAttributes(wchar_t const* FileName)
{
return GetFileAttributesW(FileName) ;
}
I dislike header files introducing macros for mixed or lower case
identifiers, because of the preprocessor's disregard for scope, so I
actually have a 40,000 line header file that undefines all such macros
introduced by the Win32 API headers and a shorter file that applies
inline overloads as above, on a case by case basis.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk