Converting ANSI to UNICODE
-
Dear All, I am having problem in converting ANSI to UNICODE but my code is not giving the desired result. Please have a look at the below code and advice me. When I compare the both strings, the strings are not equal after conversion. Please help me. Many thanks in advance.
char szData[2] ;
szData[0] = '♠';
szData[1] = 0;
wchar_t wszData1[] = L"♠";
wchar_t wszData2[2];
MultiByteToWideChar(CP_ACP, 0, szData, -1, wszData2, sizeof(wszData2) / sizeof wchar_t));
if (wcscmp(wszData1, wszData2) == 0)
MessageBox("Strings are equal!");
else
MessageBox("Strings are not equal."); -
Dear All, I am having problem in converting ANSI to UNICODE but my code is not giving the desired result. Please have a look at the below code and advice me. When I compare the both strings, the strings are not equal after conversion. Please help me. Many thanks in advance.
char szData[2] ;
szData[0] = '♠';
szData[1] = 0;
wchar_t wszData1[] = L"♠";
wchar_t wszData2[2];
MultiByteToWideChar(CP_ACP, 0, szData, -1, wszData2, sizeof(wszData2) / sizeof wchar_t));
if (wcscmp(wszData1, wszData2) == 0)
MessageBox("Strings are equal!");
else
MessageBox("Strings are not equal.");bhanu_reddy09 wrote:
szData[0] = '♠';
How could it work?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Dear All, I am having problem in converting ANSI to UNICODE but my code is not giving the desired result. Please have a look at the below code and advice me. When I compare the both strings, the strings are not equal after conversion. Please help me. Many thanks in advance.
char szData[2] ;
szData[0] = '♠';
szData[1] = 0;
wchar_t wszData1[] = L"♠";
wchar_t wszData2[2];
MultiByteToWideChar(CP_ACP, 0, szData, -1, wszData2, sizeof(wszData2) / sizeof wchar_t));
if (wcscmp(wszData1, wszData2) == 0)
MessageBox("Strings are equal!");
else
MessageBox("Strings are not equal.");szData[0] = '♠';
wchar_t wszData1[] = L"♠";These probably aren't doing what you're expecting. You should only have ASCII characters in source code, and use hex escapes for any characters outside the ASCII range. Depending on what that character is, and what your system's code page is, it may not even be possible to store the character in a non-Unicode string.
--Mike-- Dunder-Mifflin, this is Pam.
-
szData[0] = '♠';
wchar_t wszData1[] = L"♠";These probably aren't doing what you're expecting. You should only have ASCII characters in source code, and use hex escapes for any characters outside the ASCII range. Depending on what that character is, and what your system's code page is, it may not even be possible to store the character in a non-Unicode string.
--Mike-- Dunder-Mifflin, this is Pam.
Many thanks for your replies and suggestions. Actually I read a data from the serial device and it is having the ASCII value 6 and the corresponding character for 6 is '♠'. I just give the previous code as an example.
//the actual data will be
szData[0] = 0x06;//from a serial deviceNow, I want to display the corresponding character (received from serial device) for 0x06 in the CEdit. Please advice me.
-
szData[0] = '♠';
wchar_t wszData1[] = L"♠";These probably aren't doing what you're expecting. You should only have ASCII characters in source code, and use hex escapes for any characters outside the ASCII range. Depending on what that character is, and what your system's code page is, it may not even be possible to store the character in a non-Unicode string.
--Mike-- Dunder-Mifflin, this is Pam.
-
This line
szData[0] = '♠';
produces a compiler warning doesn´t it? ♠ is not an ANSI character, afaik. If you use an actual ansi sign like '®' in your code, it works properly. Souldrift
Yes, I got compiler warning but how to change the character 0x06 to Unicode and display properly in the CEdit. Thanks...
-
Yes, I got compiler warning but how to change the character 0x06 to Unicode and display properly in the CEdit. Thanks...
I am not sure if this can be done since 0x06 (actually the first 32 codes) are designated control characters. 0x06 being ACK code for data transmission, I think. Sorry to not be of more help. Souldrift Edit: http://www.handheld-basic.com/documentation/text/page_599.html[^]
-
Many thanks for your replies and suggestions. Actually I read a data from the serial device and it is having the ASCII value 6 and the corresponding character for 6 is '♠'. I just give the previous code as an example.
//the actual data will be
szData[0] = 0x06;//from a serial deviceNow, I want to display the corresponding character (received from serial device) for 0x06 in the CEdit. Please advice me.
bhanu_reddy09 wrote:
szData[0] = 0x06;//from a serial device
This is a
ASCII
control character (ACK
, see [^]), i.e. not printable. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
I am not sure if this can be done since 0x06 (actually the first 32 codes) are designated control characters. 0x06 being ACK code for data transmission, I think. Sorry to not be of more help. Souldrift Edit: http://www.handheld-basic.com/documentation/text/page_599.html[^]
Dear All, I have tried in many possible ways but I cannot display the character ♠. The real problem is that I need to change my entire project to UNICODE but this is not possible for right now. I also tried the below and even not working.
wchar_t display[2];
display[0] = 0x2660;
display[1] = 0;
edit.SetWindowText(display); //This only works when I change the project into UNICODE.Is there any possible way to do simply. Many thanks in advance.