Skip to content

Commit 348b823

Browse files
committed
tech review
1 parent 8ef57d5 commit 348b823

File tree

2 files changed

+2
-57
lines changed

2 files changed

+2
-57
lines changed

docs/build/run-time-library-behavior.md

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,9 @@ The Win32 SDK samples all use the first method. Refer to the Win32 Programmer's
9696
9797
If you wish to use the second method and call the CRT initialization code yourself, instead of using `DllMainCRTStartup()` and `DllMain()`, there are two techniques:
9898
99-
1. If there's no entry function that performs initialization code, specify `_CRT_INIT()` as the entry point of the DLL. Assuming that you've included `NTWIN32.MAK`, which defines `DLLENTRY` as `@12`, add the option to the DLL's link line: `-entry:_CRT_INIT$(DLLENTRY)`.
10099
1. If you do have your own DLL entry point, do the following in the entry point:
101100
102-
a. Use this prototype for `_CRT_INIT()`: `BOOL WINAPI _CRT_INIT(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved);`
101+
a. Use this prototype (defined in `process.h` when `_DECL_DLLMAIN` is defined) for `_CRT_INIT()`: `BOOL WINAPI _CRT_INIT(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved);`
103102
104103
For information on `_CRT_INIT()` return values, see the documentation for `DllEntryPoint`; the same values are returned.
105104
@@ -131,17 +130,6 @@ BOOL WINAPI DllEntryPoint(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved
131130
> [!NOTE]
132131
> This isn't necessary if you're using `DllMain()` and `-entry:_DllMainCRTStartup@12`.
133132
134-
### Using NTWIN32.MAK to simplify the build process
135-
136-
There are macros defined in `NTWIN32.MAK` that can be used to simplify your makefiles and to ensure that they're properly built to avoid conflicts. For this reason, Microsoft highly recommends using `NTWIN32.MAK `and its macros.
137-
138-
For compilation, use: `$(cvarsdll)` for apps/DLLs using CRT in a DLL.
139-
140-
For linking, use one of the following:
141-
142-
- `$(conlibsdll)` for console apps/DLLs using CRT in a DLL
143-
- `$(guilibsdll)` for GUI apps using CRT in a DLL
144-
145133
<a name="initializing-regular-dlls"></a>
146134
147135
### Initialize regular MFC DLLs

docs/c-runtime-library/crt-library-features.md

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "C runtime (CRT) and C++ standard library (STL) lib files"
33
description: "List of Microsoft C runtime and C++ standard library (STL) lib files that you can link against and their associated compiler options and preprocessor directives."
4-
ms.date: "3/5/2021"
4+
ms.date: 02/23/2026
55
ms.topic: "reference"
66
helpviewer_keywords: ["MSVCR71.dll", "libraries [C++], multithreaded", "library files, run-time", "LIBCMT.lib", "LIBCP.lib", "LIBCPMT.lib", "run-time libraries, C", "CRT, release versions", "MSVCP71.dll", "LIBC.lib", "libraries [C++]", "libraries [C++], run-time", "linking [C++], libraries", "STL libraries", "Microsoft standard template libraries"]
77
---
@@ -104,49 +104,6 @@ It's also possible to avoid some of these issues if all of the images in your pr
104104

105105
Be careful if your program passes certain CRT resources across DLL boundaries. Resources such as file handles, locales, and environment variables can cause problems, even when using the same version of the CRT. For more information on the issues involved and how to resolve them, see [Potential errors passing CRT objects across DLL boundaries](./potential-errors-passing-crt-objects-across-dll-boundaries.md).
106106

107-
### Problems with statically linked CRT libraries
108-
109-
There are three forms of the C Run-time library provided with the Win32 SDK:
110-
111-
- `LIBC.LIB` is a statically linked library for single-threaded programs.
112-
- `LIBCMT.LIB` is a statically linked library that supports multithreaded programs.
113-
- `CRTDLL.LIB` is an import library for `CRTDLL.DLL` that also supports multithreaded programs. `CRTDLL.DLL` is part of Windows NT.
114-
115-
Microsoft Visual C++ 32-bit edition contains these three forms as well, however, the CRT in a DLL is named `MSVCRT.LIB`. The DLL is redistributable. Its name depends on the version of VC++ (that is, `MSVCRT10.DLL` or `MSVCRT20.DLL`). Note however, that `MSVCRT10.DLL` is not supported on Win32s, while `CRTDLL.LIB` is supported on Win32s. `MSVCRT20.DLL` comes in two versions: one for Windows NT and the other for Win32s.
116-
117-
If an application that makes C runtime calls links to a DLL that also makes C runtime calls, be aware that if they are both linked with one of the statically linked C runtime libraries, the `.EXE` and DLL will have separate copies of all C runtime functions and global variables. This means that C runtime data cannot be shared between the `.EXE` and the DLL. Some of the problems that can occur are:
118-
119-
- Passing buffered stream handles from the .EXE/DLL to the other module
120-
- Allocating memory with a C runtime call in the .EXE/DLL and reallocating or freeing it in the other module
121-
- Checking or setting the value of the global `errno` variable in the .EXE/DLL and expecting it to be the same in the other module. A related problem is calling `perror()` in the opposite module from where the C runtime error occurred, since `perror()` uses `errno`.
122-
123-
To avoid these problems, link both the `.EXE` and DLL with `CRTDLL.LIB` or `MSVCRT.LIB`, which allows both the `.EXE` and DLL to use the common set of functions and data contained within CRT in a DLL, and C runtime data such as stream handles can then be shared by both the `.EXE` and DLL.
124-
125-
### Mixing library types
126-
127-
You can link your DLL with `CRTDLL.LIB`/`MSVCRT.LIB` regardless of what your `.EXE` is linked with if you avoid mixing CRT data structures and passing CRT file handles or CRT `FILE*` pointers to other modules.
128-
129-
When mixing library types adhere to the following:
130-
131-
- CRT file handles may only be operated on by the CRT module that created them.
132-
- CRT `FILE*` pointers may only be operated on by the CRT module that created them.
133-
- Memory allocated with the CRT function `malloc()` may only be freed or reallocated by the CRT module that allocated it.
134-
135-
To illustrate this, consider the following example:
136-
137-
- `.EXE` is linked with `MSVCRT.LIB`
138-
- DLL A is linked with `LIBCMT.LIB`
139-
- DLL B is linked with `CRTDLL.LIB`
140-
141-
If the `.EXE` creates a CRT file handle using `_create()` or `_open()`, this file handle may only be passed to `_lseek()`, `_read()`, `_write()`, `_close()`, etc. in the `.EXE` file. Do not pass this CRT file handle to either DLL. Do not pass a CRT file handle obtained from either DLL to the other DLL or to the `.EXE`.
142-
143-
If DLL A allocates a block of memory with `malloc()`, only DLL A may call `free()`, `_expand()`, or `realloc()` to operate on that block. You cannot call `malloc()` from DLL A and try to free that block from the `.EXE` or from DLL B.
144-
145-
> [!NOTE]
146-
> If all three modules were linked with `CRTDLL.LIB` or all three were linked with `MSVCRT.LIB`, these restrictions would not apply.
147-
148-
When linking DLLs with `LIBC.LIB`, be aware that if there is a possibility that such a DLL will be called by a multithreaded program, the DLL will not support multiple threads running in the DLL at the same time, which can cause major problems. If there is a possibility that the DLL will be called by multithreaded programs, be sure to link it with one of the libraries that support multithreaded programs (`LIBCMT.LIB`, `CRTDLL.LIB`, or `MSVCRT.LIB`).
149-
150107
## See also
151108

152109
[C runtime library reference](./c-run-time-library-reference.md)\

0 commit comments

Comments
 (0)