Unicode和多字节 Unicode是宽字符 多字节是窄字符
类型 | 变量类型 | 初始化方式 |
Unicode | LPWSTR | L"string" |
多字节 | LPSTR | "string" |
根据开发环境的设置自动适应 | LPTSTR | TEXT("string") |
代码演示
#include <windows.h> int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { //定义LPWSTR 类型的宽字符串 LPWSTR szUnicode = L"This is a Unicode String;嘿嘿"; //定义LPSTR 类型的窄字符串 LPSTR szMutliByte = "This is not a Unicode String;哈哈"; //定义LPTSTR 类型的自适用字符串 LPTSTR szString = TEXT("This string is Unicode or not depends on the option.呵呵"); //使用W版本的API函数,以宽字符串为参数 MessageBoxW(NULL, szUnicode, L"<字符编码1>", MB_OK); //使用A版本的API函数,以窄字符串为参数 MessageBoxA(NULL, szMutliByte, "<字符编码2>", MB_OK); //根据编译条件自动选择A版本火W版本的API函数,采用相适应的字符串类型为参数 MessageBox(NULL, szString, TEXT("<字符编码3>"), MB_OK); return 0; }