How would I convert a System (.net) C++\CLI
String^
into a MFC C++ LPCTSTR
string.
It is very easy to get a LPCTSTR
into String^
, but so far found nothing on doing it the other way around.
How would I convert a System (.net) C++\CLI
String^
into a MFC C++ LPCTSTR
string.
It is very easy to get a LPCTSTR
into String^
, but so far found nothing on doing it the other way around.
If you have Visual Studio 2008 or above, you should be able to do this using the C++/CLI marshaling library, like so:
More information on marshaling between types on MSDN: Overview of Marshaling in C++
You might want to try Marshal::StringToHGlobalUni, Marshal::StringToHGlobalAuto or Marshal::StringToHGlobalAnsi.
Remember the allocated unmanaged strings will need to be freed with Marshal::FreeHGlobal.