Home > Software engineering >  MFC Unicode projects about ANSI string assigned to the window associated member variable problem
MFC Unicode projects about ANSI string assigned to the window associated member variable problem

Time:10-09

Don't know the title description is good,

MFC interface a CStatic control
In order to use convenient associated with a value type variable
Cstrings m_text;

This project USES libcurl json third-party libraries such as the output of these libraries is ANSI string (char * type or a string)
So involved in the problem size bytes

The following several methods which are natural
1. Extend the third-party libraries, library returns wchar then directly assigned to m_text
2. In the assignment transformation m_text=CA2W (XXX)
3. Do not use the associated variables, instead of using SetDlgItemTextA (), so without conversion
4. I didn't think of other ways

CodePudding user response:

"" use SetDlgItemTextA (" ")

CodePudding user response:

2. In the assignment transformation m_text=CA2W (XXX)

CodePudding user response:

CA2W (XXX)

You use SetDlgItemTextA (), the accept narrow string, but what is this narrow string coding? Directly to CStatic, can display normal, not gibberish?

CodePudding user response:

The
reference 3 floor luciferisnotsatan response:
CA2W (XXX)

You use SetDlgItemTextA (), the accept narrow string, but what is this narrow string coding? Directly to CStatic, can display normal, not gibberish?


Narrow character is ANSI code

CodePudding user response:

In the underlying use ASCII,
In the upper use unicode,
The middle layer transition

CodePudding user response:

reference 4 floor silenceye response:
Quote: reference luciferisnotsatan reply: 3/f

CA2W (XXX)

You use SetDlgItemTextA (), the accept narrow string, but what is this narrow string coding? Directly to CStatic, can display normal, not gibberish?


Narrow character is ANSI code

Narrow characters can also be a utf-8, etc., under Linux the default is this,
Under Windows, also can use the setlocale to utf-8,
If you are using libcurl for web information, then you have to check the charset part, take a look at what is encoding, and then he will send you the raw data of libcurl to you can in normal showing on the interface of the coding,

CodePudding user response:

refer to 6th floor luciferisnotsatan response:
Quote: refer to 4th floor silenceye response:

Quote: refer to the third floor luciferisnotsatan response:

CA2W (XXX)

You use SetDlgItemTextA (), the accept narrow string, but what is this narrow string coding? Directly to CStatic, can display normal, not gibberish?


Narrow character is ANSI code

Narrow characters can also be a utf-8, etc., under Linux the default is this,
Under Windows, also can use the setlocale to utf-8,
If you are using libcurl for web information, then you have to check the charset part, take a look at what is encoding, and then he will send you the raw data of libcurl to you can in normal showing on the interface of the coding,


Yes this part I was converted to gb2312

CodePudding user response:

MultiByteToWideChar converted to Unicode

CodePudding user response:

Yourself in the place of the interface do coding, decoding and so on transformation to fit program and third-party libraries
  • Related