Udostępnij za pośrednictwem


Marshal Class

Microsoft Silverlight will reach end of support after October 2021. Learn more.

This type can be used only by trusted applications. If you try to use its members in a partial-trust application, your code will throw a MethodAccessException exception. This type is security-critical, which restricts its use.

[SECURITY CRITICAL]

Provides a collection of methods for allocating unmanaged memory, copying unmanaged memory blocks, and converting managed to unmanaged types, as well as other miscellaneous methods used when interacting with unmanaged code.

Inheritance Hierarchy

System.Object
  System.Runtime.InteropServices.Marshal

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

Syntax

'Declaration
<SecurityCriticalAttribute> _
Public NotInheritable Class Marshal
[SecurityCriticalAttribute]
public static class Marshal

The Marshal type exposes the following members.

Methods

  Name Description
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 Copy(array<Byte[], Int32, IntPtr, Int32) Security Critical. Copies data from a one-dimensional, managed 8-bit unsigned integer array to an unmanaged memory pointer.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 Copy(array<Char[], Int32, IntPtr, Int32) Security Critical. Copies data from a one-dimensional, managed character array to an unmanaged memory pointer.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 Copy(array<Double[], Int32, IntPtr, Int32) Security Critical. Copies data from a one-dimensional, managed double-precision floating-point number array to an unmanaged memory pointer.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 Copy(array<Int16[], Int32, IntPtr, Int32) Security Critical. Copies data from a one-dimensional, managed 16-bit signed integer array to an unmanaged memory pointer.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 Copy(array<Int32[], Int32, IntPtr, Int32) Security Critical. Copies data from a one-dimensional, managed 32-bit signed integer array to an unmanaged memory pointer.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 Copy(array<Int64[], Int32, IntPtr, Int32) Security Critical. Copies data from a one-dimensional, managed 64-bit signed integer array to an unmanaged memory pointer.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 Copy(IntPtr, array<Byte[], Int32, Int32) Security Critical. Copies data from an unmanaged memory pointer to a managed 8-bit unsigned integer array.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 Copy(IntPtr, array<Char[], Int32, Int32) Security Critical. Copies data from an unmanaged memory pointer to a managed character array.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 Copy(IntPtr, array<Double[], Int32, Int32) Security Critical. Copies data from an unmanaged memory pointer to a managed double-precision floating-point number array.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 Copy(IntPtr, array<Int16[], Int32, Int32) Security Critical. Copies data from an unmanaged memory pointer to a managed 16-bit signed integer array.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 Copy(IntPtr, array<Int32[], Int32, Int32) Security Critical. Copies data from an unmanaged memory pointer to a managed 32-bit signed integer array.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 Copy(IntPtr, array<Int64[], Int32, Int32) Security Critical. Copies data from an unmanaged memory pointer to a managed 64-bit signed integer array.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 Copy(IntPtr, array<Single[], Int32, Int32) Security Critical. Copies data from an unmanaged memory pointer to a managed single-precision floating-point number array.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 Copy(array<Single[], Int32, IntPtr, Int32) Security Critical. Copies data from a one-dimensional, managed single-precision floating-point number array to an unmanaged memory pointer.
Public methodStatic member GetDelegateForFunctionPointer Security Critical. Converts an unmanaged function pointer to a delegate.
Public methodStatic memberSupported by Silverlight for Windows Phone GetExceptionForHR Security Critical. Converts the specified HRESULT error code to a corresponding Exception object.
Public methodStatic memberSupported by Silverlight for Windows Phone GetFunctionPointerForDelegate Security Critical. Converts a delegate into a function pointer callable from unmanaged code.
Public methodStatic memberSupported by Silverlight for Windows Phone GetHRForException Security Critical. Converts the specified exception to an HRESULT.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetLastWin32Error Security Critical. Returns the error code returned by the last unmanaged function called using platform invoke that has the DllImportAttribute.SetLastError flag set.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 Prelink Security Critical. Executes one-time method setup tasks without calling the method.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 PrelinkAll Security Critical. Performs a pre-link check for all methods on a class.
Public methodStatic member PtrToStringAnsi(IntPtr) Security Critical. Copies all characters up to the first null from an unmanaged ANSI string to a managed String. Widens each ANSI character to Unicode.
Public methodStatic member PtrToStringAnsi(IntPtr, Int32) Security Critical. Allocates a managed String, copies a specified number of characters from an unmanaged ANSI string into it, and widens each ANSI character to Unicode.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 PtrToStringUni(IntPtr) Security Critical. Allocates a managed String and copies all characters up to the first null character from an unmanaged Unicode string into it.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 PtrToStringUni(IntPtr, Int32) Security Critical. Copies a specified number of characters from a Unicode string stored in native heap to a managed String.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 PtrToStructure(IntPtr, Object) Security Critical. Marshals data from an unmanaged block of memory to a managed object.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 PtrToStructure(IntPtr, Type) Security Critical. Marshals data from an unmanaged block of memory to a newly allocated managed object of the specified type.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 ReadByte(IntPtr) Security Critical. Reads a single byte from an unmanaged pointer.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 ReadByte(IntPtr, Int32) Security Critical. Reads a single byte at a given offset (or index) from an unmanaged pointer.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 ReadInt16(IntPtr) Security Critical. Reads a 16-bit signed integer from the unmanaged memory.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 ReadInt16(IntPtr, Int32) Security Critical. Reads a 16-bit signed integer from unmanaged memory.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 ReadInt32(IntPtr) Security Critical. Reads a 32-bit signed integer from unmanaged memory.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 ReadInt32(IntPtr, Int32) Security Critical. Reads a 32-bit signed integer from unmanaged memory.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 ReadInt64(IntPtr) Security Critical. Reads a 64-bit signed integer from unmanaged memory.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 ReadInt64(IntPtr, Int32) Security Critical. Reads a 64-bit signed integer from unmanaged memory.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 ReadIntPtr Security Critical. Reads a processor native sized integer from unmanaged memory.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 SizeOf(Object) Returns the unmanaged size of an object in bytes.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 SizeOf(Type) Returns the size of an unmanaged type in bytes.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 StructureToPtr Security Critical. Marshals data from a managed object to an unmanaged block of memory.
Public methodStatic memberSupported by Silverlight for Windows Phone ThrowExceptionForHR(Int32) Security Critical. Throws an exception with a specific failure HRESULT value.
Public methodStatic memberSupported by Silverlight for Windows Phone ThrowExceptionForHR(Int32, IntPtr) Security Critical. Throws an exception with a specific failure HRESULT.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 WriteByte(IntPtr, Byte) Security Critical. Writes a single byte value to unmanaged memory.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 WriteByte(IntPtr, Int32, Byte) Security Critical. Writes a single byte value to unmanaged memory.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 WriteInt16(IntPtr, Int16) Security Critical. Writes a 16-bit integer value to unmanaged memory.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 WriteInt16(IntPtr, Int32, Int16) Security Critical. Writes a 16-bit signed integer value into unmanaged memory.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 WriteInt32(IntPtr, Int32) Security Critical. Writes a 32-bit signed integer value to unmanaged memory.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 WriteInt32(IntPtr, Int32, Int32) Security Critical. Writes a 32-bit signed integer value into unmanaged memory.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 WriteInt64(IntPtr, Int64) Security Critical. Writes a 64-bit signed integer value to unmanaged memory.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 WriteInt64(IntPtr, Int32, Int64) Security Critical. Writes a 64-bit signed integer value to unmanaged memory.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 WriteIntPtr Security Critical. Writes a processor native sized integer value into unmanaged memory.

Top

Fields

  Name Description
Public fieldStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 SystemDefaultCharSize Represents the default character size on the system; the default is 2 for Unicode systems and 1 for ANSI systems. This field is read-only.

Top

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.