Home > Software engineering >  MFC in the file transfer (MFC own CFtpConnection class), under the Linux GB2312 utf-8, an odd number
MFC in the file transfer (MFC own CFtpConnection class), under the Linux GB2312 utf-8, an odd number

Time:10-30

Char * CSelectFile: : GB2312ToUtf8 (const char * gb2312)
{
Int len=MultiByteToWideChar (gb2312 CP_ACP, 0, 1, NULL, 0).
Would be * WSTR=new would [len + 1];
Memset (WSTR, 0, len + 1);
MultiByteToWideChar (gb2312 CP_ACP, 0, 1, WSTR, len);
Len=WideCharToMultiByte (WSTR CP_UTF8, 0, 1, NULL, 0, NULL, NULL);
Char * tempStr=new char [len + 1];
Memset (tempStr, 0, len + 1);
WideCharToMultiByte (WSTR CP_UTF8, 0, 1, tempStr, len, NULL, NULL);
If (WSTR) delete [] WSTR;
Return tempStr;
}

CodePudding user response:

 
.
Would be * WSTR=new would [len + 1];
Memset (WSTR, 0, len + 1);//there's a problem, the length of the memset is byte, WSTR would be double byte need take 2, memset (WSTR, 0, sizeof (would) * (len + 1));
.
Char * tempStr=new char [len + 1];
Memset (tempStr, 0, len + 1);//there is no problem, because tempStr is char single-byte
.


Can changed the above trouble spots, and then send it again to Linux on the right,

CodePudding user response:

reference 1st floor ArcRain response:
 
.
Would be * WSTR=new would [len + 1];
Memset (WSTR, 0, len + 1);//there's a problem, the length of the memset is byte, WSTR would be double byte need take 2, memset (WSTR, 0, sizeof (would) * (len + 1));
.
Char * tempStr=new char [len + 1];
Memset (tempStr, 0, len + 1);//there is no problem, because tempStr is char single-byte
.


Can be changed the problematic place first, and then send it again to Linux on the right,

This problem, notice, changed, try once, is still the same, there is the code

CodePudding user response:

Would be * WSTR=new would [len + 1];
Memset (WSTR, 0, len + 1);
Utf-8 is usually 3 bytes

CodePudding user response:

Some years ago someone met you this question, you can try: https://blog.csdn.net/lizhq007/article/details/8233515

CodePudding user response:

reference schlafenhamster reply: 3/f
would be * WSTR=new would [len + 1];
Memset (WSTR, 0, len + 1);
Utf-8 is usually 3 bytes

Uh huh, can you tell me how to modify? Instead of 3?

CodePudding user response:

Put a little more allowance?

CodePudding user response:

reference 4 floor ArcRain response:
several years ago someone met you this question, you can try: https://blog.csdn.net/lizhq007/article/details/8233515
uh-huh, I saw this post, this one is to, but not a go directly to the words, I don't know where is the root cause

CodePudding user response:

refer to 7th floor schlafenhamster response:
can't put a little more allowance?

I can't, I expanded, and the results are the same

CodePudding user response:

To set breakpoints, see first converted UNICODE is correct?
Try CP_ACP code page 936,
MultiByteToWideChar (/* CP_ACP */936,

CodePudding user response:

The
references to the tenth floor zgl7903 response:
set breakpoints, look at the converted UNICODE is correct?
Try CP_ACP code page 936,
MultiByteToWideChar (/* CP_ACP */936,

The converted correctly, with 936 try