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;

IntoVPS:按小时计费KVM月费5美元起($0.0075/小时),6个机房可选

IntoVPS是成立于2004年的Hosterion SRL旗下于2009年推出的无管理型VPS主机品牌,商家提供基于OpenStack构建的VPS产品,支持小时计费是他的一大特色,VPS可选数据中心包括美国弗里蒙特、达拉斯、英国伦敦、荷兰和罗马尼亚等6个地区机房。商家VPS主机基于KVM架构,最低每小时0.0075美元起($5/月)。下面列出几款VPS主机配置信息。CPU:1core内存:2GB...

LayerStack$10.04/月(可选中国香港、日本、新加坡和洛杉矶)高性能AMD EPYC (霄龙)云服务器,

LayerStack(成立于2017年),当前正在9折促销旗下的云服务器,LayerStack的云服务器采用第 3 代 AMD EPYC™ (霄龙) 处理器,DDR4内存和企业级 PCIe Gen 4 NVMe SSD。数据中心可选中国香港、日本、新加坡和洛杉矶!其中中国香港、日本和新加坡分为国际线路和CN2线路,如果选择CN2线路,价格每月要+3.2美元,付款支持paypal,支付宝,信用卡等!...

hostodo:美国大流量VPS,低至$3,8T流量/月-1.5G内存/1核/25gNVMe/拉斯维加斯+迈阿密

hostodo从2014年年底运作至今一直都是走低价促销侧率运作VPS,在市场上一直都是那种不温不火的品牌知名度,好在坚持了7年都还运作得好好的,站长觉得hostodo还是值得大家在买VPS的时候作为一个候选考虑项的。当前,hostodo有拉斯维加斯和迈阿密两个数据中心的VPS在促销,专门列出了2款VPS给8T流量/月,基于KVM虚拟+NVMe整列,年付送DirectAdmin授权(发ticket...

widechartomultibyte为你推荐
云图片华为手机的云照片怎么不见了怎么办备忘录模式为什么我的华为手机界面总是有个框框在备忘录上面editplus破解版cool edit pro 2.1汉化破解版弹幕播放器看过的剧有一个弹幕出来的是什么播放器中文搜索引擎百度是不是全球最大中文搜索引擎?数据分析报告范文数据分析报告怎么写新手怎么制作表格我是初学者、电脑上怎么制作表格alphablenddelphi中都有哪些控件有AlphaBlend属性,也就是可透明sungard李庆星老板咋样 我准备去CDMC上海决策者经济顾问公司上班了酷源码怎样看源码下优酷视频
域名是什么 域名管理 电信服务器租赁 域名备案收费吗 什么是域名解析 购买域名和空间 buyvm photonvps 美国翻墙 外贸主机 美国主机网 sugarsync iis安装教程 2017年黑色星期五 patcha 网通服务器ip mysql主机 日本空间 服务器架设 京东商城0元抢购 更多