You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When you create `BSTR`s and pass them between COM objects, you must take care in treating the memory they use in order to avoid memory leaks. When a `BSTR` stays within an interface, you must free its memory when you are done with it. However, when a `BSTR` passes out of an interface, the receiving object takes responsibility for its memory management.
12
12
@@ -31,6 +31,6 @@ In general, the rules for allocating and releasing memory allocated for `BSTR`s
Copy file name to clipboardExpand all lines: docs/atl-mfc-shared/unicode-and-multibyte-character-set-mbcs-support.md
+12-12Lines changed: 12 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,7 @@ Microsoft has recommended the MFC Unicode libraries for all new development, and
16
16
17
17
## MFC Support for Unicode Strings
18
18
19
-
The entire MFC class library is conditionally enabled for Unicode characters and strings stored in wide characters as UTF-16. In particular, class [CString](../atl-mfc-shared/reference/cstringt-class.md) is Unicode-enabled.
19
+
The entire MFC class library is conditionally enabled for Unicode characters and strings stored in wide characters as UTF-16. In particular, class [`CString`](../atl-mfc-shared/reference/cstringt-class.md) is Unicode-enabled.
20
20
21
21
These library, debugger, and DLL files are used to support Unicode in MFC:
22
22
@@ -51,23 +51,23 @@ These library, debugger, and DLL files are used to support Unicode in MFC:
51
51
52
52
(*version* represents the version number of the file; for example, '140' means version 14.0.)
53
53
54
-
`CString` is based on the TCHAR data type. If the symbol _UNICODE is defined for a build of your program, TCHAR is defined as type **`wchar_t`**, a 16-bit character encoding type. Otherwise, TCHAR is defined as **`char`**, the normal 8-bit character encoding. Therefore, under Unicode, a `CString` is composed of 16-bit characters. Without Unicode, it is composed of characters of type **`char`**.
54
+
`CString` is based on the `TCHAR` data type. If the symbol `_UNICODE` is defined for a build of your program, `TCHAR` is defined as type **`wchar_t`**, a 16-bit character encoding type. Otherwise, `TCHAR` is defined as **`char`**, the normal 8-bit character encoding. Therefore, under Unicode, a `CString` is composed of 16-bit characters. Without Unicode, it is composed of characters of type **`char`**.
55
55
56
56
To complete Unicode programming of your application, you must also:
57
57
58
-
- Use the _T macro to conditionally code literal strings to be portable to Unicode.
58
+
- Use the `_T` macro to conditionally code literal strings to be portable to Unicode.
59
59
60
60
- When you pass strings, pay attention to whether function arguments require a length in characters or a length in bytes. The difference is important if you are using Unicode strings.
61
61
62
62
- Use portable versions of the C run-time string-handling functions.
63
63
64
64
- Use the following data types for characters and character pointers:
65
65
66
-
- Use TCHAR where you would use **`char`**.
66
+
- Use `TCHAR` where you would use **`char`**.
67
67
68
-
- Use LPTSTR where you would use **`char`**<strong>\*</strong>.
68
+
- Use `LPTSTR` where you would use **`char`**<strong>\*</strong>.
69
69
70
-
- Use LPCTSTR where you would use **`const char`**<strong>\*</strong>. `CString` provides the operator LPCTSTR to convert between `CString` and LPCTSTR.
70
+
- Use `LPCTSTR` where you would use **`const char`**<strong>\*</strong>. `CString` provides the operator `LPCTSTR` to convert between `CString` and `LPCTSTR`.
71
71
72
72
`CString` also supplies Unicode-aware constructors, assignment operators, and comparison operators.
73
73
@@ -79,27 +79,27 @@ The class library is also enabled for multibyte character sets, but only for dou
79
79
80
80
In a multibyte character set, a character can be one or two bytes wide. If it is two bytes wide, its first byte is a special "lead byte" that is chosen from a particular range, depending on which code page is in use. Taken together, the lead and "trail bytes" specify a unique character encoding.
81
81
82
-
If the symbol _MBCS is defined for a build of your program, type TCHAR, on which `CString` is based, maps to **`char`**. It is up to you to determine which bytes in a `CString` are lead bytes and which are trail bytes. The C run-time library supplies functions to help you determine this.
82
+
If the symbol `_MBCS` is defined for a build of your program, type `TCHAR`, on which `CString` is based, maps to **`char`**. It is up to you to determine which bytes in a `CString` are lead bytes and which are trail bytes. The C run-time library supplies functions to help you determine this.
83
83
84
84
Under DBCS, a given string can contain all single-byte ANSI characters, all double-byte characters, or a combination of the two. These possibilities require special care in parsing strings. This includes `CString` objects.
85
85
86
86
> [!NOTE]
87
87
> Unicode string serialization in MFC can read both Unicode and MBCS strings regardless of which version of the application that you are running. Your data files are portable between Unicode and MBCS versions of your program.
88
88
89
-
`CString` member functions use special "generic text" versions of the C run-time functions they call, or they use Unicode-aware functions. Therefore, for example, if a `CString` function would typically call `strcmp`, it calls the corresponding generic-text function `_tcscmp` instead. Depending on how the symbols _MBCS and _UNICODE are defined, `_tcscmp` maps as follows:
89
+
`CString` member functions use special "generic text" versions of the C run-time functions they call, or they use Unicode-aware functions. Therefore, for example, if a `CString` function would typically call `strcmp`, it calls the corresponding generic-text function `_tcscmp` instead. Depending on how the symbols `_MBCS` and `_UNICODE` are defined, `_tcscmp` maps as follows:
90
90
91
91
|Symbols|Function|
92
92
|-|-|
93
-
|_MBCS defined|`_mbscmp`|
94
-
|_UNICODE defined|`wcscmp`|
93
+
|`_MBCS` defined|`_mbscmp`|
94
+
|`_UNICODE` defined|`wcscmp`|
95
95
|Neither symbol defined|`strcmp`|
96
96
97
97
> [!NOTE]
98
-
> The symbols _MBCS and _UNICODE are mutually exclusive.
98
+
> The symbols `_MBCS` and `_UNICODE` are mutually exclusive.
99
99
100
100
Generic-text function mappings for all of the run-time string-handling routines are discussed in [C Run-Time Library Reference](../c-runtime-library/c-run-time-library-reference.md). For a list, see [Internationalization](../c-runtime-library/internationalization.md).
101
101
102
-
Similarly, `CString` methods are implemented by using generic data type mappings. To enable both MBCS and Unicode, MFC uses TCHAR for **`char`** or **`wchar_t`**, LPTSTR for **`char`**<strong>\*</strong> or `wchar_t*`, and LPCTSTR for **const char**<strong>\*</strong> or `const wchar_t*`. These ensure the correct mappings for either MBCS or Unicode.
102
+
Similarly, `CString` methods are implemented by using generic data type mappings. To enable both MBCS and Unicode, MFC uses `TCHAR` for **`char`** or **`wchar_t`**, `LPTSTR` for **`char`**<strong>\*</strong> or `wchar_t*`, and `LPCTSTR` for **`const char`**<strong>\*</strong> or `const wchar_t*`. These ensure the correct mappings for either MBCS or Unicode.
The **`errno`** constants are values assigned to [`errno`](../c-runtime-library/errno-doserrno-sys-errlist-and-sys-nerr.md) in the event of various error conditions.
19
19
20
-
ERRNO.H contains the definitions of the **`errno`** values. However, not all the definitions given in ERRNO.H are used in 32-bit Windows operating systems. Some of the values in ERRNO.H are present to maintain compatibility with the UNIX family of operating systems. The **`errno`** values in a 32-bit Windows operating system are a subset of the values for **`errno`** in UNIX systems.
20
+
`ERRNO.H` contains the definitions of the **`errno`** values. However, not all the definitions given in `ERRNO.H` are used in 32-bit Windows operating systems. Some of the values in `ERRNO.H` are present to maintain compatibility with the UNIX family of operating systems. The **`errno`** values in a 32-bit Windows operating system are a subset of the values for **`errno`** in UNIX systems.
21
21
22
22
The **`errno`** value isn't necessarily the same as the actual error code returned by a system call from the Windows operating system. To access the actual operating system error code, use the [`_doserrno`](../c-runtime-library/errno-doserrno-sys-errlist-and-sys-nerr.md) variable, which contains this value.
23
23
@@ -37,7 +37,7 @@ The following **`errno`** values are supported:
37
37
|`EEXIST`| Files exists. An attempt has been made to create a file that already exists. For example, the `_O_CREAT` and `_O_EXCL` flags are specified in an `_open` call, but the named file already exists. | 17 |
38
38
|`EFAULT`| Bad address. | 14 |
39
39
|`EFBIG`| File too large. | 27 |
40
-
|`EILSEQ`| Illegal sequence of bytes (for example, in an MBCS string). | 42 |
40
+
|`EILSEQ`| Illegal sequence of bytes (for example, in an `MBCS` string). | 42 |
41
41
|`EINTR`| Interrupted function. | 4 |
42
42
|`EINVAL`| Invalid argument. An invalid value was given for one of the arguments to a function. For example, the value given for the origin when positioning a file pointer (by means of a call to `fseek`) is before the beginning of the file. | 22 |
helpviewer_keywords: ["error codes, printing", "sys_errlist global variable", "doserrno global variable", "errno global variable", "_doserrno global variable", "_sys_errlist global variable", "_sys_nerr global variable", "sys_nerr global variable"]
11
11
ms.assetid: adbec641-6d91-4e19-8398-9a34046bd369
12
12
---
13
-
# errno, _doserrno, _sys_errlist, and _sys_nerr
13
+
# `errno`, `_doserrno`, `_sys_errlist`, and `_sys_nerr`
14
14
15
15
Global macros that hold error codes that are set during program execution, and string equivalents of the error codes for display.
16
16
@@ -29,35 +29,35 @@ Both `errno` and `_doserrno` are set to 0 by the runtime during program startup.
29
29
30
30
On an error, `errno` is not necessarily set to the same value as the error code returned by a system call. For I/O operations, `_doserrno` stores the operating-system error-code equivalents of `errno` codes. For most non-I/O operations, the value of `_doserrno` is not set.
31
31
32
-
Each `errno` value is associated with an error message in `_sys_errlist` that can be printed by using one of the [perror](../c-runtime-library/reference/perror-wperror.md) functions, or stored in a string by using one of the [strerror](../c-runtime-library/reference/strerror-strerror-wcserror-wcserror.md) or [strerror_s](../c-runtime-library/reference/strerror-s-strerror-s-wcserror-s-wcserror-s.md) functions. The `perror` and `strerror` functions use the `_sys_errlist` array and `_sys_nerr`—the number of elements in `_sys_errlist`—to process error information. Direct access to `_sys_errlist` and `_sys_nerr` is deprecated for code-security reasons. We recommend that you use the more secure, functional versions instead of the global macros, as shown here:
32
+
Each `errno` value is associated with an error message in `_sys_errlist` that can be printed by using one of the [`perror`](../c-runtime-library/reference/perror-wperror.md) functions, or stored in a string by using one of the [`strerror`](../c-runtime-library/reference/strerror-strerror-wcserror-wcserror.md) or [`strerror_s`](../c-runtime-library/reference/strerror-s-strerror-s-wcserror-s-wcserror-s.md) functions. The `perror` and `strerror` functions use the `_sys_errlist` array and `_sys_nerr`—the number of elements in `_sys_errlist`—to process error information. Direct access to `_sys_errlist` and `_sys_nerr` is deprecated for code-security reasons. We recommend that you use the more secure, functional versions instead of the global macros, as shown here:
Library math routines set `errno` by calling [_matherr](../c-runtime-library/reference/matherr.md). To handle math errors differently, write your own routine according to the `_matherr` reference description and name it `_matherr`.
40
+
Library math routines set `errno` by calling [`_matherr`](../c-runtime-library/reference/matherr.md). To handle math errors differently, write your own routine according to the `_matherr` reference description and name it `_matherr`.
41
41
42
-
All `errno` values are predefined constants in \<errno.h>, and are UNIX-compatible. Only `ERANGE`, `EILSEQ`, and `EDOM` are specified in the ISO C99 standard. For a complete list, see [errno Constants](../c-runtime-library/errno-constants.md).
42
+
All `errno` values are predefined constants in `<errno.h>`, and are UNIX-compatible. Only `ERANGE`, `EILSEQ`, and `EDOM` are specified in the ISO C99 standard. For a complete list, see [errno Constants](../c-runtime-library/errno-constants.md).
The `_doserrno`, `_sys_errlist`, and `_sys_nerr` macros are Microsoft extensions. For more compatibility information, see [Compatibility](../c-runtime-library/compatibility.md).
0 commit comments