如何解决是否可以通过c#将SafeHandles数组发送到本机函数?
我有一个本机(c ++)函数,该函数将指向图像的指针数组作为参数。在我的c#API中,指向图像的指针被保存为SafeHandle。现在,我想向我的函数发送一个SafeHandles数组,但随后遇到以下错误。
System.Runtime.InteropServices.MarshalDirectiveException: Cannot marshal 'parameter #2': Invalid managed/unmanaged type combination (Arrays of SafeHandles are not supported).
简化后的代码如下:
本地方
int concatenate_images(Image **img_ref,Image **images)
{
// Concatenate the images and put the result in img_ref[0]
}
受管理方
请注意,ImageHandle是从SafeHandle派生的
Image Concatenate(Image[] images)
{
ImageHandle h = new ImageHandle();
if (!concatenate_images(ref h,handles_array))
throw new Exception("Failed concatenating images.");
return new Image(h);
}
private static extern int concatenate_images(ref ImageHandle img_ref,[In,Out] ImageHandle [] images)
我当然可以通过从SafeHandle中提取IntPtr并发送这些数组来解决问题 反对我的本机功能。但是据我了解,那么我将没有SafeHande提供的一些额外安全性。
那么,我应该如何将对象发送到本机函数?我必须制作一个IntPtr数组还是有更好的方法?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。