Skip to content

Commit ab8818c

Browse files
committed
Consolidate articles.
1 parent a487c49 commit ab8818c

2 files changed

Lines changed: 99 additions & 10 deletions

File tree

‎docs/dotnet/lock-class.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ Throws <xref:System.ApplicationException> if lock acquisition doesn't occur befo
8686

8787
The first three forms of the constructor try to acquire a lock on `_object` within the specified timeout period (or <xref:System.Threading.Timeout.Infinite> if none is specified).
8888

89-
The fourth form of the constructor doesn't acquire a lock on `_object`. `lock_later` is a member of the [lock_when Enum](../dotnet/lock-when-enum.md). Use [lock::acquire](../dotnet/lock-acquire.md) or [lock::try_acquire](../dotnet/lock-try-acquire.md) to acquire the lock in this case.
89+
The fourth form of the constructor doesn't acquire a lock on `_object`. `lock_later` is a member of the [lock_when enum](../dotnet/lock-when-enum.md). Use [lock::acquire](../dotnet/lock-acquire.md) or [lock::try_acquire](../dotnet/lock-try-acquire.md) to acquire the lock in this case.
9090

9191
The lock will automatically be released when the destructor is called.
9292

Lines changed: 98 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
22
title: "marshal_context Class"
3-
ms.date: "11/04/2016"
3+
ms.date: "12/19/2018"
44
ms.topic: "reference"
5-
f1_keywords: ["marshal_context"]
6-
helpviewer_keywords: ["marshal_context class [C++]"]
5+
f1_keywords: ["marshal_context", "msclr::interop::marshal_context::marshal_context", "marshal_context::marshal_context", "msclr.interop.marshal_context.marshal_context", "marshal_context.marshal_context", "marshal_context::~marshal_context", "msclr.interop.marshal_context.~marshal_context", "marshal_context.~marshal_context", "msclr::interop::marshal_context::~marshal_context", "~marshal_context", "marshal_context::marshal_as", "marshal_context.marshal_as", "msclr.interop.marshal_context.marshal_as", "msclr::interop::marshal_context::marshal_as" ]
6+
helpviewer_keywords: ["marshal_context class [C++]", "marshal_context class [C++], operations"]
77
ms.assetid: 241b0cf6-4ca4-4812-aaee-d671c11dc034
88
---
99
# marshal_context Class
@@ -12,23 +12,112 @@ This class converts data between native and managed environments.
1212

1313
## Syntax
1414

15-
```
15+
```cpp
1616
class marshal_context
1717
```
1818
1919
## Remarks
2020
21-
Use the `marshal_context` class for data conversions that require a context. See [Overview of Marshaling in C++](../dotnet/overview-of-marshaling-in-cpp.md) for more information about which conversions require a context and which marshaling file has to be included. The result of marshaling when you use a context is valid only until the `marshal_context` object is destroyed. To preserve your result, you must copy the data.
21+
Use the `marshal_context` class for data conversions that require a context. For more information about which conversions require a context and which marshaling file has to be included, see [Overview of marshaling in C++](../dotnet/overview-of-marshaling-in-cpp.md). The result of marshaling when you use a context is valid only until the `marshal_context` object is destroyed. To preserve your result, you must copy the data.
2222
23-
The same `marshal_context` can be used for multiple data conversions. Reusing the context in this manner will not affect the results from previous marshaling calls.
23+
The same `marshal_context` can be used for numerous data conversions. Reusing the context in this manner won't affect the results from previous marshaling calls.
2424
2525
## Requirements
2626
2727
**Header file:** \<msclr\marshal.h>, \<msclr\marshal_windows.h>, \<msclr\marshal_cppstd.h>, or \<msclr\marshal_atl.h>
2828
2929
**Namespace:** msclr::interop
3030
31-
## See Also
31+
### Public constructors
32+
33+
|Name|Description|
34+
|---------|-----------|
35+
|[marshal_context::marshal_context](#marshal_context)|Constructs a `marshal_context` object to use for data conversion between managed and native data types.|
36+
|[marshal_context::~marshal_context](#tilde-marshal_context)|Destroys a `marshal_context` object.|
37+
38+
### Public methods
39+
|Name|Description|
40+
|---------|-----------|
41+
|[marshal_context::marshal_as](#marshal_as)|Performs the marshaling on a specific data object to convert it between a managed and a native data type.|
42+
43+
## <a name=:marshal_context"></a>marshal_context::marshal_context
44+
45+
Constructs a `marshal_context` object to use for data conversion between managed and native data types.
46+
47+
```cpp
48+
marshal_context();
49+
```
50+
51+
### Remarks
52+
53+
Some data conversions require a marshal context. For more information about which translations require a context and which marshaling file you must include in your application, see [Overview of marshaling in C++](../dotnet/overview-of-marshaling-in-cpp.md).
54+
55+
### Example
56+
57+
See the example for [marshal_context::marshal_as](../dotnet/marshal-context-marshal-as.md).
58+
59+
60+
## <a name="tilde-marshal_context"></a>marshal_context::~marshal_context
61+
62+
Destroys a `marshal_context` object.
63+
64+
```cpp
65+
~marshal_context();
66+
```
67+
68+
### Remarks
69+
70+
Some data conversions require a marshal context. See [Overview of marshaling in C++](../dotnet/overview-of-marshaling-in-cpp.md) for more information about which translations require a context and which marshaling file has to be included in your application.
71+
72+
Deleting a `marshal_context` object will invalidate the data converted by that context. If you want to preserve your data after a `marshal_context` object is destroyed, you must manually copy the data to a variable that will persist.
73+
74+
## <a name="marshal_as"></a>marshal_context::marshal_as
75+
76+
Performs the marshaling on a specific data object to convert it between a managed and a native data type.
77+
78+
```cpp
79+
To_Type marshal_as<To_Type>(
80+
From_Type input
81+
);
82+
```
83+
84+
### Parameters
85+
86+
*input*<br/>
87+
[in] The value that you want to marshal to a `To_Type` variable.
88+
89+
### Return value
90+
91+
A variable of type `To_Type` that's the converted value of `input`.
92+
93+
### Remarks
94+
95+
This function performs the marshaling on a specific data object. Use this function only with the conversions indicated by the table in [Overview of marshaling in C++](../dotnet/overview-of-marshaling-in-cpp.md).
96+
97+
If you try to marshal a pair of data types that aren't supported, `marshal_as` will generate an error [C4996](../error-messages/compiler-warnings/compiler-warning-level-3-c4996.md) at compile time. Read the message supplied with this error for more information. The `C4996` error can be generated for more than just deprecated functions. Two conditions that generate this error are trying to marshal a pair of data types that aren't supported and trying to use `marshal_as` for a conversion that requires a context.
98+
99+
The marshaling library consists of several header files. Any conversion requires only one file, but you can include additional files if you need to for other conversions. The table in `Marshaling Overview in C++` indicates which marshaling file should be included for each conversion.
100+
101+
### Example
102+
103+
This example creates a context for marshaling from a `System::String` to a `const char *` variable type. The converted data won't be valid after the line that deletes the context.
104+
105+
```cpp
106+
// marshal_context_test.cpp
107+
// compile with: /clr
108+
#include <stdlib.h>
109+
#include <string.h>
110+
#include <msclr\marshal.h>
111+
112+
using namespace System;
113+
using namespace msclr::interop;
32114

33-
[Overview of Marshaling in C++](../dotnet/overview-of-marshaling-in-cpp.md)<br/>
34-
[marshal_as](../dotnet/marshal-as.md)
115+
int main() {
116+
marshal_context^ context = gcnew marshal_context();
117+
String^ message = gcnew String("Test String to Marshal");
118+
const char* result;
119+
result = context->marshal_as<const char*>( message );
120+
delete context;
121+
return 0;
122+
}
123+
```

0 commit comments

Comments
 (0)