C++/CLI: Convert a String to BSTR or some other nasty stuff
This is very usual when replacing a COM interface with a C++/CLI wrapper (Guess who's doing that?). That usually leads to the need to convert a .NET string (System::String^) to a BSTR, or a std::string. Luckily, .NET provides some handy conversion functions for this. They save us the hassle of creating buffers, releasing them and whatnot. Among them are the marshal_as functions and the marshal_context class.
Here's the lowdown for when to use which: Overview of Marshalling in C++
Comments
Post a Comment