Windows Programming 第二章

来源:百度知道 编辑:UC知道 时间:2024/09/21 08:12:18
Unicode……什么东西??咋就看不明白呢??貌似有点头疼,什么wchar_t,什么TCHAR,什么WCHAR??啥东西???是我理解能力差,还是书翻译的垃圾???

为了同时处理中文字符和英文字符,我们常常需要使用Unicode编码。通过利用#define技术,it is possible to write a single source code so that it can be compiled with or without using Unicode -- you need only define two macros (UNICODE and _UNICODE) to make the change and then recompile. 通过研究Windows是如何完成这个任务的,我们也可以在今后利用同样的技术。

下面是对Unicode和ANSI字符串处理相关的总结:
类型: char wchar_t
部分处理函数:
char * strcat(char *, const char *);
wchar_t * wcscat(wchar_t *, const wchar_t *);
char * strchr(const char *, int);
wchar_t * wcschr(const wchar_t *, wchar_t);
int strcmp(const char *, const char *);
int wcscmp(const wchar_t *, const wchar_t *);
char * strcpy(char *, const char *);
wchar_t * wcscpy(wchar_t *, const wchar_t *);
size_t strlen(const char *);
size_t wcslen(const wchar_t *);

无论是类型还是函数,我们需要这样一种符号:当我们定义了_UNICODE时,这个符号就转换为Unicode版本的类型或是函数;但当我们没有定义_UNICODE是,该符号就对应于single-bytes版本。利用define和typedef我们可以完成这样的任务。

对于类型来说,我们可以这样定义:
#ifdef