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
{{ message }}
Repository navigation
Commit ab8818c
Browse filesBrowse the repository at this point in the historyBrowse files
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).
88
88
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.
90
90
91
91
The lock will automatically be released when the destructor is called.
helpviewer_keywords: ["marshal_context class [C++]", "marshal_context class [C++], operations"]
7
7
ms.assetid: 241b0cf6-4ca4-4812-aaee-d671c11dc034
8
8
---
9
9
# marshal_context Class
@@ -12,23 +12,112 @@ This class converts data between native and managed environments.
12
12
13
13
## Syntax
14
14
15
-
```
15
+
```cpp
16
16
classmarshal_context
17
17
```
18
18
19
19
## Remarks
20
20
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.
22
22
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.
24
24
25
25
## Requirements
26
26
27
27
**Header file:** \<msclr\marshal.h>, \<msclr\marshal_windows.h>, \<msclr\marshal_cppstd.h>, or \<msclr\marshal_atl.h>
28
28
29
29
**Namespace:** msclr::interop
30
30
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.|
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).
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.
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
+
usingnamespaceSystem;
113
+
usingnamespacemsclr::interop;
32
114
33
-
[Overview of Marshaling in C++](../dotnet/overview-of-marshaling-in-cpp.md)<br/>
0 commit comments