简体   繁体   中英

Managed C++ pass float *OUT as argument

I make .Net wrapper for unmanaged C++ library. I need to use function with this signature:

BOOL Func ( float *OUT floatArray)

I tried this in managed C++:

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

But I got an 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++:

bool MyFunc (array<Single>^% floatArray)

I'm trying to return C# float[] with this function. Maybe there is another option to do my task.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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