I’m not sure the standard guarantees that the data in a std::string
is stored as a char*
. The most portable way I can think of is to use a std::vector
, which is guaranteed to store its data in a continuous chunk of memory:
std::vector<char> buffer(100);
FunctionInDLL(&buffer[0], buffer.size());
std::string stringToFillIn(&buffer[0]);
This will of course require the data to be copied twice, which is a bit inefficient.