Here is an example for string to wstring transform.
HRESULT DSU_StrToWcs( string strSrc, wstring* wstrDst, UINT nCodepage = CP_UTF8) ;
HRESULT DSU_StrToWcs(string strSrc, wstring* wstrDst, UINT nCodepage)
{
if ( wstrDst == NULL )
return E_POINTER;
int iStrLen = strSrc.length() ;
int nCount = MultiByteToWideChar(nCodepage, 0, strSrc.c_str(), iStrLen, NULL, 0) ;
WCHAR* pWCHAR = (WCHAR*)alloca(sizeof(WCHAR) * (nCount + 1)) ;
nCount = MultiByteToWideChar(nCodepage, 0, strSrc.c_str(), iStrLen, pWCHAR, nCount+1) ;
pWCHAR[nCount] = NULL ;
*wstrDst = pWCHAR ;
return S_OK ;
}
沒有留言:
張貼留言