93.16 Workarounds

If your favorite function has not been exported in a Unicode version, you can often use a very simple workaround:

Use an equivalent function that does have a Unicode version. For example, use CreateFile instead of OpenFile

Map characters to/from 8-bits around the function call. For example, the number formatting functions atoi and itoa understand only the digits 0–9. Normally, mapping Unicode to 8-bit characters could cause loss of data; but in this case, you get the correct result by changing the following statements:

char str[4];

num = atoi(str);

to a type-independent:

TCHAR str[4];

CHAR strTmp[SIZE];

#ifdef UNICODE

wctomb(strTmp, str, sizeof(strTmp));

num = atoi(strTmp);

#else

num = atoi(str);

#endif

where wctomb is the C runtime function to translate Unicode to ASCII. The atoi function stops at any character that is not a digit.