如何使用P/Invoke在C#中返回列表
How to return a list in C# using P/Invoke?
我正在处理一个小项目,在该项目中我使用p/Invoke,并希望在C#中返回以下内容:
public: class std::list<int,class std::allocator<int> > const * __thiscall TransactionsModule_t::GetTransactionList(void)const
现在我感到困惑的地方是:
[DllImport("TransactionManager.dll", EntryPoint = "...", CallingConvention = CallingConvention.ThisCall)]
public static extern ??? GetTransactionList(
IntPtr interfacePtr);
我甚至不知道从哪里开始寻找,因为我无法直接看到返回类型是什么,很明显,这是一种列表。我理解这么多,但这是一个嵌套列表吗?也许是字典Dictionary<int,List<int>>
?
您不能这样做。模板类型AFAIK不适用于P/Invoke,可能是因为运行时无法计算列表的长度/如何分配&释放所需的内存量等。
最好的办法是编写一个C++/CLI包装器,或者将C++中的返回类型更改为int数组,或者将参数传递给可以在C++端填充的方法(out参数(。
您可能认为C#列表和std::列表可以双向排列,但事实并非如此。
相关问题:封送.NET泛型类型
相关文章:
- C++:如何使函数只返回作为列表一部分的字符串
- 将大括号括起来的初始值设定项列表作为结构返回
- 从封装在对象中的函数 C++ 返回时为空的列表
- 如何在不销毁对象的情况下返回对象列表
- 什么更好?返回对象指针列表?或返回指向对象列表的指针?
- 如何优化代码以返回最接近给定整数的数字,但给定列表中不存在?
- 给定一个源文件,有没有办法要求 gcc 返回仅直接包含的头文件的列表?
- 当返回语句时,逗号运算符、大括号初始化列表和 std::unique_ptr 组合在一起
- 从非托管 C# DLL 返回列表/数组
- 在索引中插入节点:链接列表未正确返回列表
- C++列表函数返回列表
- 从 C++ 调用的 python 方法返回列表
- 如何返回列表成员 c++ 的空指针
- std::对中的C++返回列表
- 递归:按顺序遍历返回列表
- 返回列表元素的指针(如果具有相同的名称)
- 如何使用P/Invoke在C#中返回列表
- 当按值返回列表初始化的对象时,为什么不调用复制构造函数?
- 如何在C++中返回列表
- 返回列表前端 (C++) 的类型