MSDN provides some information on how to marshal data. They also provide some standard implementation for msclr::marshal_aswrt std::string.
cli::arraya little more complicated, the key for the general case here is the pinarray at first (so we don’t have its movement behind our backs). In case of conversion String^ marshal_aswill be pin Stringappropriate.
The essence of the code:
vector<string> marshal_array(cli::array<String^>^ const& src)
{
vector<std::string> result(src->Length);
if (src->Length) {
cli::pin_ptr<String^> pinned = &src[0];
for (int i = 0; i < src->Length; ++i) {
result[static_cast<size_t>(i)] = marshal_as<string>(src[i]);
}
}
return result;
}