I eventually found my bug. My program picks up the COM port name from a ComboBox using ComboBox.Text.c_str() that returns a wchar_t* used as input of CreateFile().
The problem is that the .c_str() method doesn't append a terminal zero at the end of the string.
The fix consisted to write the code to place this zero (from Text.Length() method)
The strange thing is that it worked well in the IDE.
Now my problem is to understand the weird behaviour of .c_str() method