wchar_t*和char*之间的互相转换的那些事
- 最近在看一写PE文件格式的东西,想做一个读取PE文件信息的小工具,中间遇到将LPVOID格式无法转换到LPTSTR格式,强制转换屡试屡败,多显示乱码。我们知道LPVOID格式可以直接转换到char *,最后发现一篇写char*与wchar_t*格式互相转换的文章,引用文中代码转换成功。
- 原帖地址http://www.cnblogs.com/yyxr/archive/2009/10/06/1578458.html
- //将单字节char*转化为宽字节wchar_t*
- wchar_t* AnsiToUnicode( const char* szStr )
- {
- int nLen = MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, szStr, -1, NULL, 0 );
- if (nLen == 0)
- {
- return NULL;
- }
- wchar_t* pResult = new wchar_t[nLen];
- MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, szStr, -1, pResult, nLen );
- return pResult;
- }
- //将宽字节wchar_t*转化为单字节char*
- inline char* UnicodeToAnsi( const wchar_t* szStr )
- {
- int nLen = WideCharToMultiByte( CP_ACP, 0, szStr, -1, NULL, 0, NULL, NULL );
- if (nLen == 0)
- {
- return NULL;
- }
- char* pResult = new char[nLen];
- WideCharToMultiByte( CP_ACP, 0, szStr, -1, pResult, nLen, NULL, NULL );
- return pResult;
- }
wchar_t*和char*之间的互相转换的那些事的更多相关文章
- wchar_t 和 char 之间转换
vc++2005以后,Visual studio 编译器默认的字符集为Unicode.VC中很多字符处理默认为宽字符wchar_t,如CString的getBuffer(),而一些具体操作函数的输入却 ...
- CString string char* char 之间的字符转换(多种方法)
在写程序的时候,我们经常遇到各种各样的类型转换,比如 char* CString string 之间的互相转换.首先解释下三者的含义. CString 是一种很有用的数据类型.它们很大程度上简化了MF ...
- C++中“wchar_t* ”和“ char * ”之间的相互转换
把char*转换为wchar_t* 用stdlib.h中的mbstowcs_s函数,可以通过下面的例子了解其用法: char *CStr = "string to convert" ...
- string与char之间的互相转换
string对象是一种很强大的存在哈~~ 1. string转const char* string s = "abc"; const char* c_s = s.c_str(); ...
- string char * const char *之间的互相转换
string -> const char * 用str的c_str()方法或者data()方法均可,这个两个方法返回值为cong char * string str = "hel ...
- int 与 String 与 char 之间的互相转换
int 转 String: //方式一: int i1 = 888; String s1 = Integer.toString(i1); //方式二: int i2 = 888; String s2 ...
- wchar_t * 与 char * 互相转换小记
wchar_t * 与char *之间的转化只需要借助标准库里面的std::wcstombs和std::mbstowcs就能实现了
- (转)CString,int,string,char*之间的转换
CString,int,string,char*之间的转换http://www.cnblogs.com/greatverve/archive/2010/11/10/cstring-int-string ...
- MFC/C++/C中字符类型CString, int, string, char*之间的转换
1 CString,int,string,char*之间的转换 string 转 CString CString.format("%s", string.c_str()); cha ...
随机推荐
- Android导航栏ActionBar的具体分析
尊重原创:http://blog.csdn.net/yuanzeyao/article/details/39378825 关于ActionBar,相信大家并不陌生,可是真正能够熟练使用的也不是许多,这 ...
- hdu 2777(线段树)
这道题是看了别人的思路才做出来的. 刚看完这道题没什么思路,线段的长度是10^5,操作指令数是10^5,还要记录不同颜色种类数,觉着怎么写肯定都是要超时.我当时在节点里增加了一个数组记录已经出现的颜色 ...
- NHibernate初入门之映射文件配置说明(三)
转载逆心http://www.cnblogs.com/kissdodog/archive/2013/02/21/2919886.html 1. hibernate-mapping 这个元素包括以下可选 ...
- Google Maps 学习笔记(三)
1.GPolyline折线对象和GPolygon多边形对象 html标签中必须包含v="urn:schemas-microsoft--com:vml"的命名空间 <html ...
- C#复习三(Day 22)
哈哈,又到了总结的时间了.今天还是在继续复习C#的基础语法.这次总结主要以一下小程序为主. Split()的运用 123-456---789-----123-2把类似的字符串中重复符号去掉,得到123 ...
- News feed
1. Level 1.0 Database Schema: a. User UserID Name Age 1 Jason 25 2 Michael 26 b. Friendship Friendsh ...
- JS学习之prototype属性
javascript中的每个对象都有prototype属性,Javascript中对象的prototype属性的解释是:返回对象类型原型的引用.以A.prototype = new B();为例, 理 ...
- 利用python进行数据分析之数据聚合和分组运算
对数据集进行分组并对各分组应用函数是数据分析中的重要环节. group by技术 pandas对象中的数据会根据你所提供的一个或多个键被拆分为多组,拆分操作是在对象的特定轴上执行的,然后将一个函数应用 ...
- 用PyRestful快速构建Tornado下REST APIs 的支持
一.安装PyRestful库 $ pip install pyrestful 二.使用案例 (一)books_service.py # -*- coding: utf-8 -*- import tor ...
- jQuery File Upload 插件 php代码分析
jquery file upload php代码分析首先进入构造方法 __construct() 再进入 initialize()因为我是post方式传的数据 在进入initialize()中的po ...