# HG changeset patch # User Jeandet Alexis # Date 2014-03-26 09:42:15 # Node ID 84df714fc1b4a60453672ce5dc77d62512bf7c6b # Parent a846d982cee0f444b7b19fe710cf20a416608572 An other char to wchar conv 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");