gcnew和System :: IntPtr ^使用中的错误在托管c ++中具有处理程序 [英] errors in usage of gcnew and System::IntPtr^ has handler in managed c++

查看:137
本文介绍了gcnew和System :: IntPtr ^使用中的错误在托管c ++中具有处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目

MyClass::Func01(UINT32 param1, UINT32 param2)
{

UINT8* invalBuf = NULL; // System::IntPtr^ invalBuf = NULL; even uncommenting and usage of above would give the same error.
Error	8	error C2059: syntax error : ';'	e:\Proj\ManagedProject.cpp	232
UINT8* outvalBuf = NULL; // System::IntPtr^ outvalBuf = NULL;
Error	9	error C2059: syntax error : ';'	e:\Proj\ManagedProject.cpp	232

UINT16 var1;
UINT32 var2;
.....

when invoking gcnew with above variables, and allocation of memory,

invalBuf = (System::IntPtr) gcnew(var1,true,"invalBuf");
...
memcpy(outBuf,inBuf,var1);
//error C2440: 'type cast' : cannot convert from 'System::IntPtr ^' to 'void *'	e:\Proj\ManagedProject.cpp	249	


outvalBuf[2] = Some bitwise operated value;
Error	13	error C3915: 'System::IntPtr' has no default indexed property (class indexer)	e:\Proj\ManagedProject.cpp	252

outvalBuf[3] = some other bitwise operted values;
....
	
....
....


我需要解决与每个语句对应的错误,我正在使用Managed C ++,并使用gcnew进行内存分配,即使我使用System :: IntPtr ^具有处理程序,也无法克服以上错误.解决上述问题的任何帮助都将是可观的.

另外,我正在使用VS2008 IDE,Win 7 SP1 O/S.

问候,
Samanth_90


I need to resolve the errors given correponding to each statements, I am using Managed C++, and using gcnew for allocation of memory, Even if I use System::IntPtr^ has handler, I could not overcome the above error. Any Help in resolving the above would be appreciable.

Also, I am using VS2008 IDE, Win 7 SP1 O/S.

With Regards,
Samanth_90

推荐答案

此代码是一团糟,几乎无法修复.您应该知道的第一件事:指针的C ++/CLI类似物是管理器引用,请使用"^"而不是"*".

通常,如果您使用C ++/CLI,则请记住,尽管可以将两者结合使用,但它与C ++相差甚远.因此,与其基于您的C ++经验开始学习,不如阅读有关C ++/CLI语言的大量文章.

请参阅:
http://en.wikipedia.org/wiki/C%2B%2B/CLI [ ^ ],
http://www.ecma-international.org/publications/standards/Ecma-372.htm [^ ],
http://msdn.microsoft.com/en-us/library/dtefa218.aspx [ ^ ].

—SA
This code is a mess, nearly beyond repair. First thing you should know: C++/CLI analog of pointer is the manager reference, use ''^'' instead of ''*''.

Generally, if you use C++/CLI, remember that it is pretty far from C++, even though you can combine both. So, instead of starting based on you C++ experience, read a good deal about the C++/CLI language.

Please see:
http://en.wikipedia.org/wiki/C%2B%2B/CLI[^],
http://www.ecma-international.org/publications/standards/Ecma-372.htm[^],
http://msdn.microsoft.com/en-us/library/dtefa218.aspx[^].

—SA


这篇关于gcnew和System :: IntPtr ^使用中的错误在托管c ++中具有处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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