Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Displaying text previously get by winapi [crash]  (Read 1327 times)

0 Members and 1 Guest are viewing this topic.

Szustarol

  • Newbie
  • *
  • Posts: 19
    • View Profile
Displaying text previously get by winapi [crash]
« 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?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Displaying text previously get by winapi [crash]
« Reply #1 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);
Laurent Gomila - SFML developer

Szustarol

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Displaying text previously get by winapi [crash]
« Reply #2 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.

 

anything