How to: Convert Between Char* to wchar*

To convert between a small char to a wide char, I would showing two types with a very little variation. You can use either to take away warnings between these conversion:

Method 1:
char *nexToken;
char *strMy = strtok_s( strM, %,&nextToken);
while (strMy != NULL)
{
wchar_t *lpfile;
lpfile = NULL;
mbstowcs(lpfile,strMy,100);
}
Method 2:
char *nexToken;
char *strMy = strtok( strM, %);
while (strMy != NULL)
{
wchar_t *lpfile;
lpfile = NULL;
mbstowcs(lpfile,strMy,100);
}
do not use secure tokenizer over here
Method 3 (referred to MSDN here):
char *strMy;
size_t origsize = strlen(strMy) + 1;
const size_t newsize = 100;
size_t convertedChars = 0;
wchar_t wcstring[newsize];
mbstowcs_s(&convertedChars, wcstring, origsize, strMy, _TRUNCATE);
//wcscat_s(wcstring, L (wchar_t *));
wcout << &&&<

These conversion are helpful when you try to call system builtin functions in VStudio

Leave a Reply

Your email address will not be published. Required fields are marked *