W2A & A2W

1. Preparation

  • 头文件:
#include 
  • 使用前应添加宏:
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运行结果
  • 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));
W2A运行结果

你可能感兴趣的:(W2A & A2W)