Arduino and C++ Serial communication
BOOL retVal = WriteFile(SP-&gt;hSerial, &amp;value, sizeof(value), &amp;bytesSend, NULL);


You're writing sizeof(value) bytes to the Arduino. Since value is an int, which is typically 4 bytes in size for PC compilers/processors, when you send 20, what actually gets to the Arduino is 0x00000014. Your processor is apparently little-endian so the order of bytes sent is 0x14, 0x00, 0x00, 0x00. 

You're reading a single byte in every loop() iteration. Your first sketch worked because you didn't provide any else clause for unrecognized bytes. The Arduino merely ignored those leading zeros. However, your second sketch handled unknown bytes (such as 0x00) by printing gggg. So what you get for every value you send to the Arduino is exactly what you'd expect and what you see in your shell -- the result you want (openn == 0x14), followed by 3 gibberish results (because of the leading zero bytes). 

You can fix it by either declaring value as a uint8_t in your CPP code (after including stdint.h) or only reading chunks of 4 bytes on the Arduino and then parsing what you get. The former solution seems more reasonable/reliable.