widechartomultibyte一个API函数怎么用

widechartomultibyte  时间:2021-07-16  阅读:()

sqlite乱码

一种方式是:设置数据编码为 GB2312 ..(在SQLite数据库管理器那边可以改)..[推荐]

然后不然就是在代码里面重新转换数据..这种方式比较麻烦,也耗资源...

思路是先将从sqlite数据库读取出的nvarchar 转换成byte[] 数组..然后 调用 System.Text.Encoding.Unicode.GetString(byte[] 数组); 它返回的应该是 无乱码的数据了.

只是一时想到的两种方式.. 可能还有好的解决办法吧...

pb 调用怎么调用MultiByteToWideChar函数

为了支持Unicode编码,需要多字节与宽字节之间的相互转换。

这两个系统函数在使用时需要指定代码页,在实际应用过程中遇到乱码问题,然后重新阅读《Windows核心编程》,总结出正确的用法。

WideCharToMultiByte的代码页用来标记与新转换的字符串相关的代码页。

MultiByteToWideChar的代码页用来标记与一个多字节字符串相关的代码页。

常用的代码页由CP_ACP和CP_UTF8两个。

使用CP_ACP代码页就实现了ANSI与Unicode之间的转换。

使用CP_UTF8代码页就实现了UTF-8与Unicode之间的转换。

下面是代码实现: 1. ANSI to Unicode wstring ANSIToUnicode( const string& str ) { int len = 0; len = str.length(); int unicodeLen = ::MultiByteToWideChar( CP_ACP, 0, str.c_str(), -1, NULL, 0 ); wchar_t * pUnicode; pUnicode = new wchar_t[unicodeLen+1]; memset(pUnicode,0,(unicodeLen+1)*sizeof(wchar_t)); ::MultiByteToWideChar( CP_ACP, 0, str.c_str(), -1, (LPWSTR)pUnicode, unicodeLen ); wstring rt; rt = ( wchar_t* )pUnicode; delete pUnicode; return rt; } 2. Unicode to ANSI string UnicodeToANSI( const wstring& str ) { char* pElementText; int iTextLen; // wide char to multi char iTextLen = WideCharToMultiByte( CP_ACP, 0, str.c_str(), -1, NULL, 0, NULL, NULL ); pElementText = new char[iTextLen + 1]; memset( ( void* )pElementText, 0, sizeof( char ) * ( iTextLen + 1 ) ); ::WideCharToMultiByte( CP_ACP, 0, str.c_str(), -1, pElementText, iTextLen, NULL, NULL ); string strText; strText = pElementText; delete[] pElementText; return strText; } 3. UTF-8 to Unicode wstring UTF8ToUnicode( const string& str ) { int len = 0; len = str.length(); int unicodeLen = ::MultiByteToWideChar( CP_UTF8, 0, str.c_str(), -1, NULL, 0 ); wchar_t * pUnicode; pUnicode = new wchar_t[unicodeLen+1]; memset(pUnicode,0,(unicodeLen+1)*sizeof(wchar_t)); ::MultiByteToWideChar( CP_UTF8, 0, str.c_str(), -1, (LPWSTR)pUnicode, unicodeLen ); wstring rt; rt = ( wchar_t* )pUnicode; delete pUnicode; return rt; } 4. Unicode to UTF-8 string UnicodeToUTF8( const wstring& str ) { char* pElementText; int iTextLen; // wide char to multi char iTextLen = WideCharToMultiByte( CP_UTF8, 0, str.c_str(), -1, NULL, 0, NULL, NULL ); pElementText = new char[iTextLen + 1]; memset( ( void* )pElementText, 0, sizeof( char ) * ( iTextLen + 1 ) ); ::WideCharToMultiByte( CP_UTF8, 0, str.c_str(), -1, pElementText, iTextLen, NULL, NULL ); string strText; strText = pElementText; delete[] pElementText; return strText; }

如何将unsigned short 转换成unsigned char

unsigned short 转换为 unsigned char可以这样转: unsigned short * word; int size= WideCharToMultiByte(CP_ACP,0,word,-1, NULL, 0, NULL,0); char * AsciiBuff =new char[size]; WideCharToMultiByte(CP_ACP,0,word,-1,AsciiBuff,size, NULL, 0);

error C2664: "WideCharToMultiByte": 不能将参数 3 从"CString"转换为"LPCWSTR",参数3是m_edit

m_edit是你添加的Edit控件的变量吧 你是要把这个Edit控件里面的内容传进这个参数么 如果是的话, CString cstrEditString; m_edit.GetWindowText(cstrEditString); 然后把 WideCharToMultiByte的第三个参数改为cstrEditString

一个API函数怎么用

WideCharToMultiByte   函数功能:该函数映射一个unicode字符串到一个多字节字符串。

  函数原型:   int WideCharToMultiByte(   UINT CodePage, //指定执行转换的代码页   DWORD dwFlags,   LPCWSTR lpWideCharStr, //指定的宽字节字符串的缓冲区   hWideChar, //指定由参数lpWideCharStr指向的缓冲区的字符个数   LPSTR lpMultiByteStr, //指向接收被转换字符串的缓冲区   hMultiByte, //指定由参数lpMultiByteStr指向的缓冲区最大值   LPCSTR lpDefaultChar,   LPBOOL pfUsedDefaultChar   ); 范例: wchar_t wText[20] = {L"宽字符转换实例!OK!"}; DWORD dwNum = WideCharToMultiByte(CP_OEMCP,NULL,lpcwszStr,-1,NULL,0,NULL,FALSE); char *psText; psText = new char[dwNum]; if(!psText) { delete []psText; } WideCharToMultiByte (CP_OEMCP,NULL,lpcwszStr,-1,psText,dwNum,NULL,FALSE); delete []psText;

香港九龙湾(27元) 2核2G 20元 香港沙田

弘速云是创建于2021年的品牌,运营该品牌的公司HOSU LIMITED(中文名称弘速科技有限公司)公司成立于2021年国内公司注册于2019年。HOSU LIMITED主要从事出售香港VPS、美国VPS、香港独立服务器、香港站群服务器等,目前在售VPS线路有CN2+BGP、CN2 GIA,该公司旗下产品均采用KVM虚拟化架构。可联系商家代安装iso系统。国庆活动 优惠码:hosu10-1产品介绍...

Bluehost美国虚拟主机2.95美元/月,十八周年庆年付赠送顶级域名和SSL证书

Bluehost怎么样,Bluehost好不好,Bluehost成立十八周年全场虚拟主机优惠促销活动开始,购买12个月赠送主流域名和SSL证书,Bluehost是老牌虚拟主机商家了,有需要虚拟主机的朋友赶紧入手吧,活动时间:美国MST时间7月6日中午12:00到8月13日晚上11:59。Bluehost成立于2003年,主营WordPress托管、虚拟主机、VPS主机、专用服务器业务。Blueho...

raksmart:年中大促,美国物理机$30/月甩卖;爆款VPS仅月付$1.99;洛杉矶/日本/中国香港多IP站群$177/月

RAKsmart怎么样?RAKsmart发布了2021年中促销,促销时间,7月1日~7月31日!,具体促销优惠整理如下:1)美国西海岸的圣何塞、洛杉矶独立物理服务器低至$30/月(续费不涨价)!2)中国香港大带宽物理机,新品热卖!!!,$269.23 美元/月,3)站群服务器、香港站群、日本站群、美国站群,低至177美元/月,4)美国圣何塞,洛杉矶10G口服务器,不限流量,惊爆价:$999.00,...

widechartomultibyte为你推荐
flash控件flash插件怎么弄akf德州水份检测仪价格,AKF系列卡尔费休水份测定仪和世界顶级进口品牌相比怎么样?开票系统网上申请的发票怎么读入开票系统qq号查询怎样查找本地qq号码郭凡生慧聪的董事长是谁?跟马云比,怎么样?tvosTVOS系统是什么?备忘录模式华为荣耀5X怎么在手机上新建一个备忘录inode智能客户端inode智能客户端怎么使用wifi?网页微信客户端什么叫微信网页版?和电脑版是一回事吗?清除电脑垃圾怎样清除电脑里的垃圾
联通vps 主机测评 net主机 lamp安装 xfce 网站被封 华为4核 e蜗牛 cpanel空间 天互数据 新家坡 香港亚马逊 创建邮箱 腾讯总部在哪 四川电信商城 vul 东莞服务器托管 国外的代理服务器 摩尔庄园注册 江苏徐州移动 更多