一部のUnicode文字(など)のコードポイントは、2バイト以上を消費します。CreateFile()
これらの文字のようにWin32API関数を使用するにはどうすればよいですか?
WinBase.h
WINBASEAPI
__out
HANDLE
WINAPI
CreateFileA(
__in LPCSTR lpFileName,
__in DWORD dwDesiredAccess,
__in DWORD dwShareMode,
__in_opt LPSECURITY_ATTRIBUTES lpSecurityAttributes,
__in DWORD dwCreationDisposition,
__in DWORD dwFlagsAndAttributes,
__in_opt HANDLE hTemplateFile
);
WINBASEAPI
__out
HANDLE
WINAPI
CreateFileW(
__in LPCWSTR lpFileName,
__in DWORD dwDesiredAccess,
__in DWORD dwShareMode,
__in_opt LPSECURITY_ATTRIBUTES lpSecurityAttributes,
__in DWORD dwCreationDisposition,
__in DWORD dwFlagsAndAttributes,
__in_opt HANDLE hTemplateFile
);
#ifdef UNICODE
#define CreateFile CreateFileW
#else
#define CreateFile CreateFileA
#endif // !UNICODE
LPCSTRとLPCWSTRは、WinNT.hで次のように定義されています。
typedef __nullterminated CONST CHAR *LPCSTR, *PCSTR;
typedef __nullterminated CONST WCHAR *LPCWSTR, *PCWSTR;
CHAR
WinNT.hでは次のようにWCHAR
定義されています。
typedef char CHAR;
#ifndef _MAC
typedef wchar_t WCHAR; // wc, 16-bit UNICODE character
#else
// some Macintosh compilers don't define wchar_t in a convenient location, or define it as a char
typedef unsigned short WCHAR; // wc, 16-bit UNICODE character
#endif
CreateFileA()
LPCSTR
内部で8ビットchar
配列に格納されているファイル名を受け入れます。内部で16ビット配列に格納されているファイル名
CreateFileW()
を受け入れます。LPCWSTR
wchar_t
C:\。txtの位置にファイルを作成しました。を使用してこのファイルを開くことはできないようですCreateFile()
。これは、Unicodeコードポイントが0x24B62であり、WCHAR配列セルにも収まらない文字が含まれているためです。
しかし、そのファイルは私のハードディスクに存在し、Windowsはそれを正常に管理します。Windowsが内部で行うように、Win32 API関数でこのファイルを開くにはどうすればよいですか?