Export (0) Print
Expand All

Marshal.PtrToStructure Method

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

Overload List

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

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Sub PtrToStructure(IntPtr, Object)
[C#] public static void PtrToStructure(IntPtr, object);
[C++] public: static void PtrToStructure(IntPtr, Object*);
[JScript] public static function PtrToStructure(IntPtr, Object);

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

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Function PtrToStructure(IntPtr, Type) As Object
[C#] public static object PtrToStructure(IntPtr, Type);
[C++] public: static Object* PtrToStructure(IntPtr, Type*);
[JScript] public static function PtrToStructure(IntPtr, Type) : Object;

Example

[Visual Basic, C#] The following example demonstrates using PtrToStructure after calling UCOMITypeInfo.GetTypeAttr to obtain a TYPEATTR structure. GetTypeAttr is defined with a by-reference IntPtr parameter because the unmanaged signature's TYPEATTR** parameter is not supported by the interop marshaler.

[Visual Basic, C#] Note   This example shows how to use one of the overloaded versions of PtrToStructure. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Dim typeInfo As UCOMITypeInfo = ... 
Dim ptr As IntPtr = IntPtr.Zero
typeInfo.GetTypeAttr(ptr)
Dim attr As TYPEATTR = _ 
  CType(Marshal.PtrToStructure(ptr, GetType(TYPEATTR)), TYPEATTR)
[C#] 
UCOMITypeInfo typeInfo = ...; 
IntPtr ptr = IntPtr.Zero; 
typeInfo.GetTypeAttr(ref ptr); 
TYPEATTR attr = (TYPEATTR)Marshal.PtrToStructure(ptr, 
    typeof(TYPEATTR));

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

Marshal Class | Marshal Members | System.Runtime.InteropServices Namespace

Show:
© 2014 Microsoft