简体   繁体   English

托管C ++通过float * OUT作为参数

[英]Managed C++ pass float *OUT as argument

I make .Net wrapper for unmanaged C++ library. 我为非托管C ++库制作.Net包装器。 I need to use function with this signature: 我需要使用带有此签名的功能:

BOOL Func ( float *OUT floatArray)

I tried this in managed C++: 我在托管C ++中尝试过此操作:

float* mp = new float(10);
bool what = Func(mp);

But I got an AccessViolationException. 但是我有一个AccessViolationException。 (Attempt to read or write protected memory. This often indicates that the other memory is corrupt.) What's wrong? (尝试读取或写入受保护的内存。这通常表示其他内存已损坏。)这是怎么回事?

This is my function in managed C++: 这是我在托管C ++中的功能:

bool MyFunc (array<Single>^% floatArray)

I'm trying to return C# float[] with this function. 我正在尝试使用此函数返回C#float []。 Maybe there is another option to do my task. 也许还有另一种选择可以完成我的任务。

在C ++中将在C ++中分配的(托管)未托管内存的大块返回给C#似乎是一个相当糟糕的主意(谁负责释放内存(删除[]))?您在C ++中使用了System :: Array并通过'ref'传递了值(在c#中)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM