Write a generic Windows Application Package application
Generic Windows Application Package applications allow maximum portability because the same source code can be compiled for OEM, ANSI, and Unicode.
Generic applications are built by specifying different preprocessor definitions, and by using the generic version of the APIs (the ones without the "A" or "W" suffixes). Following is a short list of guidelines for writing a generic application:
- Instead of including the usual <string.h> for manipulating strings, include <TCHAR.H>.
- Use generic data types for characters and strings. Use 'TCHAR' for 'char' in your source code.
- Use the _TEXT macro for literal characters and strings. For example,
TCHAR A[]=_TEXT("A Generic String")
. - Use generic string manipulation functions. For example, use
_tcscpy
instead ofstrcpy
. - Be especially careful when using the 'sizeof' operator - always
remember that a Unicode character occupies two bytes. When determining
the number of characters in a generic TCHAR array A, instead of the
simple
sizeof(A)
, usesizeof(A)/sizeof(TCHAR)
. - Use proper preprocessor definitions for compilation. When compiling
your source for Unicode in Visual C++, you should also use the preprocessor
definitions
UNICODE
and_UNICODE
. Instead of defining_UNICODE
in the MAK file, you may want to define it at the beginning of your source code as:#ifdef UNICODE #define _UNICODE #endif
For a complete description of these guidelines, see the following resources:
- Richter, J. Advanced Windows: The Developer's Guide to the Win32 API for Windows NT 3.5 and Windows 95, Microsoft Press, Redmond, WA, 1995.
- Kano, Nadine Developing International Software for Windows 95 and Windows NT: a handbook for software design, Microsoft Press, Redmond, WA, 1995.
- Microsoft Support Knowledge Base articles (See related links.)
- MSDN Library (See related links.)