The problem is that to convert to a wide string, instead of converting, I replaced this part of the code by opening the port as follows:
wchar_t wcPort[64]; size_t convertedChars = 0; mbstowcs_s(&convertedChars, wcPort, strlen(portName), portName, _TRUNCATE); this->hSerial = CreateFile(wcPort, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
Or, as Ben Voigt pointed out in a comment, you can also name the CreateFileA option so that Windows does the conversion for you.
source share