1

i'm creating a simple program in C++ using WinAPI, see this code below:

CreateWindowW(L"STATIC", L"Portão", WS_CHILD | WS_VISIBLE, 10, 10, 100, 20, hwnd, (HMENU)ID_LABEL1, NULL, NULL);

The above code is to create a static control on the main form, the problem is that the 2nd parameter uses a brazilian portuguese word with accent (Portão means Gate), and it give an error, the error is:

C:\CBProjects\ListF\main.cpp|46|error: converting to execution character set: Invalid argument|

i'm using wide character(wchar_t*), but if i replace "Portão" for "Portao" (without accent), it works just fine, Why? How can i solve this?

i'm using Code::Blocks IDE with MinGW Compilator.

FelipeDurar
  • 1,163
  • 9
  • 15
  • That character is probably an extended Unicode character and the compiler refuses it. Look up its Unicode value and specify it in the form of `\x0000` in the string. http://stackoverflow.com/questions/442735/how-can-i-embed-unicode-string-constants-in-a-source-file – xxbbcc Jan 05 '15 at 16:56
  • Try using a compiler that's less alien to Windows development. [Visual Studio Express 2013 for Windows Desktop](http://www.visualstudio.com/en-us/products/visual-studio-express-vs.aspx) is likely a better alternative. – IInspectable Jan 05 '15 at 16:58
  • 1
    @xxbbcc the character is actually `\xe3` (or `\u00e3` in C++11). But that's a workaround, not a real solution. The compiler should be able to convert the source input into the proper Unicode characters. – Mark Ransom Jan 05 '15 at 16:58
  • @MarkRansom I meant my comment as a general solution, for any Unicode character. (I should've written `\u0000` instead of `\x...` but I can't edit the comment anymore.) I don't know that particular character but I don't see this as a workaround - the compiler is not required to recognize random characters during compilation. If the file is not saved as UTF-8, that character may be misinterpreted based on character set of the file. – xxbbcc Jan 05 '15 at 17:05
  • in visual studio it works just fine, but how can i convert the current form to the form of \x0000 in mingw? – FelipeDurar Jan 05 '15 at 17:08
  • What MinGW are you using, vanilla MinGW or MinGW-w64? If the former, switch to the latter and see if your problem still persists. – andlabs Jan 05 '15 at 22:10
  • @IInspectable I do not understand your comment. How is MinGW "alien" to Windows development? It is specifically intended for Windows development and works just fine for it. It does not communicate in a way that Visual Studio likes, but it's *not* Visual Studio so the point is moot. The only problem is that there the original MinGW is the one most people seem to still use despite not having anything from the past 15 years of Windows in it... a fork like MinGW-w64 is much better in this case. – andlabs Jan 05 '15 at 22:13
  • @andlabs: You constantly have to fiddle with it so that it does what Visual Studio does out of the box. MinGW (or Code::Blocks rather) still - in 2015 - defaults to use ANSI APIs instead of the respective Unicode versions. Debugging from Code::Blocks is a pain. There is no proper profiler, no code analyzer for SAL annotations, no AppVerifier support. Nothing. Targeting a platform is more than choosing a compiler. – IInspectable Jan 05 '15 at 23:29
  • Ah, those are valid points indeed... and definitely things to worry about. I'm not skilled enough in x86 compilers to tackle the problem for the benefit of those who prefer to use gcc, though (and I mainly target gcc because it's targeted by the FFI of another programming language I use). – andlabs Jan 06 '15 at 01:02

1 Answers1

0

C++ has notions of source character set and execution character set. Basically source character set is about characters in file with code and execution character set is about internal string representation in compiler. Please look at this stack overflow question for more details on this topic.

Community
  • 1
  • 1
robal
  • 368
  • 2
  • 8