As this is my first post (and it's a question :D ) I have to say this website is amazing and very helpful. Thank You for making it. So, here is my problem... I'm trying to convert String^ to wstring, searching already 3 days but cannot find anything about that.. I'm writing a program that creates a desktop shortcut of the file user selects. I use FolderBrowserDialog^ so that users can select the path, and it returns String^, and I use IShellLink to create the shortcut, which works with LPCWSTR. So I need to convert String^ to LPCWSTR, and I don't know how to, but I can convert wstring to LPCWSTR, so if I could do String^ to wstring, would be great)) Thank you.
Asked
Active
Viewed 324 times
-1
-
https://msdn.microsoft.com/en-us/library/d1ae6tz5.aspx – Hans Passant Apr 24 '16 at 15:49
2 Answers
0
std::wstring new_wstring(c_string)
where new_wstring is the name of your new wstring, and c_string is the name of your String:
Convert CString to std::wstring
0
Thanks very much. I would like to post the code so that everyone can see the final result. Here is what i did:
String^ str1 = "Your Text";
char* str2 = (char*)(void*)Marshal::StringToHGlobalAnsi(str1);
CString target = str2;
Marshal::FreeHGlobal((IntPtr)str2);
CString str3 = CString(str2);
std::wstring new_wstring(str3);