-1

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.

1

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

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); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.