如何将PCWSTR转换为char * [英] How to convert PCWSTR to char *

查看:408
本文介绍了如何将PCWSTR转换为char *的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

喜。我想将类型PCWSTR转换为char * .tnx





hi. i want to convert type PCWSTR to char *.tnx


HWND hwnd;
CComHeapPtr spszLocation;
if (FAILED(GetBrowserInfo(svar.pdispVal, &hwnd,&spszLocation))) continue;
LPCWSTR tmp=static_cast(spszLocation);
size_t wcsChars = wcslen( tmp);
MD5 md5MdFive;
unsigned char ucMdfiveExit[16];
md5MdFive.ConvertMD5(spszLocation,(unsigned long)iDataSize,ucMdfiveExit);
std::wcout << hwnd<< L" "<< static_cast<PCWSTR>(spszLocation)<< std::endl;







<在convertmd5的第一个参数上面的代码中的
是const unsigned char *但是我有LPCWSTR





in the code above the first parameter of the convertmd5 is const unsigned char * but i have LPCWSTR

推荐答案

看看这个 -

how-do-you-convert-lpcwstr-to-const-char [ ^ ]
Have a look at this-
how-do-you-convert-lpcwstr-to-const-char[^]


这样的东西



Something like this

wstring wstr( L"abcdef" );
int len = WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), wstr.size(), NULL, 0, NULL, NULL);
char* buffer = new char[len + 1];
WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), wstr.size(), buffer, len, NULL, NULL);
buffer[len] = '\0';





或特定于您的情况:





or to be specific to your case:

PCWSTR pstr(L"abcdef");
int len = WideCharToMultiByte(CP_ACP, 0, pstr, wcslen(pstr), NULL, 0, NULL, NULL);
char* buffer = new char[len + 1];
WideCharToMultiByte(CP_ACP, 0, pstr, wcslen(pstr), buffer, len, NULL, NULL);
buffer[len] = '\0';


请参阅有关 wcstombs 功能。


这篇关于如何将PCWSTR转换为char *的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆