关于VS2005的error C2664: cannot convert parameter 2 from 'const char [2]' to 'LPCWSTR

一、VS2005设置UNICODE或ASCII字符集问题

VS2005开发程序时,默认的字符集是Unicode。所以如果程序中使用字符常量一定要显示转换为Unicode型,否则编译时报错。

如果你不希望程序支持Unicode字符集,更改项目设置就可以了。

project->properties->configurations Properties -> General ->Project Defaults -> Charater Set中将Unicode字符集改为未设置即可。

(解释从网络转载)

UNICODE <wbr><wbr><br><wbr><span></span>  计算机发明后,为了在计算机中表示字符,人们制定了一种编码,叫ASCII码。ASCII码由一个字节中的7位(bit)表示,范围是0x00 <wbr><span></span>- <wbr><span></span>0x7F <wbr><span></span>共128个字符。他们以为这128个数字就足够表示abcd....ABCD....1234 <wbr><span></span>这些字符了。 <wbr><wbr><br><wbr><span></span>  咳......说英语的人就是“笨”!后来他们突然发现,如果需要按照表格方式打印这些字符的时候,缺少了“制表符”。于是又扩展了ASCII的定义,使用一个字节的全部8位(bit)来表示字符了,这就叫扩展ASCII码。范围是0x00 <wbr><span></span>- <wbr><span></span>0xFF <wbr><span></span>共256个字符。 <wbr><wbr><br><wbr><span></span>  咳......说中文的人就是聪明!中国人利用连续2个扩展ASCII码的扩展区域(0xA0以后)来表示一个汉字,该方法的标准叫GB-2312。后来,日文、韩文、阿拉伯文、台湾繁体(BIG-5)......都使用类似的方法扩展了本地字符集的定义,现在统一称为 <wbr><span></span>MBCS <wbr><span></span>字符集(多字节字符集)。这个方法是有缺陷的,因为各个国家地区定义的字符集有交集,因此使用GB-2312的软件,就不能在BIG-5的环境下运行(显示乱码),反之亦然。 <wbr><wbr><br><wbr><span></span>  咳......说英语的人终于变“聪明”一些了。为了把全世界人民所有的所有的文字符号都统一进行编码,于是制定了UNICODE标准字符集。 UNICODE <wbr><span></span>使用2个字节表示一个字符(unsigned <wbr><span></span>shor <wbr><span></span>int、WCHAR、_wchar_t、OLECHAR)。这下终于好啦,全世界任何一个地区的软件,可以不用修改地就能在另一个地区运行了。虽然我用 <wbr><span></span>IE <wbr><span></span>浏览日本网站,显示出我不认识的日文文字,但至少不会是乱码了。UNICODE <wbr><span></span>的范围是 <wbr>0x0000 <wbr><span></span>- <wbr><span></span>0xFFFF <wbr><span></span>共6万多个字符,其中光汉字就占用了4万多个。嘿嘿,中国人赚大发了:0) <wbr><wbr><br><wbr><span></span>  在程序中使用各种字符集的方法: <wbr><wbr><br><wbr><span></span><wbr><wbr><br><wbr><span></span><wbr><span></span><wbr><span></span><wbr><span></span><wbr><span></span><wbr><span></span><wbr><span></span>const <wbr><span></span>char <wbr><span></span>* <wbr><span></span>p <wbr><span></span>= <wbr><span></span>"Hello"; <wbr><span></span>// <wbr><span></span>使用 <wbr><span></span>ASCII <wbr><span></span>字符集 <wbr><wbr><br><wbr><span></span><wbr><span></span><wbr><span></span><wbr><span></span><wbr><span></span><wbr><span></span><wbr><span></span>const <wbr><span></span>char <wbr><span></span>* <wbr><span></span>p <wbr><span></span>= <wbr><span></span>"你好"; <wbr><span></span>// <wbr><span></span>使用 <wbr><span></span>MBCS <wbr><span></span>字符集,由于 <wbr><span></span>MBCS <wbr><span></span>完全兼容 <wbr><span></span>ASCII,多数情况下,我们并不严格区分他们 <wbr><wbr><br><wbr><span></span><wbr><span></span><wbr><span></span><wbr><span></span><wbr><span></span><wbr><span></span><wbr><span></span>LPCSTR <wbr><span></span>p <wbr><span></span>= <wbr><span></span>"Hello,你好"; <wbr><span></span>// <wbr><span></span>意义同上 <wbr><wbr><br><wbr><span></span><wbr><span></span><wbr><span></span><wbr><span></span><wbr><span></span><wbr><span></span><wbr><span></span><wbr><wbr><br><wbr><span></span><wbr><span></span><wbr><span></span><wbr><span></span><wbr><span></span><wbr><span></span><wbr><span></span>const <wbr><span></span>WCHAR <wbr><span></span>* <wbr><span></span>p <wbr><span></span>= <wbr><span></span>L"Hello,你好"; <wbr><span></span>// <wbr><span></span>使用 <wbr><span></span>UNICODE <wbr><span></span>字符集 <wbr><wbr><br><wbr><span></span><wbr><span></span><wbr><span></span><wbr><span></span><wbr><span></span><wbr><span></span><wbr><span></span>LPCOLESTR <wbr><span></span>p <wbr><span></span>= <wbr><span></span>L"Hello,你好"; <wbr><span></span>// <wbr><span></span>意义同上 <wbr><wbr><br><wbr><span></span><wbr><span></span><wbr><span></span><wbr><span></span><wbr><span></span><wbr><span></span><wbr><span></span><wbr><wbr><br><wbr><span></span><wbr><span></span><wbr><span></span><wbr><span></span><wbr><span></span><wbr><span></span><wbr><span></span>// <wbr><span></span>如果预定义了_UNICODE,则表示使用UNICODE字符集;如果定义了_MBCS,则表示使用 <wbr>MBCS <wbr><wbr><br><wbr><span></span><wbr><span></span><wbr><span></span><wbr><span></span><wbr><span></span><wbr><span></span><wbr><span></span>const <wbr><span></span>TCHAR <wbr><span></span>* <wbr><span></span>p <wbr><span></span>= <wbr><span></span>_T("Hello,你好"); <wbr><span></span><wbr><wbr><br><wbr><span></span><wbr><span></span><wbr><span></span><wbr><span></span><wbr><span></span><wbr><span></span><wbr><span></span>LPCTSTR <wbr><span></span>p <wbr><span></span>= <wbr><span></span>_T("Hello,你好"); <wbr><span></span>// <wbr><span></span>意义同上 <wbr><wbr><br><wbr><span></span>  在上面的例子中,T是非常有意思的一个符号(TCHAR、LPCTSTR、LPTSTR、_T()、_TEXT()...),它表示使用一种中间类型,既不明确表示使用 <wbr><span></span>MBCS,也不明确表示使用 <wbr><span></span>UNICODE。那到底使用哪种字符集那?嘿嘿......编译的时候决定吧。设置条件编译的方式是:VC6 中,"Project\Settings...\C/C++卡片 <wbr>Preprocessor <wbr><span></span>definitions" <wbr><span></span>中添加或修改 <wbr><span></span>_MBCS、_UNICODE;VC.NET中,"项目\属性\配置属性\常规\字符集"然后用组合窗进行选择。使用 <wbr><span></span>T <wbr><span></span>类型,是非常好的习惯,严重推荐!</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

转自:http://blog.sina.com.cn/s/blog_70b3b3a701010g2f.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值