在VS 2005中将String *转换为wchar_t [英] Conversion of String* to wchar_t in VS 2005

查看:142
本文介绍了在VS 2005中将String *转换为wchar_t的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我正在使用VS 2005来升级演示项目,我在一堆代码中遇到了这个错误

,这些代码在VC ++ 2003上编译得很好。


< code>

wchar_t __pin * pVal = PtrToStringChars(val);

< / code>


< ;错误>

错误1错误C2440:''初始化'':无法将''__ const_Char_ptr''

转换为''wchar_t __pin *''

< / error>


任何人都可以给我一个如何解决这个问题的提示。还包括vcclr.h。


谢谢,


blair

解决方案
"布莱尔" < BL *** @ discussions.microsoft.com>在留言中写道

news:67 ********************************** @ microsof t.com ...

您好我正在使用VS 2005来升级演示项目,我在一堆代码中遇到了这个
错误
在VC ++ 2003上编译得很好.....................................................错误1错误C2440:''初始化'':无法从
'__ const_Char_ptr''
转换为''wchar_t __pin *''
< / error>

任何人都可以给我一个如何解决这个问题的提示。还包括vcclr.h。




我_think_新语法要求目标是const


const_cast< interior_ptr<字符> >(PtrToStringChars(val));


我应该告诉你,我还没有与VS2005进行任何互操作和

避风港'编译这个。


对旧的差异的一个很好的介绍MC ++语法和

" new" C ++ / CLI语法在这里:

http://msdn.microsoft.com/library/de...TransGuide.asp


问候,




blair写道:

您好我正在使用VS 2005升级演示项目和我在一堆代码中遇到了这个错误
在VC ++ 2003上编译得很好。

< code>
wchar_t __pin * pVal = PtrToStringChars(val);
< / code>

<错误>
错误1错误C2440:''初始化'':无法从''__ const_Char_ptr''转换为''/' wchar_t __pin *''
< / error>

任何人都可以给我一个如何解决这个问题的提示。还包括vcclr.h。

谢谢,

blair




用于固定的C ++ / CLI语法是

cli :: pin_ptr< wchar_t> pVal(PtrToStringChars(val));


我还没试过这个例子。


或者你使用旧的MC ++句法?我从未在VC ++ 2005中使用它。


Tom


我正在尝试编译一些旧的代码语法,以便我可以调试一些在.NET 2.0下运行时看到的唯一错误(实际程序使用的是b
)。我只有源和一个发布dll :)


当我尝试这段代码时:

const_cast< interior_ptr<字符> >(PtrToStringChars(val));

编译器抛出语法错误可能是因为我启用了/ clr:oldSyntax

。我真的不想将整个代码库重写为新的

语法;但是如果我必须好好的话。


感谢您的帮助,

blair


Tamas Demjen ;写道:

blair写道:

您好我正在使用VS 2005升级一个演示项目我遇到了这个错误
在一堆在VC ++ 2003上编译好的代码。

< code>
wchar_t __pin * pVal = PtrToStringChars(val);
< / code>
<错误>
错误1错误C2440:''初始化'':无法从''__ const_Char_ptr''转换为''wchar_t __pin *''
< / error>

任何人都可以给我一个如何解决这个问题的提示。还包括vcclr.h。

谢谢,

blair



用于固定的C ++ / CLI语法是
CLI :: pin_ptr< wchar_t的> pVal(PtrToStringChars(val));

我还没试过这个例子。

或者您使用旧的MC ++语法?我从未在VC ++ 2005中使用它。

Tom



Hi I am using VS 2005 to upgrade a demo project and I came across this error
in a bunch of code which compiles fine on VC++ 2003.

<code>
wchar_t __pin* pVal = PtrToStringChars( val );
</code>

<error>
Error 1 error C2440: ''initializing'' : cannot convert from ''__const_Char_ptr''
to ''wchar_t __pin *''
</error>

Can anyone give me a hint on how to fix this. Also vcclr.h is included.

Thanks,

blair

解决方案

"blair" <bl***@discussions.microsoft.com> wrote in message
news:67**********************************@microsof t.com...

Hi I am using VS 2005 to upgrade a demo project and I came across this
error
in a bunch of code which compiles fine on VC++ 2003.

<code>
wchar_t __pin* pVal = PtrToStringChars( val );
</code>

<error>
Error 1 error C2440: ''initializing'' : cannot convert from
''__const_Char_ptr''
to ''wchar_t __pin *''
</error>

Can anyone give me a hint on how to fix this. Also vcclr.h is included.



I _think_ that the new syntax requires that the target be const

const_cast< interior_ptr<Char> >( PtrToStringChars(val) );

I should tell you, though, that I haven''t done any interop with VS2005 and
haven''t compiled this.

A good introduction to the differences with the "old" MC++ syntax and the
"new" C++/CLI syntax is here:

http://msdn.microsoft.com/library/de...TransGuide.asp

Regards,
Will


blair wrote:

Hi I am using VS 2005 to upgrade a demo project and I came across this error
in a bunch of code which compiles fine on VC++ 2003.

<code>
wchar_t __pin* pVal = PtrToStringChars( val );
</code>

<error>
Error 1 error C2440: ''initializing'' : cannot convert from ''__const_Char_ptr''
to ''wchar_t __pin *''
</error>

Can anyone give me a hint on how to fix this. Also vcclr.h is included.

Thanks,

blair



The C++/CLI syntax for pinning is
cli::pin_ptr<wchar_t> pVal(PtrToStringChars(val));

I haven''t tried this example, though.

Or are you using the old MC++ syntax? I''ve never used that with VC++ 2005.

Tom


I am trying to compile some code written in the old syntax so that I can
debug some unique errors only seen when running under .NET 2.0 (what my
actual program uses). I have the source and a Release dll only :)

Also when I tried this code:
const_cast< interior_ptr<Char> >( PtrToStringChars(val) );
the complier threw a syntax error probably because I have /clr:oldSyntax
enabled. I really do not want to rewrite the whole code base into the new
syntax; but if I have to Oh well.

Thanks for the help,
blair

"Tamas Demjen" wrote:

blair wrote:

Hi I am using VS 2005 to upgrade a demo project and I came across this error
in a bunch of code which compiles fine on VC++ 2003.

<code>
wchar_t __pin* pVal = PtrToStringChars( val );
</code>

<error>
Error 1 error C2440: ''initializing'' : cannot convert from ''__const_Char_ptr''
to ''wchar_t __pin *''
</error>

Can anyone give me a hint on how to fix this. Also vcclr.h is included.

Thanks,

blair



The C++/CLI syntax for pinning is
cli::pin_ptr<wchar_t> pVal(PtrToStringChars(val));

I haven''t tried this example, though.

Or are you using the old MC++ syntax? I''ve never used that with VC++ 2005.

Tom



这篇关于在VS 2005中将String *转换为wchar_t的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆