使用 P-Invoke 将字符串数组从托管 C# 传递到非托管函数
是否可以使用 P-Invoke 将字符串数组从托管 C# 传递到非托管函数?
这工作正常:
[DllImport("LibraryName.dll")]
private static extern void Function_Name(string message);
虽然这:
[DllImport("LibraryName.dll")]
private static extern void Function_Name(string[] message);
失败了
未处理的异常:System.NotSupportedException:NotSupportedException
我尝试使用MarshalAs
但没有成功([MarshalAs(UnmanagedType.LPArray, ArraySubType=UnmanagedType.LPWStr)] String[] dataToLoadArr)
是否可以通过这种方式传递字符串数组?
Is it possible to pass a string array from managed C# to an unmanaged function using P-Invoke?
This works fine:
[DllImport("LibraryName.dll")]
private static extern void Function_Name(string message);
While this:
[DllImport("LibraryName.dll")]
private static extern void Function_Name(string[] message);
fails with
Unhandled exception: System.NotSupportedException: NotSupportedException
I have tried using MarshalAs
with no luck ([MarshalAs(UnmanagedType.LPArray, ArraySubType=UnmanagedType.LPWStr)] String[] dataToLoadArr)
Is it possible to pass string arrays this way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这在我的 OpenCL 库 OpenCL.NET (http://openclnet.codeplex.com/SourceControl/changeset/view/94246#1251571) 中运行良好。请注意,我也使用 SizeParamIndex 传递计数。
This works fine in my OpenCL library, OpenCL.NET (http://openclnet.codeplex.com/SourceControl/changeset/view/94246#1251571). Note that I am passing in the count using SizeParamIndex as well.