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 of strcpy.
  • 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), use sizeof(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:

  1. 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.
  2. Kano, Nadine Developing International Software for Windows 95 and Windows NT: a handbook for software design, Microsoft Press, Redmond, WA, 1995.
  3. Microsoft Support Knowledge Base articles (See related links.)
  4. MSDN Library (See related links.)