14.5.1 Using Windows C Libraries

You can use the Windows C run-time libraries with CL version 5.1 and later. The Windows-specific versions of the C run-time libraries are adapted for the Windows environment. The Windows prolog and epilog code have been added to all C run-time functions that require them. This prevents problems associated with code-segment movement in low-memory situations. Many C run-time functions have been rewritten to avoid the assumption that the contents of the DS register equal the contents of the SS register, which is not true for Windows dynamic-link libraries. For information about calling C run-time library functions from a dynamic-link library (with DS equal to SS), see Chapter 20, “Dynamic-Link Libraries.”

The SDK contains two sets of run-time libraries. One set is linked with Windows applications, and the other set is linked with Windows dynamic-link libraries. These libraries contain application- or DLL-startup code in addition to C run-time functions, including memory-model-dependent replacement functions. As a result, the SDK requires only one import library, LIBW.LIB. This import library is memory-model independent.

The install command in version 3.1 of the SDK always names the Windows versions of the C run-time libraries according to the following naming convention:

{S|M|C|L}{LIB|DLL}C[E]W.LIB

S, M, C, and L represent small, medium, compact, or large memory model libraries, respectively. LIB and DLL indicate libraries intended to be linked with application and DLL modules, respectively. E indicates the emulated math library. Because of this naming convention, you must explicitly name the Windows version of the C run-time library when linking your application. The following shows an example of using the link command to link an application module to a Windows C run-time library:

link generic, , , /nod slibcew libw, generic.def

The /nod (no default directory search) option is recommended to prevent link from searching for a C run-time function in an MS-DOS version of the C run-time library if it does not find the function in the Windows version of the library. When you use this option, your application will not compile if you inadvertently called a C run-time function that is not supported by the Windows C run-time libraries.

The SDK also contains Windows-specific versions of the C run-time header files. These files help you detect during compilation whether you have inadvertently called a C run-time function that is not supported in the Windows environment. To perform this check, add the following directive to your module header file prior to any #include directives for the C run-time header files:

#define _WINDOWS

The set of C run-time functions that support calling from Windows applications includes a subset of functions that support calling from Windows dynamic-link libraries. The Windows-specific header files identify this subset. If you are creating a dynamic-link library, you should include both of these directives before any #include directives for the C run-time header files, as shown in the following example:

#define _WINDOWS
#define _WINDLL