0

I'm sending an user-generated string from my program into a C++ DLL function I'm making. It works fine, until I send a string like "åäö". My function looks something like this:

export void showMessage(char* str) {
    MessageBox(NULL, str, "DLL says", MB_OK);
}

When "åäö" is sent from the program, a message with "åäö" popups up. How do I convert it into "åäö"? What library is needed? I'm using Code::Blocks for the DLL.

david
  • 292
  • 5
  • 20
  • 1
    There's no reason to make `str` a `char *` instead of a `const char *`. It's functions like this that disallow doing `str.c_str()` as an argument for no good reason. And you should be using the wide version of `MessageBox` if you want Unicode characters. – chris Jun 06 '14 at 19:58
  • 3
    That is indeed utf-8. Not the system code page that MessageBoxA() or the utf-16 string that MessageBoxW() needs. Use MultiByteToWideString() to make the latter work. – Hans Passant Jun 06 '14 at 20:02

1 Answers1

2

The characters you are using appear to be in the extended ASCII table (value greater than 127), and will depend on the code page you are using, which is a less than portable approach, since the system running your code needs to make environment changes outside of the program itself.

Instead of using MessageBox, use the Unicode enabled version, MessageBoxW, and look up the Unicode encodings for the characters you specified.

References


  1. Unicode Versions and ANSI Versions of Functions, Accessed 2014-06-06, <http://zone.ni.com/reference/en-XX/help/371361J-01/lvexcodeconcepts/unicode_ansi_version_functs/>
  2. ASCII Table Lookup, Accessed 2014-06-06, <http://www.theasciicode.com.ar/extended-ascii-code/capital-letter-a-ring-uppercase-ascii-code-143.html>
  3. Unicode Lookup, Accessed 2014-06-06, <http://unicodelookup.com/>
Cloud
  • 18,753
  • 15
  • 79
  • 153