You have three valid options. All others are invalid. The third of these options is the best.
Option 1: Force ANSI (slower on NT, doesn't work on CE, possible problems with internationalization)
Code:
? 1 2hFile = CreateFileA(
"C:\\tab.doc"
,GENERIC_READ|GENERIC_WRITE,
?
FILE_SHARE_READ,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
Option 2: Force Unicode (doesn't work on 9x)
Code:
? 1 2hFile = CreateFileW(L
"C:\\tab.doc"
,GENERIC_READ|GENERIC_WRITE,
?
FILE_SHARE_READ,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
Option 3: Make it easily switchable in the project settings (easy to get working and ideal versions for everywhere)
Code:
? 1 2hFile = CreateFile(TEXT(
"C:\\tab.doc"
),GENERIC_READ|GENERIC_WRITE,
?
FILE_SHARE_READ,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
If you include <tchar.h>, you can use _TEXT() or _T() instead of TEXT(), but that is the only permitted variation. Everything else is invalid.
?
LPSTR 一个32位的指向字符串的指针
LPCSTR 一个32位的指向字符串常量的指针
LPWSTR 一个32位的指向unicode字符串的指针
LPCWSTR 一个32位的指向unicode字符串常量的指针
前面的L代表LONG,P就是指针的意思,C就是constant的意思
W是wide的意思,STR就是string的意思
LPSTR = char *
LPCSTR = const char *
LPWSTR = wchar_t *
LPCWSTR = const wchar_t *
LPOLESTR = OLECHAR * = BSTR = LPWSTR(Win32)
LPCOLESTR = const OLECHAR * = LPCWSTR(Win32)
LPTSTR = _TCHAR *
LPCTSTR = const _TCHAR *
多字节字符串与宽字符串的转换可使用C API者Win32 API.
C API: mbstowcs,wcstombs
Win32 API: MultiByteToWideChar, WideCharToMultiByte