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;

半月湾($59.99/年),升级带宽至200M起步 三网CN2 GIA线路

在前面的文章中就有介绍到半月湾Half Moon Bay Cloud服务商有提供洛杉矶DC5数据中心云服务器,这个堪比我们可能熟悉的某服务商,如果我们有用过的话会发现这个服务商的价格比较贵,而且一直缺货。这里,于是半月湾服务商看到机会来了,于是有新增同机房的CN2 GIA优化线路。在之前的文章中介绍到Half Moon Bay Cloud DC5机房且进行过测评。这次的变化是从原来基础的年付49....

个人网站备案流程及注意事项(内容方向和适用主机商)

如今我们还有在做个人网站吗?随着自媒体和短视频的发展和兴起,包括我们很多WEB2.0产品的延续,当然也包括个人建站市场的低迷和用户关注的不同,有些个人已经不在做网站。但是,由于我们有些朋友出于网站的爱好或者说是有些项目还是基于PC端网站的,还是有网友抱有信心的,比如我们看到有一些老牌个人网站依旧在运行,且还有新网站的出现。今天在这篇文章中谈谈有网友问关于个人网站备案的问题。这个也是前几天有他在选择...

A400:36元/季,16.8/月kvm架构,线路优质,延迟低

A400互联是一家成立于2020年的商家,主要推行洛杉矶服务器采用kvm架构,线路优质,延迟低,稳定性高!全场产品对标腾讯云轻量,服务器线路有有美国洛杉矶cn2_gia、香港cn2+cmi,目前推行的vps服务器均为精心挑选的优质线路机房,A400互联推出了夏季优惠洛杉矶5折、香港7折促销活动,质量可靠,价格实惠!二:优惠码洛杉矶五折优惠码:20210620香港cn2七折优惠码:0710三、优惠方...

widechartomultibyte为你推荐
元数据管理请元数据管理包括哪些内容?httpsessionhttpsession中的SessionID是如何生成的?微信收款语音播报怎么设置微信收款码声音怎么设置fclose为什么fclose之后remove还是不成功qq号查询怎样查找本地qq号码editplus破解版手机的常用软件和ngage的破解版inode智能客户端inode智能客户端无法正常启动,根本开都开不了问卷星登陆请问问卷星怎么设置答题时间?jsindexofjavascript 中indexof 的用法pci数据捕获和信号处理控制器三星450r5v x05 设备管理器出现pci数据捕获和信号处理控制器有个黄色的感叹号怎么办
kvmla 韩国电信 天猫双十一秒杀 好看的桌面背景大图 北京主机 帽子云 789电视网 adroit 如何用qq邮箱发邮件 太原网通测速平台 联通网站 阿里云邮箱登陆 免备案jsp空间 重庆联通服务器托管 移动王卡 香港ip godaddy退款 asp介绍 服务器机柜 卡巴斯基免费版下载 更多