【发布时间】:2019-07-03 15:57:48
【问题描述】:
我有一个 C++ 函数:
std::map<std::string, std::string> foo(const std::vector<unsigned char>& v);
Swig 生成以下 C# 函数:
MapStringString foo(SWIGTYPE_p_std__vectorT_unsigned_char_t v);
我想在 C# 函数中调用它,该函数接收 byte[] 并返回 IDictionary,即:
IDictionary<string, string> bar(byte[] b)
{
SWIGTYPE_p_std__vectorT_unsigned_char_t b1;
// initialize b1 from b
MapStringString m = foo(b1);
IDictionary<string, string> result;
// Populate result from MapStringString
return result;
}
如何从 b 初始化 b1(即 SWIGTYPE_p_std__vectorT_unsigned_char_t 从 byte[])以及如何从 MapStringString 填充 IDictionary?
提前致谢!
【问题讨论】:
-
我不知道 swig,但是 Visual Studio 中的 IntelliSense,或者 Visual Studio 的对象浏览器(右键单击类型名称,从上下文菜单中选择“转到定义”)应该可以告诉你 swig 生成的
SWIGTYPE_p_std__vectorT_unsigned_char_t和MapStringString类型提供了哪些方法/字段/属性/索引器。我希望一旦你真正看到/知道这些类型提供的方法/字段/属性/索引器应该不会太难...... -
谢谢! Visual Studio 中的 SWIGTYPE_p_std__vectorT_unsigned_char_t 向我展示了 4 种方法:Equals、GetHashCode、GetType、ToString - 它们看起来都不适合提取数组元素。
-
SWIGTYPE_p_std__vectorT_unsigned_char_t是否可能派生自可能提供更多有用成员的基类? -
不,它不是从任何类派生的。它实际上是一个生成的类。互联网上到处都是 Swig 帮助显示如何生成类,但无处显示如何使用它们。
-
好吧,除非有人可以帮助你喝 swig(正如我所说,我不知道 swig;我什至不知道 swig 是否以及如何能够编组复杂的 C++ 类型,这将是相当的壮举)。 (1/2)