Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
MSDN Library

Marshal.PtrToStructure(Of 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.

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

'Declaration
Public Shared Function PtrToStructure(Of T) ( _
	ptr As IntPtr _
) As T

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.

Parameters

ptr
Type: System.IntPtr

A pointer to an unmanaged block of memory.

Return Value

Type: T
A managed object that contains the data that the ptr parameter points to.

ExceptionCondition
ArgumentException

The layout of T is not sequential or explicit.

MissingMethodException

The class specified by T does not have an accessible default constructor.

PtrToStructure(Of 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.

.NET Framework

Supported in: 4.6, 4.5.1

.NET for Windows Phone apps

Supported in: Windows Phone 8.1

  • SecurityCriticalAttribute 

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

Show:
© 2015 Microsoft