Marshal.PtrToStructure<'T> Method (IntPtr, 'T)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

[Supported in the .NET Framework 4.5.1 and later versions]

Marshals data from an unmanaged block of memory to a managed object of the specified type.

Namespace:   System.Runtime.InteropServices
Assembly:  mscorlib (in mscorlib.dll)

static member PtrToStructure<'T> : 
        ptr:nativeint *
        structure:'T -> unit


Type: System.IntPtr

A pointer to an unmanaged block of memory.

Type: T

The object to which the data is to be copied.

Type Parameters


The type of structure. This must be a formatted class.

Exception Condition

Structure layout is not sequential or explicit.

PtrToStructure<'T>(IntPtr, 'T) is often necessary in COM interop and platform invoke when structure parameters are represented as IntPtr values. You cannot use this method overload with value types.


requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code.

Universal Windows Platform
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
Return to top