is there any way through which we can get the collection of string from c++ to c#
C# Code
[DllImport("MyDLL.dll")]
private static extern List<string> GetCollection();
public static List<string> ReturnCollection()
{
return GetCollection();
}
C++ Code
std::vector<string> GetCollection()
{
std::vector<string> collect;
return collect;
}
The code above is only for sample, the main aim is to get collection in C# from C++, and help would be appreciated
//Jame S
There are a multitude of ways to tackle this, but they are all rather more complex than what you currently have.
Probably the easiest way to pass a string allocated in C++ to C# is as a BSTR
. That allows you to allocate the string down in your C++ and let the C# code deallocate it. This is the biggest challenge you face and marshalling as BSTR
solves it trivially.
Since you want a list of strings you could change to marshalling it as an array of BSTR
. That's one way, it's probably the route I would take, but there are many other approaches.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With