diff --git a/src/RS232_win.c b/src/RS232_win.c --- a/src/RS232_win.c +++ b/src/RS232_win.c @@ -119,11 +119,12 @@ rs232port_t rs232open(char* psPortName) { rs232port_t fd; /* Char to Wchar conversion*/ - int len = strlen(psPortName),convlen; - wchar_t *wcstr = (wchar_t *)malloc((len*sizeof(wchar_t)) + 10); - mbstowcs_s(&convlen,wcstr,len, psPortName,len); + int neededSize = MultiByteToWideChar(CP_ACP, 0, psPortName, -1, 0, 0); + wchar_t* wcstr = new wchar_t[neededSize]; + MultiByteToWideChar(CP_ACP, 0, charString, -1, wcstr, neededSize); fd = (rs232port_t)CreateFile(wcstr,GENERIC_READ | GENERIC_WRITE,0,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0); - #ifdef RS232_debug + delete wcstr; +#ifdef RS232_debug if(fd==(rs232port_t)INVALID_HANDLE_VALUE) { printf("can't open Port\n");