0

I am using ReadFile to read a pipe that has output from a command I run. However my understanding is ReadFile only reads the bytes and doesn't care if they are WCHAR or CHAR. It just reads the bytes.

I am trying to understand how would I go about determining if the bytes it reads from the buffer are WCHAR or CHAR so I can print properly. These bytes will be sent back to a Python server that will print.

Govind Parmar
  • 20,656
  • 7
  • 53
  • 85
Doritos
  • 403
  • 3
  • 16
  • 1
    AFAIK UNICODE support in `cmd.exe` is still broken and just a PITA. – Swordfish Feb 19 '19 at 16:29
  • Do you know of any other way to run CMD.EXE commands that support UNICODE? I was originally doing a wpopen but that spawns a cmd.exe window. Was switching to CreateProcess so I can hide it. – Doritos Feb 19 '19 at 16:34
  • `_wpopen()` doesn't start a different command interpreter. It is just a version of `_popen()` that accepts UNICODE strings as command line. Do you actually know that the tools you call output UNICODE characters? – Swordfish Feb 19 '19 at 16:38
  • A dir command could output Unicode. – Doritos Feb 19 '19 at 16:39
  • I don't think so. [Windows Console and Double/Multi Byte Character Set](https://www.curlybrace.com/words/2014/10/03/windows-console-and-doublemulti-byte-character-set/) – Swordfish Feb 19 '19 at 16:41
  • Oh that is interesting. – Doritos Feb 19 '19 at 16:58

1 Answers1

1

You are basically reading from a stream, be it pipe of file or a in-memory buffer. So what you usually obtain is a pointer to a buffer in your program. It is up to your app logic to determine how to treat those bytes - as CHAR or as WCHAR, i.e. UTF-8 or UTF-16. Keep in mind that a buffer of CHAR elements can be cast to one of WCHAR and vice-versa.

I could suggest to use WHCAR to make your app UTF-16 compatible. Youc an refer to this question In C++ when to use WCHAR and when to use CHAR

vasile_t
  • 372
  • 2
  • 12