美文网首页C++
C++类型转换 LPWSTR转char*

C++类型转换 LPWSTR转char*

作者: 刘千予 | 来源:发表于2018-06-30 17:48 被阅读0次

/******************************************************************************************

Function:        ConvertLPWSTRToLPSTR

Description:    LPWSTR转char*

Input:          lpwszStrIn:待转化的LPWSTR类型

Return:          转化后的char*类型

*******************************************************************************************/

char* ConvertLPWSTRToLPSTR(LPWSTR lpwszStrIn)

{

LPSTR pszOut = NULL;

try

{

if (lpwszStrIn != NULL)

{

int nInputStrLen = wcslen(lpwszStrIn);

// Double NULL Termination 

int nOutputStrLen = WideCharToMultiByte(CP_ACP, 0, lpwszStrIn, nInputStrLen, NULL, 0, 0, 0) + 2;

pszOut = new char[nOutputStrLen];

if (pszOut)

{

memset(pszOut, 0x00, nOutputStrLen);

WideCharToMultiByte(CP_ACP, 0, lpwszStrIn, nInputStrLen, pszOut, nOutputStrLen, 0, 0);

}

}

}

catch (std::exception e)

{

}

return pszOut;

}

相关文章

网友评论

    本文标题:C++类型转换 LPWSTR转char*

    本文链接:https://www.haomeiwen.com/subject/jsxxuftx.html