ANSI and Unicode Strings

All 16-bit applications use ANSI strings. 32-bit applications can use either ANSI or Unicode strings. ANSI applications store strings as unsigned char, each byte containing a different character. Unicode applications store strings as unsigned short, each short integer value containing a different character.

To specify ANSI, declare the following statement in your project settings:

#define OLE2ANSI

To specify Unicode, declare the following statement in your project settings:

#define _UNICODE

The advantage of using Unicode in your applications is that it enables you to easily localize your application into languages such as Chinese, where two bytes are required to store characters. ANSI applications require special double-byte character set (DBCS) functions to be localized into such languages.

The advantage of using ANSI strings is that the Windows system calls take ANSI strings in Windows 95. In contrast, if you use Unicode strings, you must convert them to ANSI strings before calling these functions.

You can compile your application in ANSI or Unicode by using the _T macro. The _T macro is defined by Visual C++ and is used to wrap all string literals. In ANSI, this macro does nothing. In Unicode, it appends the L keyword to inform the compiler that the literal is to be read in as Unicode.

void OpenADatabase()
	{
	CdbDBEngine dben;
	CdbDatabase db;

	db = dben.OpenDatabase(_T("MyDB.MDB"));
	}

The preceding code will compile for both ANSI and Unicode applications.