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
* correction regarding CStringA
* Update open-wopen.md
Clarify that _O_TEMPORARY sets FILE_SHARE_DELETE.
* Update other pages that mention _O_TEMPORARY effects.
* New article - IDL method wizard
* update after review
* update after review
* Update after review
* Update after review
* Updating - Add property wizard for VS2022
* Updating broken links
* Update after review
* New article - Add an IDL Property
* link updation
* Update after review
* update after review
* update after review
* New article - IDL MFC property wizard
* Broken link fixed
* Broken link fixed
* Update virtual-functions.md
* update for links
* Updating links
* Address cpp-docs 3780 3782 3790 3791 3805
* Attempt correction of table format
* Add documentation for compiler error C2956 and update error text (MicrosoftDocs#4176)
* Add documentation for compiler error C2956 and update error text
* Add TOC entry
* Update for grammar and my own comprehension.
Sometimes, you just get carried away. This version could use some simplification.
* Simplify.
Address remarks, attempt simplification.
Acrolinx all the things.
* More updates per review
Co-authored-by: Colin Robertson <corob@microsoft.com>
* Address cpp-docs 3816
* Address non-blocking issues from 4207
* fix for sample program.
* edits
* edit pass. Move to ide location
* minor edit
* fix link
* Final update
* final update
* final update
* resolving blocking issue
* resolving blocking issue
* ToC update for new article
* ToC update
* link update
* Correct inconsistent formatting for the `_O_EXCL` constant in the docs for the open functions
* Update c28195.md
* Update in alt-text
* Update in alt-text
* Final Update- See also section
* edit pass
* edit pass
* more cleanup
* typo
* small edit
* Final update
* edit pass
* edit pass
* formatting for scannability
* acrolinx
* one more try at spacing
* final update
* VMCS -> VMXON
According to the intel IA32 development manual (Volume 3 C3 23.7):
"Before executing VMXON, software should allocate a naturally aligned 4-KByte region of memory that a logical
processor may use to support VMX operation. This region is called the VMXON region."
* edit and add links
* fix links
* add code example
* click->tick
* Update date, link to Intel docs
* Another go at updating the description
* Fix stray double-quote
* Address issue in DD PR 1393452
* add /interface and /internal-partition - draft (MicrosoftDocs#4227)
* add /interface and /internal-partition - draft
* add example
* fix formatting
* update text regarding example
* tech review
* link updates
* fix switch name and link
* edits
* reorder version info
* cleanup
* add /tp flag
* fix command line
Co-authored-by: TylerMSFT <Tyler.Whitney@microsoft.com>
* Update os-ot-favor-small-code-favor-fast-code.md
Change "minimize or maximize size" to "minimize size or maximize speed"
* Expand into a whole SEO-friendly sentence
* Clarify when _matherr will be invoked (#4230)
Customer here https://developercommunity.visualstudio.com/t/_matherr-example-does-not-work-for-me/1676341#T-ND10016474 expressed confusion over when _matherr is called. This change points out that the only setting that will enable/disable this is the presence of _matherr, but it will not be triggered when using intrinsics.
* acrolinx and other fixes
* fix typo
* more code escape
* another code escape
* better formatting for retval possibilities
* fix backslashes
* incorp feedback
* SEO work
* acrolinx
* SEO work (MicrosoftDocs#4234)
* SEO work
* acrolinx
Co-authored-by: TylerMSFT <Tyler.Whitney@microsoft.com>
* SEO work
* incorp feedback
* better link description
* incorp review feedback
* fix location of graphic
* fix github issue#3845
* acrolinx
* Twhitney seo (MicrosoftDocs#4239)
* seo adjustments
* update toc
* fix links
* acrolinx pass
* incorp feedback
Co-authored-by: TylerMSFT <Tyler.Whitney@microsoft.com>
* add info about converting narrow and wide strings
* fix link
* fix another link
* Fixes for F1 issues in DD 1524526
* minor cleanup
* Minimal acrolinx fixes
* acrolinx
* minor cleanup
* acrolinx
* going for 100% acrolinx
* incorp feedback
* make instructions for control panel slightly better
Co-authored-by: TylerMSFT <Tyler.Whitney@microsoft.com>
Co-authored-by: Steve Wishnousky <stwish@microsoft.com>
Co-authored-by: rachana-satao <83084319+rachana-satao@users.noreply.github.com>
Co-authored-by: opbld15 <opbld15@microsoft.com>
Co-authored-by: Colin Robertson <corob@microsoft.com>
Co-authored-by: opbld16 <opbld16@microsoft.com>
Co-authored-by: opbld17 <opbld17@microsoft.com>
Co-authored-by: atikmapari <31974726+atikmapari@users.noreply.github.com>
Co-authored-by: PRMerger19 <prmrgr19@microsoft.com>
Co-authored-by: Ming Ho <94572161+homing1@users.noreply.github.com>
Co-authored-by: PRMerger5 <prmergr5@microsoft.com>
Co-authored-by: Regan Downer <97987445+v-regandowner@users.noreply.github.com>
Co-authored-by: Jonathan Emmett <joemmett@microsoft.com>
Co-authored-by: Tamara K <93546702+tamarakhader@users.noreply.github.com>
Co-authored-by: PRMerger17 <prmrgr17@microsoft.com>
Co-authored-by: Paula Miller <v-paulmi@microsoft.com>
Co-authored-by: Martin Storsjö <martin@martin.st>
Co-authored-by: Sunny Chatterjee <sunnych@microsoft.com>
Co-authored-by: Tyler Whitney <TylerMSFT@users.noreply.github.com>
Co-authored-by: Colin Cooper <72402153+v-ccolin@users.noreply.github.com>
Co-authored-by: krispy <monstertyo@gmail.com>
Co-authored-by: PRMerger8 <prmrgr8@microsoft.com>
Co-authored-by: PRMerger10 <prmrgr10@microsoft.com>
Co-authored-by: Tech Stuff <103606018+teknixstuff@users.noreply.github.com>
Co-authored-by: Dennis Rea <v-denrea@microsoft.com>
Co-authored-by: Anna Huff <92125952+AnnaMHuff@users.noreply.github.com>
Co-authored-by: PRMerger13 <prmrgr13@microsoft.com>
Co-authored-by: PRMerger7 <prmrgr7@microsoft.com>
Co-authored-by: PRMerger Service account 2 <PRMerger-2@users.noreply.github.com>
This topic demonstrates how to convert various Visual C++ string types into other strings. The strings types that are covered include `char *`, `wchar_t*`, [_bstr_t](../cpp/bstr-t-class.md), [CComBSTR](../atl/reference/ccombstr-class.md), [CString](../atl-mfc-shared/using-cstring.md), [basic_string](../standard-library/basic-string-class.md), and <xref:System.String?displayProperty=fullName>. In all cases, a copy of the string is made when converted to the new type. Any changes made to the new string will not affect the original string, and vice versa.
10
+
This article shows how to convert various Visual C++ string types into other strings.
12
11
13
-
## Example: Convert from char *
12
+
The strings types that are covered include `char *`, `wchar_t*`, [`_bstr_t`](../cpp/bstr-t-class.md), [`CComBSTR`](../atl/reference/ccombstr-class.md), [`CString`](../atl-mfc-shared/using-cstring.md), [`basic_string`](../standard-library/basic-string-class.md), and <xref:System.String?displayProperty=fullName>.
13
+
14
+
In all cases, a copy of the string is made when converted to the new type. Any changes made to the new string won't affect the original string, and vice versa.
15
+
16
+
For more background information about converting narrow and wide strings, see [Converting between narrow strings and wide strings](#converting-between-narrow-and-wide-strings).
17
+
18
+
## Example: Convert from `char *`
14
19
15
20
### Description
16
21
17
-
This example demonstrates how to convert from a `char *` to the other string types listed above. A `char *` string (also known as a Cstyle string) uses a null character to indicate the end of the string. Cstyle strings usually require one byte per character, but can also use two bytes. In the examples below, `char *` strings are sometimes referred to as multibyte character strings because of the string data that results from converting from Unicode strings. Single byte and multibyte character (`MBCS`) functions can operate on `char *` strings.
22
+
This example demonstrates how to convert from a `char *` to the string types listed above. A `char *` string (also known as a C-style string) uses a null character to indicate the end of the string. C-style strings usually require 1 byte per character, but can also use 2 bytes. In the examples below, `char *` strings are sometimes referred to as multibyte character strings because of the string data that results from converting from wide Unicode strings. Single byte and multibyte character (`MBCS`) functions can operate on `char *` strings.
This example demonstrates how to convert from a `wchar_t *` to the other string types listed above. Several string types, including `wchar_t *`, implement wide character formats. To convert a string between a multibyte and a wide character format, you can use a single function call like `mbstowcs_s` or a constructor invocation for a class like `CStringA`.
121
+
This example demonstrates how to convert from a `wchar_t *` to other string types. Several string types, including `wchar_t *`, implement wide character formats. To convert a string between a multibyte and a wide character format, you can use a single function call like `mbstowcs_s` or a constructor invocation for a class like `CStringA`.
This example demonstrates how to convert from a `_bstr_t` to the other string types listed above. The `_bstr_t` object is a way to encapsulate wide character `BSTR` strings. A BSTR string has a length value and does not use a null character to terminate the string, but the string type you convert to may require a terminating null.
243
+
This example demonstrates how to convert from a `_bstr_t` to other string types. The `_bstr_t` object encapsulates wide character `BSTR` strings. A `BSTR` string has a length value and doesn't use a null character to terminate the string, but the string type you convert to may require a terminating `NULL`.
This example demonstrates how to convert from a `CComBSTR` to the other string types listed above. Like _bstr_t, a `CComBSTR` object is a way to encapsulate wide character BSTR strings. A BSTR string has a length value and does not use a null character to terminate the string, but the string type you convert to may require a terminating null.
341
+
This example demonstrates how to convert from a `CComBSTR` to other string types. Like `_bstr_t`, a `CComBSTR` object encapsulates wide character `BSTR` strings. A `BSTR` string has a length value and doesn't use a null character to terminate the string, but the string type you convert to may require a terminating `NULL`.
This example demonstrates how to convert from a `CString` to the other string types listed above. `CString` is based on the TCHAR data type, which in turn depends on whether the symbol `_UNICODE` is defined. If `_UNICODE`is not defined, `TCHAR` is defined to be char and `CString` contains a multibyte character string; if `_UNICODE` is defined, `TCHAR` is defined to be **`wchar_t`** and `CString` contains a wide character string.
449
+
This example demonstrates how to convert from a `CString` to other string types. `CString` is based on the `TCHAR` data type, which in turn depends on whether the symbol `_UNICODE` is defined. If `_UNICODE`isn't defined, `TCHAR` is defined to be `char` and `CString` contains a multibyte character string; if `_UNICODE` is defined, `TCHAR` is defined to be **`wchar_t`** and `CString` contains a wide character string.
445
450
446
-
`CStringA`is the multibyte string always version of `CString`, `CStringW` is the wide character string only version. Neither `CStringA`nor`CStringW` use `_UNICODE` to determine how they should compile. `CStringA` and `CStringW` are used in this example to clarify minor differences in buffer size allocation and output handling.
451
+
`CStringA`contains the `char` type and supports single-byte or multibyte strings. `CStringW` is the wide character version. `CStringA`and`CStringW` don't use `_UNICODE` to determine how they should compile. `CStringA` and `CStringW` are used in this example to clarify minor differences in buffer size allocation and output handling.
This example demonstrates how to convert from a wide character (Unicode) [System::String](/dotnet/api/system.string) to the other string types listed above.
685
+
This example demonstrates how to convert from a wide character [System::String](/dotnet/api/system.string) to other string types.
// Make a copy of the System::String as a multibyte
714
719
// char* string. Allocate two bytes in the multibyte
715
720
// output string for every wide character in the input
716
-
// string, including space for a terminating null.
721
+
// string, including space for a terminating NULL.
717
722
size_t origsize = wcslen(wch) + 1;
718
723
const size_t newsize = origsize*2;
719
724
size_t convertedChars = 0;
@@ -778,16 +783,32 @@ Hello, World! (CStringW)
778
783
Hello, World! (basic_string)
779
784
```
780
785
786
+
## Converting between narrow and wide strings
787
+
788
+
Legacy C and Windows apps use code pages rather than Unicode encodings when handling narrow strings and wide strings.
789
+
790
+
.NET strings are UTF-16, but ATL's `CStringA` is a narrow string, and the conversion from wide to narrow is performed by the [`WideCharToMultiByte`](/windows/win32/api/stringapiset/nf-stringapiset-widechartomultibyte) Win32 function. When converting a C-style `CHAR*` (a C-style `CHAR*` is a .NET `byte*`) to a string, the opposite Win32 function, [`MultiByteToWideChar`](/windows/win32/api/stringapiset/nf-stringapiset-multibytetowidechar) is called.
791
+
792
+
Both functions rely on the Windows concept of a code page; not the .NET concept of a culture. To change the system code page, use the region setting using **Control Panel** > enter `Region` into the search box > **Region (change date, time, or number formats)** > **Administrative** > **Change system locale**.
793
+
794
+
On an `en-US` language version of Windows, the code page defaults to 1033. If you install a different language of Windows, it will have a different code page. You can change it using the control panel.
795
+
796
+
There's a mismatch in the way that `CStringA` performs a wide to narrow conversion and the way that `gcnew string(CHAR*)` performs a narrow to wide conversion. `CStringA` passes `CP_THREAD_ACP`, which means to use the current *thread* code page, to the narrowing conversion method. But `string.ctor(sbyte*)` passes `CP_ACP`, which means to use the current *system* code page, to the widening conversion method. If the system and thread code pages don't match, it can cause round-trip data corruption.
797
+
798
+
To reconcile this difference, use the constant `_CONVERSION_DONT_USE_THREAD_LOCALE`) to get the conversion to use `CP_ACP` (like .NET) instead of `CP_THREAD_ACP`. For more information, see [_CONVERSION_DONT_USE_THREAD_LOCALE](https://social.msdn.microsoft.com/Forums/vstudio/en-US/f3820781-c418-40bf-8c4f-7250001e5b68/visual-studio-2015-update-1-implicit-string-narrow-wide-conversion-and).
799
+
800
+
Another approach is to use [`pinvoke`](/dotnet/standard/native-interop/pinvoke) to call [`GetThreadLocale`](/windows/win32/api/winnls/nf-winnls-getthreadlocale). Use the returned `LCID` to create a [`CultureInfo`](/dotnet/api/system.globalization.cultureinfo). Then use `CultureInfo.TextInfo` to get the code page to use in the conversion.
801
+
781
802
## See also
782
803
783
-
[ATL and MFC String Conversion Macros](../atl/reference/string-conversion-macros.md)<br/>
784
-
[CString Operations Relating to C-Style Strings](../atl-mfc-shared/cstring-operations-relating-to-c-style-strings.md)<br/>
785
-
[How to: Convert Standard String to System::String](../dotnet/how-to-convert-standard-string-to-system-string.md)<br/>
786
-
[How to: Convert System::String to Standard String](../dotnet/how-to-convert-system-string-to-standard-string.md)<br/>
787
-
[How to: Convert System::String to wchar_t* or char\*](../dotnet/how-to-convert-system-string-to-wchar-t-star-or-char-star.md)<br/>
788
-
[Programming with CComBSTR](../atl/programming-with-ccombstr-atl.md)<br/>
0 commit comments