#define _countof(array) (sizeof(array) / sizeof(array[0]))
void __fastcall TForm1::btn1Click(TObject *Sender)
{
    wchar_t  buf[] = L"中国人民解放军";
    WideString ws = "中国人民解放军";
    WCHAR* buf2 = ws.c_bstr();
    int a = _countof(buf);
    int b = sizeof(buf);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::btn2Click(TObject *Sender)
{
    char* buffer = "中国人民解放军";
    int cbMultiByte = strlen(buffer) + 1;
    wchar_t wbuffer[20] = {0};
    int cchWideChar = cbMultiByte;
    MultiByteToWideChar(
        CP_ACP,
        MB_PRECOMPOSED,
        buffer,
        strlen(buffer) + 1,
        wbuffer,
        strlen(buffer) + 1
    );

    ShowMessage(wbuffer);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::btn3Click(TObject *Sender)
{
    wchar_t* wbuffer = L"中国人民志愿军";
    int cchWideChar = wcslen(wbuffer) + 1;
    char buffer[20] = {0};
    int cbMultiByte = cchWideChar * sizeof(wchar_t) + 1;

    WideCharToMultiByte(CP_ACP,
        0,
        wbuffer,
        cchWideChar,
        buffer,
        cbMultiByte,
        NULL,
        NULL);


    DWORD err = GetLastError();
    AnsiString errMsg = SysErrorMessage(err);

    ShowMessage(buffer);

}
//---------------------------------------------------------------------------
void __fastcall TForm1::btn4Click(TObject *Sender)
{
    wchar_t* wbuffer = L"中国人民解放军第301医院";
    PVOID pvBuffer = wbuffer;
    int cb = (wcslen(wbuffer) + 1) * sizeof(wchar_t);
    BOOL bRet = IsTextUnicode(pvBuffer , cb , NULL);

    char* buffer = "中国人民解放军第309医院";
    pvBuffer = buffer;
    cb = (strlen(buffer) + 1) * sizeof(char);
    bRet = IsTextUnicode(pvBuffer , cb , NULL);
}

 

posted on 2021-07-26 22:02  zooz  阅读(287)  评论(0编辑  收藏  举报