-2

I wrote a C ++ dll. One of the dll's functions returns the vector it takes as a parameter as follows

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

I want to write the elements of the vector, which is the return value of the above function, into the listbox named lstData on the C# side.How can I do that ? Thanks in advance.

east1000
  • 1,240
  • 1
  • 10
  • 30
  • 2
    Well, you can't just "pass" a C++ vector to C# code as is. You need to write some sort of interop layer, either P/Invoke (like the linked answer shows) or C++/CLI. Once that's done, then the rest is just trivial enumeration. – Etienne de Martel Apr 19 '21 at 14:22

1 Answers1

1

a std::vector<std::string> is a c++ object. P/Invoke calls c-style functions and have no understanding of c++ objects. Your alternatives are more or less

  1. Add a method to you c++ dll that accepts/returns pointers or c-style arrays.
  2. Write a c++/cli adapter that converts between the vector and a C# list/array.
JonasH
  • 28,608
  • 2
  • 10
  • 23