It does not work because you are using
strlen()
to get the length of data to be written but your data is binary and contains NULL bytes. So you are writing only two bytes (0x1B and 0x70) which is an incomplete command. Using
strlen()
won't even work properly when the data does not contain a NULL byte when not appending one as string terminator.
Because you have a
char
array with fixed size, you can use the array size instead:
DWORD dwBytesToWrite = sizeof(cData2);
That will write all five bytes.