1. Preparation
- 头文件:
#include <atlconv.h>
- 使用前应添加宏:
USES_CONVERSION;
2. Examples
- W2A
USES_CONVERSION;
wchar_t wszSendBuffer[1024] = L"北京2008";
char *pszSendBuffer = W2A(wszSendBuffer);
printf("buffer:%s; len:%d", pszSendBuffer, lstrlen(pszSendBuffer));
- A2W
USES_CONVERSION;
char szRecvBuffer[1024] = "北京2008";
wchar_t *pwszRecvBuffer = A2W(szRecvBuffer);
setlocale(LC_ALL, "chs");
wprintf(L"buffer:%s; len:%d", pwszRecvBuffer, wcslen(pwszRecvBuffer));