是从书上看来的示例代码,但是在我这就是无法运行一到WideCharToMultiByte那句就出错!不知是那里写错了?代码大致如下:
BOOL StringReverseA(PSTR pMultiByteStr)
{
PWSTR pWideCharStr;
int nLenOfWideCharStr;
BOOL fOK = FALSE; //Calculate the number of characters needed to hold 
//the wide-character version of the string.
nLenOfWideCharStr = MultiByteToWideChar(CP_ACP,0,pMultiByteStr,-1,NULL,0); //Allocate memory from the process's default heap to
//accommodate the size of the wide-character string.
//Don't forget that MultiBytetToWideChar returns the
//number of characters,not the number of bytes,so you
//must multiply by the size of a wide character.
pWideCharStr = (PWSTR)HeapAlloc(GetProcessHeap(),0,nLenOfWideCharStr * sizeof(WCHAR)); if(pWideCharStr == NULL)
return(fOK); //Convert the multibyte string to a wide-character string.
MultiByteToWideChar(CP_ACP,0,pMultiByteStr,-1,pWideCharStr,nLenOfWideCharStr); //Call the wide-character version of this
//function to do the actual work.
fOK = StringReverseW(pWideCharStr); if(fOK)
{
//Convert the wide-character string back to a multibyte string.
WideCharToMultiByte(CP_ACP,0,pWideCharStr,-1,pMultiByteStr,strlen(pMultiByteStr),NULL,NULL);
} //Free the memory containing the wide-character string.
HeapFree(GetProcessHeap(),0,pWideCharStr); return(fOK);
}

解决方案 »

  1.   

    那里搞得代码,没有StringReverseW这个函数呀,我编译不过去。
      

  2.   

    int iWideCharCnt = ::MultiByteToWideChar(nCodePage, 0, (const char*)pBuff, iBuffLen, NULL, 0);
    LPWSTR lpszWideChar = new wchar_t[iWideCharCnt + 1];
    memset(lpszWideChar, 0, (iWideCharCnt + 1) * sizeof(WCHAR));
    iWideCharCnt = MultiByteToWideChar(nCodePage, 0, (const char*)pBuff, iBuffLen, lpszWideChar, iWideCharCnt); int iDestCnt = WideCharToMultiByte(nDestCodePage, 0, lpszWideChar, iWideCharCnt, NULL, 0, NULL, NULL);
    lpCodePage = new BYTE[iDestCnt + 1];
    memset(lpCodePage, 0, iDestCnt + 1);
    iDestCnt = WideCharToMultiByte(nDestCodePage, 0, lpszWideChar, iWideCharCnt, (char*)lpCodePage, iDestCnt, NULL, NULL);nCodePage 是原串的编码页
    nDestCodePage是目标串的编码页
      

  3.   

    topwork(日光) 
      StringReverseW只是自己写的一个小函数,只是将字符串的次序到过来。可以去掉!