According to some older StackOverflow questions ( Unable to pass std::wstring across DLL , C++ DLL returning pointer to std::list
Nothing has changed with regards passing C++ objects across DLL boundaries. That is still not allowed for the same reason as before. The module on the other side of the boundary may have a different definition of the class.
The fact that &s[0]
is a valid modifiable pointer to character array is not really relevant. Because a std::basic_string
is a lot more than just an array of characters.
Remember that each implementation of std::basic_string
can have different internal storage. Can have a different implementation for operator[]
. Can be allocated off a different heap. And so on.
I think it is safe to assume that it will never be valid to pass C++ objects across general DLL boundaries. It is only viable if you guarantee that both sides of the boundary are linked against the same runtime instance.