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
Copy file name to clipboardExpand all lines: docs/atl-mfc-shared/allocating-and-releasing-memory-for-a-bstr.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -46,19 +46,19 @@ When you create `BSTR`s and pass them between COM objects, you must take care in
46
46
47
47
- When you call into a function that expects a `BSTR` argument, you must allocate the memory for the `BSTR` before the call and release it afterwards. For example:
- When you implement a function that returns a `BSTR`, allocate the string but do not free it. The receiving the function releases the memory. For example:
Multiple threads could be running using this same thread procedure but since each thread has its own heap there is no contention between threads. In addition, the fact that each heap is not thread-safe gives a measurable increase in performance even if just one copy of the thread is running. This is the result of the heap not using expensive interlocked operations to protect against concurrent access.
`Class CString` is based on class template [CStringT Class](../atl-mfc-shared/reference/cstringt-class.md). `CString` is a `typedef` of `CStringT`. More exactly, `CString` is a `typedef` of an *explicit specialization* of `CStringT`, which is a common way to use a class template to define a class. Similarly defined classes are `CStringA` and `CStringW`. For more information on explicit specialization, see [Class Template Instantiation](../Topic/Class%20Template%20Instantiation.md).
53
+
`Class CString` is based on class template [CStringT Class](../atl-mfc-shared/reference/cstringt-class.md). `CString` is a `typedef` of `CStringT`. More exactly, `CString` is a `typedef` of an *explicit specialization* of `CStringT`, which is a common way to use a class template to define a class. Similarly defined classes are `CStringA` and `CStringW`. For more information on explicit specialization, see [Class Template Instantiation](../topic/class%20template%20instantiation.md).
54
54
55
55
`CString`, `CStringA`, and `CStringW` are defined in atlstr.h. `CStringT` is defined in cstringt.h.
56
56
@@ -63,11 +63,11 @@ This topic explains the following basic [CString](../atl-mfc-shared/reference/cs
63
63
64
64
- Assign the value of a C literal string to a `CString` object.
The contents of a `CString` object are copied when one `CString` object is assigned to another. Therefore, the two strings do not share a reference to the actual characters that make up the string. For more information about how to use `CString` objects as values, see [CString Semantics](../atl-mfc-shared/cstring-semantics.md).
73
73
@@ -80,7 +80,7 @@ This topic explains the following basic [CString](../atl-mfc-shared/reference/cs
80
80
## <aname="_core_concatenating_two_cstring_objects"></a> Concatenating Two CString Objects
81
81
To concatenate two `CString` objects, use the concatenation operators (+ or +=), as follows.
At least one argument to the concatenation operators (+ or +=) must be a `CString` object, but you can use a constant character string (for example, `"big"`) or a `char` (for example, 'x') for the other argument.
86
86
@@ -97,7 +97,7 @@ This topic explains the following basic [CString](../atl-mfc-shared/reference/cs
97
97
98
98
The `CStringT` class template defines the relational operators (<, \<=, >=, >, ==, and !=), which are available for use by `CString`. You can compare two `CStrings` by using these operators, as shown in the following example.
For information about converting CString objects to other string types, see [How to: Convert Between Various String Types](../text/how-to-convert-between-various-string-types.md).
Copy file name to clipboardExpand all lines: docs/atl-mfc-shared/cstring-argument-passing.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -55,9 +55,9 @@ This article explains how to pass [CString](../atl-mfc-shared/reference/cstringt
55
55
## <aname="_core_strings_as_function_outputs"></a> Strings as Function Outputs
56
56
Typically you can return `CString` objects from functions because `CString` objects follow value semantics like primitive types. To return a read-only string, use a constant `CString` reference (**const CString&**). The following example illustrates the use of `CString` parameters and return types:
Sometimes you may require a copy of `CString` data to modify directly. Use the more secured function `strcpy_s` (or the Unicode/MBCS-portable `_tcscpy_s`) to copy the `CString` object into a separate buffer. This is where characters can be safely modified, as shown by the following example.
> The third argument to `strcpy_s` (or the Unicode/MBCS-portable `_tcscpy_s`) is either a `const``wchar_t*` (Unicode) or a `const``char*` (ANSI). The example above passes a `CString` for this argument. The C++ compiler automatically applies the conversion function defined for the `CString` class that converts a `CString` to an `LPCTSTR`. The ability to define casting operations from one type to another is one of the most useful features of C++.
For most functions that need a string argument, it is best to specify the formal parameter in the function prototype as a `const` pointer to a character (`LPCTSTR`) instead of a `CString`. When a formal parameter is specified as a `const` pointer to a character, you can pass either a pointer to a `TCHAR` array, a literal string [`"hi there"`], or a `CString` object. The `CString` object will be automatically converted to an `LPCTSTR`. Any place you can use an `LPCTSTR`, you can also use a `CString` object.
110
110
111
111
You can also specify a formal parameter as a constant string reference (that is, `const``CString&`) if the argument will not be modified. Drop the `const` modifier if the string will be modified by the function. If a default null value is desired, initialize it to the null string [`""`], as shown below:
Copy file name to clipboardExpand all lines: docs/atl-mfc-shared/cstring-semantics.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,7 +39,7 @@ Even though [CString](../atl-mfc-shared/reference/cstringt-class.md) objects are
39
39
40
40
You can assign one **CString** object to another. However, when you modify one of the two `CString` objects, the other `CString` object is not modified, as shown by the following example:
Note in the example that the two `CString` objects are considered "equal" because they represent the same character string. The `CString` class overloads the equality operator (`==`) to compare two `CString` objects based on their value (contents) rather than their identity (address).
> Uninitialized `CTime` objects are not initialized to a valid time.
50
50
51
51
2. Call the `CTime::GetCurrentTime` function to get the current time from the operating system. This function returns a `CTime` object that can be used to set the value of `CTime`, as follows:
Since `GetCurrentTime` is a static member function from the `CTime` class, you must qualify its name with the name of the class and the scope resolution operator (`::`), `CTime::GetCurrentTime()`.
56
56
57
57
Of course, the two steps outlined previously could be combined into a single program statement as follows:
Copy file name to clipboardExpand all lines: docs/atl-mfc-shared/date-and-time-automation-support.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -69,7 +69,7 @@ This article describes how to take advantage of the class library services relat
69
69
70
70
Note that a workaround is used near the end of the example to display the date properly using `COleDateTime::Format`. See the Knowledge Base article "BUG: Format("%D") Fails for `COleDateTime` and `COleDateTimeSpan`" (Q167338).
0 commit comments