Convert String^ in c# to CString in c++/CLI
.net, c#, c-strings, mfc, string
Solution
Consider reading this MSDN thread about string conversions. Also, following discussions may be useful for you:
- Convert CString to std::wstring
- Problem: How to convert CString into const char * in C++ MFC
- Converting String to Cstring in c++
- CString to LPCTSTR conversion
- Conversion of CString to char
- How to convert _bstr_t to CString
With this material you can find out how to do it and even post own solution as an answer
Problem
I need a help on one question where I stuck while coding my app in `MFC`. I am using `CLR` i.e `Common Language Runtime` in my application to integrate c# APIs. but now I stuck on converting `System::String^` to `CString`. I am not able to do that. I am using Following code. ``` String^ csPass = gcnew String(strPassword.GetBuffer()); array<Byte>^ Value = Encoding::UTF8->GetBytes(csPass); for (int i = 0; i < Value->Length; i++ ) { csPass += String::Format( "{0:X2}", Value[ i ] ); } ``` now I want to convert `csPass` to `CString`. Can any one help me on this. Thank you in advance.