我想在 C# 表单应用程序的列表框中打印 C++ 向量的元素

I want to print the elements of the C++ vector in a listbox in the C# form application

我写了一个C++ dll。 dll的其中一个函数returns作为参数的vector如下

 std::vector<std::string> foo(std::vector<std::string> strVec) {return strVec;}

我想将向量的元素(即上述函数的 return 值)写入 C# 上名为 lstData 的列表框中 side.How 可以吗?提前致谢。

a std::vector<std::string> 是一个 C++ 对象。 P/Invoke 调用 c 风格的函数并且不了解 c++ 对象。您的选择或多或少

  1. 为你的 c++ dll 添加一个方法,accepts/returns 指针或 C 风格数组。
  2. 编写一个 c++/cli 适配器,在矢量和 C# 之间进行转换list/array。