I am new to C++/Cli, actually in the C# project I have string[] which I converted to array, Now I need to pass this unmanaged array into the native CPP file, ie I want to convert this "array" to std::string*. How I can do that. I tried this below:
void functionA(cli::array^varA){
cli::pin_ptr<System::String^>varA_value = &varA[0];
std::string* varA_value_final = varA_value;
}
But it gives error saying: a value of type cli::pin_ptr cannot be used to initialize entity of type std::string*
The managed class System::String
is completely different from the unmanaged class std::string
. The classes are completely different, and store completely different data. You cannot get a pointer to one and pretend it's the other.
Iterate over the cli::array<System::String^>
, convert each element, and stick the results in a std::vector<std::string>
or other unmanaged container. Grab a pointer to the first element. Use marshal_as<std::string>()
to convert each element.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.