Reputation: 904
I am trying to drwa some text using GDI on c++
It happens that I have a class that has a method to return the status and I want to draw it
The status is a std::string!
So here is what I have so far:
RECT status = RECT();
status.left = rcClient.right-200;
status.left = rcClient.left;
status.top = rcClient.top;
status.bottom = rcClient.bottom;
DrawTextW(hdc, game->GetStatus().c_str(), 1, status, 0);
The errors I have are:
error C2664: 'FormatMessageW' : cannot convert parameter 5 from 'LPWSTR' to 'char *'687 damas error C2664: 'FormatMessageW' : cannot convert parameter 5 from 'wchar_t *' to 'char *'damas error C2664: 'DrawTextW' : cannot convert parameter 2 from 'const char *' to 'LPCWSTR'
I can't find a way to solve this... can someone help me out?
Upvotes: 3
Views: 1731
Reputation: 48038
A std::string
uses chars, but DrawTextW
is expecting wide chars (WCHAR
s, which are identical to wchar_t
s).
You can call DrawTextA
explicitly with your string. It will make a copy of your string using wide characters and pass it on to DrawTextW
.
DrawTextA(hdc, game->GetStatus().c_str(), 1, &status, 0);
(Also note that it takes a pointer to the RECT
, so you need the &
as well.)
Upvotes: 2