C++类型转换 LPWSTR转char*

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

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;

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。