Converting Method Samples to Unicode

The DAO method samples are designed to illustrate the DAO methods in a simple, yet effective manner. Thus, the samples are written as ANSI console applications because they are the easiest type of application to read and require the least prior knowledge to understand.

The samples should also work as Unicode console applications, but they will require modification.

Note The samples are already partially modified for your convenience. But why is there any support at all for Unicode when the samples are designed for ANSI builds? Frankly, to encourage you to write your future applications so they will be able to handle ANSI or Unicode.

To convert the method samples to Unicode

  1. Convert literal strings to Unicode. All literal text strings should be enclosed in the _T( string ) macro. In an ANSI build, this macro has no effect on string. In a Unicode build, string is prefixed with 'L' which declares it to be Unicode.

  2. Change declarations of char to TCHAR. In an ANSI build, TCHAR is defined to be char; in a Unicode build, it is defined to be wchar_t.

  3. Change printf functions to _tprintf. In an ANSI build, _tprintf is defined to be printf; in a Unicode build, it is define to be wprintf. In an ANSI build, the printf formatting argument for an ANSI string is "%s", and the argument for a Unicode string is "%S". In a Unicode build, this rule is reversed: ANSI strings are formatted with "%S" and Unicode strings are formatted with "%s". Adjust formatting arguments accordingly.

  4. Change _cgets, sscanf, and associated logic to use swscanf, and/or getws.

These samples are the Microsoft Visual C++ equivalents of the Visual Basic DAO samples, so it was necessary to map Microsoft Visual Basic functionality to equivalent Microsoft Visual C++ constructs. However, certain constructs in the ANSI build (such as _cgets) have no Unicode equivalent. In this case you must change the program logic to get the desired result.