Friday, December 20, 2013

Converting WCHAR* to CHAR*

size_t origsize = wcslen(wszName) + 1;
       size_t convertedChars = 0;
       const size_t newsize = origsize * 2;
       char strConcat[] = ".BLC"; // the same file name plus different extension name
       size_t strConcatsize = (strlen(strConcat) + 1) * 2;

       char *nstring = new char[newsize + strConcatsize];

       wcstombs_s(&convertedChars, nstring, newsize, wszName, _TRUNCATE);

       strcat_s((char*)nstring, newsize + strConcatsize, ( char*)strConcat);

0 Comments:

Post a Comment

<< Home