Marshal::PtrToStructure<T> Method (IntPtr)
[Supported in the .NET Framework 4.5.1 and later versions]
Marshals data from an unmanaged block of memory to a newly allocated managed object of the type specified by a generic type parameter.
Assembly: mscorlib (in mscorlib.dll)
public: generic<typename T> [SecurityCriticalAttribute] static T PtrToStructure( IntPtr ptr )
Parameters
- ptr
-
Type:
System::IntPtr
A pointer to an unmanaged block of memory.
Return Value
Type: TA managed object that contains the data that the ptr parameter points to.
Type Parameters
- T
The type of the object to which the data is to be copied. This must be a formatted class or a structure.
| Exception | Condition |
|---|---|
| ArgumentException | The layout of T is not sequential or explicit. |
| MissingMethodException | The class specified by T does not have an accessible default constructor. |
PtrToStructure<T>(IntPtr) is often necessary in COM interop and platform invoke when structure parameters are represented as System::IntPtr values. You can pass a value type to this method overload.
requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code.
Available since 8.1
.NET Framework
Available since 4.5.1
Portable Class Library
Supported in: portable .NET platforms
Windows Phone
Available since 8.1