char *转LPWSTR ,c和c++实现

char *转LPWSTR ,c和c++实现,第1张

 需要包含头文件include !

// c++函数

LPWSTR ConvertCharToLPWSTR(const char* szString)

{

int dwLen = strlen(szString) + 1;

int nwLen = MultiByteToWideChar(CP_ACP, 0, szString, dwLen, NULL, 0);//算出合适的长度

LPWSTR lpszPath = new WCHAR[dwLen];

MultiByteToWideChar(CP_ACP, 0, szString, dwLen, lpszPath, nwLen);

return lpszPath;

}

// c函数

LPWSTR ConvertCharToLPWSTR(const char* szString)

{

int dwLen = strlen(szString) + 1;

int nwLen = MultiByteToWideChar(CP_ACP, 0, szString, dwLen, NULL, 0);//算出合适的长度

LPWSTR lpszPath = (LPWSTR)malloc(sizeof(WCHAR) * dwLen);

MultiByteToWideChar(CP_ACP, 0, szString, dwLen, lpszPath, nwLen);

return lpszPath;

}

使用实例

 char str[20] = {0};

 LPWSTR Wstr = ConvertCharToLPWSTR(str);

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/579348.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-11
下一篇 2022-04-11

发表评论

登录后才能评论

评论列表(0条)

保存