Reputation: 5115
how would I return a C++ std::vector<std::string>
to C# code?
My methods declaration (C++ side) currently Looks like:
__declspec(dllexport) std::vector<std::string> __cdecl Initialize(std::vector<std::string> array = {})
But I have no idea about how to get the vector
or how to send it to C++.
Any help is greatly appreciated.
Upvotes: 1
Views: 1567
Reputation: 42944
It's not trivial to marshal a vector
of strings.
You may consider building a bridging layer between C++ and C# using C++/CLI.
If you don't want to use C++/CLI, a valid alternative is to use SAFEARRAY
s. You can simplify safe array programming in C++ with ATL::CComSafeArray
.
You may find this article on safe arrays on MSDN Magazine helpful.
You should also pay attention to the string encoding. If you use UTF-8 for you std::string
s, then you should convert to UTF-16 for SAFEARRAY(BSTR)
or for the .NET String
class.
Upvotes: 4