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;

Virmach$7.2/年,新款月抛vps上线,$3.23/半年,/1核640M内存/10 GB存储/ 1Gbps/1T流量

Virmach自上次推出了短租30天的VPS后,也就是月抛型vps,到期不能续费,直接终止服务。此次又推出为期6个月的月抛VPS,可选圣何塞和水牛城机房,适合短期有需求的用户,有兴趣的可以关注一下。VirMach是一家创办于2014年的美国商家,支持支付宝、PayPal等方式,是一家主营廉价便宜VPS服务器的品牌,隶属于Virtual Machine Solutions LLC旗下!在廉价便宜美国...

DMIT(季度$28.88)调整洛杉矶CN2 GIA优化端口

对于DMIT商家已经关注有一些时候,看到不少的隔壁朋友们都有分享到,但是这篇还是我第一次分享这个服务商。根据看介绍,DMIT是一家成立于2017年的美国商家,据说是由几位留美学生创立的,数据中心位于香港、伯力G-Core和洛杉矶,主打香港CN2直连云服务器、美国CN2直连云服务器产品。最近看到DMIT商家有对洛杉矶CN2 GIA VPS端口进行了升级,不过价格没有变化,依然是季付28.88美元起。...

台湾云服务器整理推荐UCloud/易探云!

台湾云服务器去哪里买?国内有没有哪里的台湾云服务器这块做的比较好的?有很多用户想用台湾云服务器,那么判断哪家台湾云服务器好,不是按照最便宜或最贵的选择,而是根据您的实际使用目的选择服务器,只有最适合您的才是最好的。总体而言,台湾云服务器的稳定性确实要好于大陆。今天,云服务器网(yuntue.com)小编来介绍一下台湾云服务器哪里买和一年需要多少钱!一、UCloud台湾云服务器UCloud上市云商,...

widechartomultibyte为你推荐
flash控件flash插件怎么弄akfWOW的意思是什么?AKF呢?rdlcordless phone是什么意思webcrack我用WebCrack4 在破解路由器密码的时候为什么在破解密码的中途自动关闭掉电子日历墙上挂的电子日历不显示怎么维修李昊天李昊天这名字给多少分tvosairpods什么意思 airpods连接方式是怎样的arc是什么意思arctanx等于什么?editplus破解版手机的常用软件和ngage的破解版vipjrvipjr怎么样?有真实体验的来说一下
域名信息查询 godaddy域名注册 免费动态域名解析 申请免费域名 怎样申请域名 flashfxp怎么用 美国主机网 国外空间 英文站群 酷番云 台湾google www789 河南移动梦网 帽子云排名 中国linux 日本代理ip 万网注册 服务器防御 双11促销 脚本大全 更多