Skip to content

Commit 58edf0a

Browse files
Merge pull request #4917 from MicrosoftDocs/main638421498487873282sync_temp
For protected branch, push strategy should use PR and merge to target branch method to work around git push error
2 parents 68a9ba1 + 08b6bca commit 58edf0a

File tree

2 files changed

+58
-49
lines changed

2 files changed

+58
-49
lines changed

docs/atl-mfc-shared/reference/csimplestringt-class.md

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: "Learn more about: CSimpleStringT Class"
33
title: "CSimpleStringT Class"
4-
ms.date: 10/04/2021
4+
ms.date: 01/26/2024
55
f1_keywords: ["CSimpleStringT", "ATLSIMPSTR/ATL::CSimpleStringT", "ATLSIMPSTR/ATL::CSimpleStringT::PCXSTR", "ATLSIMPSTR/ATL::CSimpleStringT::PXSTR", "ATLSIMPSTR/ATL::CSimpleStringT::CSimpleStringT", "ATLSIMPSTR/ATL::CSimpleStringT::Append", "ATLSIMPSTR/ATL::CSimpleStringT::AppendChar", "ATLSIMPSTR/ATL::CSimpleStringT::CopyChars", "ATLSIMPSTR/ATL::CSimpleStringT::CopyCharsOverlapped", "ATLSIMPSTR/ATL::CSimpleStringT::Empty", "ATLSIMPSTR/ATL::CSimpleStringT::FreeExtra", "ATLSIMPSTR/ATL::CSimpleStringT::GetAllocLength", "ATLSIMPSTR/ATL::CSimpleStringT::GetAt", "ATLSIMPSTR/ATL::CSimpleStringT::GetBuffer", "ATLSIMPSTR/ATL::CSimpleStringT::GetBufferSetLength", "ATLSIMPSTR/ATL::CSimpleStringT::GetLength", "ATLSIMPSTR/ATL::CSimpleStringT::GetManager", "ATLSIMPSTR/ATL::CSimpleStringT::GetString", "ATLSIMPSTR/ATL::CSimpleStringT::IsEmpty", "ATLSIMPSTR/ATL::CSimpleStringT::LockBuffer", "ATLSIMPSTR/ATL::CSimpleStringT::Preallocate", "ATLSIMPSTR/ATL::CSimpleStringT::ReleaseBuffer", "ATLSIMPSTR/ATL::CSimpleStringT::ReleaseBufferSetLength", "ATLSIMPSTR/ATL::CSimpleStringT::SetAt", "ATLSIMPSTR/ATL::CSimpleStringT::SetManager", "ATLSIMPSTR/ATL::CSimpleStringT::SetString", "ATLSIMPSTR/ATL::CSimpleStringT::StringLength", "ATLSIMPSTR/ATL::CSimpleStringT::Truncate", "ATLSIMPSTR/ATL::CSimpleStringT::UnlockBuffer"]
66
helpviewer_keywords: ["shared classes, CSimpleStringT", "strings [C++], ATL class", "CSimpleStringT class"]
77
---
@@ -445,7 +445,7 @@ An `PXSTR` pointer to the object's (null-terminated) character buffer.
445445
446446
Call this method to return the buffer contents of the `CSimpleStringT` object. The returned `PXSTR` is not a constant and therefore allows direct modification of `CSimpleStringT` contents.
447447
448-
If you use the pointer returned by `GetBuffer` to change the string contents, you must call [`ReleaseBuffer`](#releasebuffer) before you use any other `CSimpleStringT` member methods.
448+
If you use the pointer returned by `GetBuffer` to change the string contents, you must call [`ReleaseBuffer`](#releasebuffer) to update the internal state of `CSimpleStringT` before you use any other `CSimpleStringT` methods.
449449
450450
The address returned by `GetBuffer` may not be valid after the call to `ReleaseBuffer` because additional `CSimpleStringT` operations can cause the `CSimpleStringT` buffer to be reallocated. The buffer is not reallocated if you do not change the length of the `CSimpleStringT`.
451451
@@ -491,7 +491,7 @@ A `PXSTR` pointer to the object's (null-terminated) character buffer.
491491
492492
Call this method to retrieve a specified length of the internal buffer of the `CSimpleStringT` object. The returned `PXSTR` pointer is not **`const`** and thus allows direct modification of `CSimpleStringT` contents.
493493
494-
If you use the pointer returned by [`GetBufferSetLength`](#getbuffersetlength) to change the string contents, call `ReleaseBuffer` to update the internal state of `CsimpleStringT` before you use any other `CSimpleStringT` methods.
494+
If you use the pointer returned by [`GetBufferSetLength`](#getbuffersetlength) to change the string contents, call `ReleaseBuffer` to update the internal state of `CSimpleStringT` before you use any other `CSimpleStringT` methods.
495495
496496
The address returned by `GetBufferSetLength` may not be valid after the call to `ReleaseBuffer` because additional `CSimpleStringT` operations can cause the `CSimpleStringT` buffer to be reallocated. The buffer is not reassigned if you do not change the length of the `CSimpleStringT`.
497497
@@ -502,9 +502,7 @@ If you keep track of the string length yourself, do not append the terminating n
502502
For more information about reference counting, see the following articles:
503503
504504
- [Managing Object Lifetimes through Reference Counting](/windows/win32/com/managing-object-lifetimes-through-reference-counting) in the Windows SDK.
505-
506505
- [Implementing Reference Counting](/windows/win32/com/implementing-reference-counting) in the Windows SDK.
507-
508506
- [Rules for Managing Reference Counts](/windows/win32/com/rules-for-managing-reference-counts) in the Windows SDK.
509507
510508
### Example
@@ -517,9 +515,7 @@ LPTSTR pstr = str.GetBufferSetLength(3);
517515
pstr[0] = _T('C');
518516
pstr[1] = _T('u');
519517
pstr[2] = _T('p');
520-
521-
// No need for trailing zero or call to ReleaseBuffer()
522-
// because GetBufferSetLength() set it for us.
518+
str.ReleaseBuffer();
523519
524520
str += _T(" soccer is best!");
525521
ASSERT(_tcscmp(str, _T("Cup soccer is best!")) == 0);
@@ -1166,19 +1162,19 @@ The following example demonstrates the use of `CSimpleStringT::Truncate`.
11661162
CAtlString basestr;
11671163
IAtlStringMgr* pMgr = basestr.GetManager();
11681164
CSimpleString str(_T("abcdefghi"), pMgr);
1169-
_tprintf_s(_T("Allocated length: %d\n"), str.GetLength());
1170-
_tprintf_s(_T("Contents: %s\n"), str);
1165+
_tprintf_s(_T("String length: %d / Allocated length: %d\n"), str.GetLength(), str.GetAllocLength());
1166+
_tprintf_s(_T("Contents: %s\n"), (LPCTSTR)str);
11711167
str.Truncate(4);
1172-
_tprintf_s(_T("Allocated length: %d\n"), str.GetLength());
1173-
_tprintf_s(_T("Contents: %s\n"), str);
1168+
_tprintf_s(_T("String length: %d / Allocated length: %d\n"), str.GetLength(), , str.GetAllocLength());
1169+
_tprintf_s(_T("Contents: %s\n"), (LPCTSTR)str);
11741170
```
11751171
11761172
The output from this example is:
11771173
11781174
```Output
1179-
Allocated length: 9
1175+
String length: 9 / Allocated length: 15
11801176
Contents: abcdefghi
1181-
Allocated length: 4
1177+
String length: 4 / Allocated length: 15
11821178
Contents: abcd
11831179
```
11841180

0 commit comments

Comments
 (0)