VS中字符集处理_C/C++_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > C/C++ > VS中字符集处理

VS中字符集处理

 2012/1/19 9:11:49  soartomato  程序员俱乐部  我要评论(0)
  • 摘要:Youhavethreevalidoptions.Allothersareinvalid.Thethirdoftheseoptionsisthebest.Option1:ForceANSI(sloweronNT,doesn'tworkonCE,possibleproblemswithinternationalization)Code:?12hFile=CreateFileA("C:\\tab.doc",GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ
  • 标签:

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 2 hFile = 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 2 hFile = 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 2 hFile = 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

  • 相关文章
发表评论
用户名: 匿名