How to send UNICODE characters to serial port

I am trying to write data in Russian language to the serial (RS-232) port. My display device is already set to that character code page.

But output on the device is not exactly what I require.

My code snippet is like this below
1
2
3
4
5
6
CString pBuffer = L"английский"; //Russian Language
LPBYTE pByte = new BYTE[pBuffer.GetLength() + 1];
memcpy(pByte, (VOID*)LPCTSTR(pBuffer), pBuffer.GetLength());
long nBuffer=pBuffer.GetLength()+1;
DWORD dwWritten=0;
WriteFile(pHandle , pByte, nBuffer ,&dwWritten , NULL);

pHandle is a valid handle.

Waiting for valuable response of yours. Welcome in case of any further information.
closed account (N36fSL3A)
But output on the device is not exactly what I require.

What's your output?
Output is 08
Define " that code page". if your device expects a single-byte extended ASCII encoding such as iso8859-5 or cp1251, your code is not sending that, it is sending a wide string (that is, encoded as UTF-16le on Windows, UTF-32 on more Unicode-aware systems).
Thanks to all the experts for your guidance. With your guidance I am progressing slowly but not as expected... :-)<o:p></o:p>

Now, the problem is that when I pass these Russian Characters from edit control. It is again mis-behaving as faced during starting of this discussion. But the same is working fine if I pass the data statically (hard code).


Code snippet used by me is like this one...

CString pBuffer;
m_text.GetWindowText(pBuffer); \\m_text is edit control variable.
int nBuffer = (pBuffer.GetLength()+1) * sizeof(TCHAR);
DWORD dwWritten=0;
returnval=WriteFile(pHandle , (void*)pBuffer.GetString(), nBuffer ,&dwWritten , NULL);
Thanks in advance !!
Topic archived. No new replies allowed.