Skip to content

Commit e752317

Browse files
authored
Merge pull request MicrosoftDocs#3609 from TylerMSFT/twhitney-githubissues
Twhitney githubissues
2 parents feb19e7 + 22ce8f4 commit e752317

File tree

3 files changed

+253
-252
lines changed

3 files changed

+253
-252
lines changed

docs/c-runtime-library/reference/setlocale-wsetlocale.md

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
---
22
title: "setlocale, _wsetlocale"
33
description: "Describes the Microsoft C runtime (CRT) library functions setlocale and _wsetlocale."
4-
ms.date: "4/2/2020"
4+
ms.date: "6/8/2021"
55
api_name: ["_wsetlocale", "setlocale", "_o__wsetlocale", "_o_setlocale"]
66
api_location: ["msvcrt.dll", "msvcr80.dll", "msvcr90.dll", "msvcr100.dll", "msvcr100_clr0400.dll", "msvcr110.dll", "msvcr110_clr0400.dll", "msvcr120.dll", "msvcr120_clr0400.dll", "ucrtbase.dll", "api-ms-win-crt-locale-l1-1-0.dll", "api-ms-win-crt-private-l1-1-0.dll"]
77
api_type: ["DLLExport"]
88
topic_type: ["apiref"]
99
f1_keywords: ["_wsetlocale", "_tsetlocale", "setlocale"]
1010
helpviewer_keywords: ["wsetlocale function", "setlocale function", "tsetlocale function", "locales, defining", "_tsetlocale function", "defining locales", "_wsetlocale function"]
11-
ms.assetid: 3ffb684e-5990-4202-9553-b5339af9520d
1211
no-loc: [setlocale, _wsetlocale]
1312
---
1413
# `setlocale`, `_wsetlocale`
@@ -171,13 +170,27 @@ The function [`_configthreadlocale`](configthreadlocale.md) is used to control w
171170

172171
## UTF-8 Support
173172

174-
Starting in Windows 10 build 17134 (April 2018 Update), the Universal C Runtime supports using a UTF-8 code page. This means that `char` strings passed to C runtime functions will expect strings in the UTF-8 encoding. To enable UTF-8 mode, use "`UTF-8`" as the code page when using `setlocale`. For example, `setlocale(LC_ALL, ".utf8")` will use the current default Windows ANSI code page (ACP) for the locale and UTF-8 for the code page.
173+
Starting in Windows 10 build 17134 (April 2018 Update), the Universal C Runtime supports using a UTF-8 code page. This means that `char` strings passed to C runtime functions will expect strings in the UTF-8 encoding. To enable UTF-8 mode, use `".UTF8"` as the code page when using `setlocale`. For example, `setlocale(LC_ALL, ".UTF8")` will use the current default Windows ANSI code page (ACP) for the locale and UTF-8 for the code page.
175174

176-
After calling `setlocale(LC_ALL, ".UTF8")`, you may pass "😊" to `mbtowcs` and it will be properly translated to a `wchar_t` string, whereas previously there was not a locale setting available to do this.
175+
The string to specify UTF-8 mode is:
176+
- case-insensitive
177+
- the hyphen (-) is optional
178+
- It must be in the code page part of the locale name, so must have a leading period '.' For example, `"en_US.UTF8"` or `".utf8"`
177179

178-
UTF-8 mode is also enabled for functions that have historically translated `char` strings using the default Windows ANSI code page (ACP). For example, calling [`_mkdir("😊")`](../reference/mkdir-wmkdir.md) while using a UTF-8 code page will correctly produce a directory with that emoji as the folder name, instead of requiring the ACP to be changed to UTF-8 prior to running your program. Likewise, calling [`_getcwd()`](../reference/getcwd-wgetcwd.md) inside of that folder will return a UTF-8 encoded string. For compatibility, the ACP is still used if the C locale code page is not set to UTF-8.
180+
The following examples show how to specify the UTF-8 string:
179181

180-
The following aspects of the C Runtime that are not able to use UTF-8 because they are set during program startup and must use the default Windows ANSI code page (ACP): [`__argv`](../argc-argv-wargv.md), [`_acmdln`](../acmdln-tcmdln-wcmdln.md), and [`_pgmptr`](../pgmptr-wpgmptr.md).
182+
`".UTF8"`\
183+
`".UTF-8"`\
184+
`".utf8"`\
185+
`".utf-8"`\
186+
`"en_us.utf8"`\
187+
`"ja_JP.Utf-8"`
188+
189+
After calling `setlocale(LC_ALL, ".UTF8")`, you may pass "😊" to `mbtowcs` and it will be properly translated to a `wchar_t` string, whereas previously there wasn't a locale setting available to do this.
190+
191+
UTF-8 mode is also enabled for functions that have historically translated `char` strings using the default Windows ANSI code page (ACP). For example, calling [`_mkdir("😊")`](../reference/mkdir-wmkdir.md) while using a UTF-8 code page will correctly produce a directory with that emoji as the folder name, instead of requiring the ACP to be changed to UTF-8 before running your program. Likewise, calling [`_getcwd()`](../reference/getcwd-wgetcwd.md) in that folder will return a UTF-8 encoded string. For compatibility, the ACP is still used if the C locale code page is not set to UTF-8.
192+
193+
The following aspects of the C Runtime can't use UTF-8 because they are set during program startup and must use the default Windows ANSI code page (ACP): [`__argv`](../argc-argv-wargv.md), [`_acmdln`](../acmdln-tcmdln-wcmdln.md), and [`_pgmptr`](../pgmptr-wpgmptr.md).
181194

182195
Previous to this support, [`mbrtoc16`, `mbrtoc32`](../reference/mbrtoc16-mbrtoc323.md), [`c16rtomb`, and `c32rtomb`](../reference/c16rtomb-c32rtomb1.md) existed to translate between UTF-8 narrow strings, UTF-16 (same encoding as `wchar_t` on Windows platforms) and UTF-32. For compatibility reasons, these APIs still only translate to and from UTF-8 and not the code page set via `setlocale`.
183196

@@ -190,7 +203,7 @@ To use this feature on an OS prior to Windows 10, such as Windows 7, you must us
190203
|`setlocale`|`<locale.h>`|
191204
|`_wsetlocale`|`<locale.h>` or `<wchar.h>`|
192205

193-
For additional compatibility information, see [Compatibility](../../c-runtime-library/compatibility.md).
206+
For more compatibility information, see [Compatibility](../../c-runtime-library/compatibility.md).
194207

195208
## Example
196209

docs/mfc/windows-sockets-using-class-casyncsocket.md

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
11
---
22
description: "Learn more about: Windows Sockets: Using Class CAsyncSocket"
33
title: "Windows Sockets: Using Class CAsyncSocket"
4-
ms.date: "11/04/2016"
4+
ms.date: "6/8/2021"
55
helpviewer_keywords: ["CAsyncSocket class [MFC], programming model", "Windows Sockets [MFC], asynchronous", "sockets [MFC], converting between Unicode and MBCS strings", "SOCKET handle", "sockets [MFC], asynchronous operation", "Windows Sockets [MFC], converting Unicode and MBCS strings"]
6-
ms.assetid: 825dae17-7c1b-4b86-8d6c-da7f1afb5d8d
76
---
8-
# Windows Sockets: Using Class CAsyncSocket
7+
# Windows Sockets: Using Class `CAsyncSocket`
98

10-
This article explains how to use class [CAsyncSocket](../mfc/reference/casyncsocket-class.md). Be aware that this class encapsulates the Windows Sockets API at a very low level. `CAsyncSocket` is for use by programmers who know network communications in detail but want the convenience of callbacks for notification of network events. Based on this assumption, this article provides only basic instruction. You should probably consider using `CAsyncSocket` if you want Windows Sockets' ease of dealing with multiple network protocols in an MFC application but do not want to sacrifice flexibility. You might also feel that you can get better efficiency by programming the communications more directly yourself than you could using the more general alternative model of class `CSocket`.
9+
This article explains how to use class [`CAsyncSocket`](../mfc/reference/casyncsocket-class.md). This class encapsulates the Windows Sockets API at a very low level. `CAsyncSocket` is for use by programmers who know network communications in detail but want the convenience of callbacks for notification of network events. Based on this assumption, this article provides only basic instruction. You should probably consider using `CAsyncSocket` if you want Windows Sockets' ease of dealing with multiple network protocols in an MFC application but don't want to sacrifice flexibility. You might also feel that you can get better efficiency by programming the communications more directly yourself than you could using the more general alternative model of class `CSocket`.
1110

12-
`CAsyncSocket` is documented in the *MFC Reference*. Visual C++ also supplies the Windows Sockets specification, located in the Windows SDK. The details are left to you. Visual C++ does not supply a sample application for `CAsyncSocket`.
11+
`CAsyncSocket` is documented in the *MFC Reference*. Visual C++ also supplies the Windows Sockets specification, located in the Windows SDK. The details are left to you. Visual C++ doesn't supply a sample application for `CAsyncSocket`.
1312

14-
If you are not highly knowledgeable about network communications and want a simple solution, use class [CSocket](../mfc/reference/csocket-class.md) with a `CArchive` object. See [Windows Sockets: Using Sockets with Archives](../mfc/windows-sockets-using-sockets-with-archives.md) for more information.
13+
If you aren't highly knowledgeable about network communications and want a simple solution, use class [`CSocket`](../mfc/reference/csocket-class.md) with a `CArchive` object. See [Windows Sockets: Using Sockets with Archives](../mfc/windows-sockets-using-sockets-with-archives.md) for more information.
1514

1615
This article covers:
1716

1817
- Creating and using a `CAsyncSocket` object.
1918

20-
- [Your responsibilities with CAsyncSocket](#_core_your_responsibilities_with_casyncsocket).
19+
- [Your responsibilities with `CAsyncSocket`](#_core_your_responsibilities_with_casyncsocket).
2120

22-
## <a name="_core_creating_and_using_a_casyncsocket_object"></a> Creating and Using a CAsyncSocket Object
21+
## <a name="_core_creating_and_using_a_casyncsocket_object"></a> Creating and using a `CAsyncSocket`
2322

24-
#### To use CAsyncSocket
23+
#### To use `CAsyncSocket`
2524

26-
1. Construct a [CAsyncSocket](../mfc/reference/casyncsocket-class.md) object and use the object to create the underlying **SOCKET** handle.
25+
1. Construct a [`CAsyncSocket`](../mfc/reference/casyncsocket-class.md) object and use the object to create the underlying **`SOCKET`** handle.
2726

2827
Creation of a socket follows the MFC pattern of two-stage construction.
2928

@@ -35,48 +34,48 @@ This article covers:
3534

3635
[!code-cpp[NVC_MFCSimpleSocket#4](../mfc/codesnippet/cpp/windows-sockets-using-class-casyncsocket_2.cpp)]
3736

38-
The first constructor above creates a `CAsyncSocket` object on the stack. The second constructor creates a `CAsyncSocket` on the heap. The first [Create](../mfc/reference/casyncsocket-class.md#create) call above uses the default parameters to create a stream socket. The second `Create` call creates a datagram socket with a specified port and address. (You can use either `Create` version with either construction method.)
37+
The first constructor above creates a `CAsyncSocket` object on the stack. The second constructor creates a `CAsyncSocket` on the heap. The first [`Create`](../mfc/reference/casyncsocket-class.md#create) call above uses the default parameters to create a stream socket. The second `Create` call creates a datagram socket with a specified port and address. (You can use either `Create` version with either construction method.)
3938

4039
The parameters to `Create` are:
4140

4241
- A "port": a short integer.
4342

4443
For a server socket, you must specify a port. For a client socket, you typically accept the default value for this parameter, which lets Windows Sockets select a port.
4544

46-
- A socket type: **SOCK_STREAM** (the default) or **SOCK_DGRAM**.
45+
- A socket type: **`SOCK_STREAM`** (the default) or **`SOCK_DGRAM`**.
4746

48-
- A socket "address," such as "ftp.microsoft.com" or "128.56.22.8".
47+
- A socket "address" such as `"ftp.microsoft.com"` or `"128.56.22.8"`.
4948

50-
This is your Internet Protocol (IP) address on the network. You will probably always rely on the default value for this parameter.
49+
This is your Internet Protocol (IP) address on the network. You'll probably always rely on the default value for this parameter.
5150

5251
The terms "port" and "socket address" are explained in [Windows Sockets: Ports and Socket Addresses](../mfc/windows-sockets-ports-and-socket-addresses.md).
5352

54-
1. If the socket is a client, connect the socket object to a server socket, using [CAsyncSocket::Connect](../mfc/reference/casyncsocket-class.md#connect).
53+
1. If the socket is a client, connect the socket object to a server socket, using [`CAsyncSocket::Connect`](../mfc/reference/casyncsocket-class.md#connect).
5554

5655
-or-
5756

58-
If the socket is a server, set the socket to begin listening (with [CAsyncSocket::Listen](../mfc/reference/casyncsocket-class.md#listen)) for connect attempts from a client. Upon receiving a connection request, accept it with [CAsyncSocket::Accept](../mfc/reference/casyncsocket-class.md#accept).
57+
If the socket is a server, set the socket to begin listening (with [`CAsyncSocket::Listen`](../mfc/reference/casyncsocket-class.md#listen)) for connect attempts from a client. Upon receiving a connection request, accept it with [`CAsyncSocket::Accept`](../mfc/reference/casyncsocket-class.md#accept).
5958

60-
After accepting a connection, you can perform such tasks as validating passwords.
59+
After accepting a connection, you can do tasks like validating passwords.
6160

6261
> [!NOTE]
63-
> The `Accept` member function takes a reference to a new, empty `CSocket` object as its parameter. You must construct this object before you call `Accept`. If this socket object goes out of scope, the connection closes. Do not call `Create` for this new socket object. For an example, see the article [Windows Sockets: Sequence of Operations](../mfc/windows-sockets-sequence-of-operations.md).
62+
> The `Accept` member function takes a reference to a new, empty `CSocket` object as its parameter. You must construct this object before you call `Accept`. If this socket object goes out of scope, the connection closes. Don't call `Create` for this new socket object. For an example, see the article [Windows Sockets: Sequence of Operations](../mfc/windows-sockets-sequence-of-operations.md).
6463
6564
1. Carry out communications with other sockets by calling the `CAsyncSocket` object's member functions that encapsulate the Windows Sockets API functions.
6665

67-
See the Windows Sockets specification and class [CAsyncSocket](../mfc/reference/casyncsocket-class.md) in the *MFC Reference*.
66+
See the Windows Sockets specification and class [`CAsyncSocket`](../mfc/reference/casyncsocket-class.md) in the *MFC Reference*.
6867

6968
1. Destroy the `CAsyncSocket` object.
7069

71-
If you created the socket object on the stack, its destructor is called when the containing function goes out of scope. If you created the socket object on the heap, using the **`new`** operator, you are responsible for using the **`delete`** operator to destroy the object.
70+
If you created the socket object on the stack, its destructor is called when the containing function goes out of scope. If you created the socket object on the heap, using the **`new`** operator, you're responsible for using the **`delete`** operator to destroy the object.
7271

73-
The destructor calls the object's [Close](../mfc/reference/casyncsocket-class.md#close) member function before destroying the object.
72+
The destructor calls the object's [`Close`](../mfc/reference/casyncsocket-class.md#close) member function before destroying the object.
7473

7574
For an example of this sequence in code (actually for a `CSocket` object), see [Windows Sockets: Sequence of Operations](../mfc/windows-sockets-sequence-of-operations.md).
7675

77-
## <a name="_core_your_responsibilities_with_casyncsocket"></a> Your Responsibilities with CAsyncSocket
76+
## <a name="_core_your_responsibilities_with_casyncsocket"></a> Your responsibilities with `CAsyncSocket`
7877

79-
When you create an object of class [CAsyncSocket](../mfc/reference/casyncsocket-class.md), the object encapsulates a Windows **SOCKET** handle and supplies operations on that handle. When you use `CAsyncSocket`, you must deal with all the issues you might face if using the API directly. For example:
78+
When you create an object of class [`CAsyncSocket`](../mfc/reference/casyncsocket-class.md), the object encapsulates a Windows **`SOCKET`** handle and supplies operations on that handle. When you use `CAsyncSocket`, you must deal with all the issues you might face if using the API directly. For example:
8079

8180
- "Blocking" scenarios.
8281

@@ -86,14 +85,12 @@ When you create an object of class [CAsyncSocket](../mfc/reference/casyncsocket-
8685

8786
For definitions of these terms and additional information, see [Windows Sockets: Blocking](../mfc/windows-sockets-blocking.md), [Windows Sockets: Byte Ordering](../mfc/windows-sockets-byte-ordering.md), [Windows Sockets: Converting Strings](../mfc/windows-sockets-converting-strings.md).
8887

89-
Despite these issues, class `CAsycnSocket` may be the right choice for you if your application requires all the flexibility and control you can get. If not, you should consider using class `CSocket` instead. `CSocket` hides a lot of detail from you: it pumps Windows messages during blocking calls and gives you access to `CArchive`, which manages byte order differences and string conversion for you.
88+
Despite these issues, class `CAsyncSocket` may be the right choice for you if your application requires all the flexibility and control you can get. If not, consider using class `CSocket` instead. `CSocket` hides many details from you: it pumps Windows messages during blocking calls and gives you access to `CArchive`, which manages byte order differences and string conversion for you.
9089

9190
For more information, see:
9291

93-
- [Windows Sockets: Background](../mfc/windows-sockets-background.md)
94-
95-
- [Windows Sockets: Stream Sockets](../mfc/windows-sockets-stream-sockets.md)
96-
92+
- [Windows Sockets: Background](../mfc/windows-sockets-background.md)\
93+
- [Windows Sockets: Stream Sockets](../mfc/windows-sockets-stream-sockets.md)\
9794
- [Windows Sockets: Datagram Sockets](../mfc/windows-sockets-datagram-sockets.md)
9895

9996
## See also

0 commit comments

Comments
 (0)