SFML community forums

Help => General => Topic started by: Szustarol on June 21, 2016, 12:16:38 pm

Title: Displaying text previously get by winapi [crash]
Post by: Szustarol on June 21, 2016, 12:16:38 pm
Hi i get a text from text field to wstring (text contains polish chars)
GetWindowTextW(g_name, (LPWSTR)g_namestr.c_str(), GetWindowTextLength(g_name) + 1);

sadly, this:
                  text.setString(g_namestr);
or this:
                  text.setString(g_namestr.c_str());

causes the app to crash.
I need it to be wide string (displaying polish chars is a must), i know i can manually set a wide string to text by
text.setString(L"Wide text");
but how do i do it with predefined text string?
Title: Re: Displaying text previously get by winapi [crash]
Post by: Laurent on June 21, 2016, 12:30:05 pm
Quote
GetWindowTextW(g_name, (LPWSTR)g_namestr.c_str(), GetWindowTextLength(g_name) + 1);
c_str() is not a valid way to have write access to the string content. The compiler would have told you without the ugly C cast in front of it.

What you must do is (quick and dirty version):
wchat_t buffer[1024];
GetWindowTextW(g_name, buffer, 1024);
Title: Re: Displaying text previously get by winapi [crash]
Post by: Szustarol on June 21, 2016, 12:35:54 pm
thanks a lot!
it works
i kinda noticed c_str() is the problem here but i hat no idea how to get through it without using this method.