Marshal Class

Marshal Class

For apps that target Windows Phone OS 7.0 and 7.1, do not use any members of this type in your app. If you do, your code will throw a MethodAccessException. This type is security-critical, which restricts it to internal use by the .NET Framework for Windows Phone class library.
[SECURITY CRITICAL]

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

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.

System::Object
  System.Runtime.InteropServices::Marshal

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

No code example is currently available or this language may not be supported.

The Marshal type exposes the following members.

  NameDescription
Public methodStatic memberAddRefSecurity Critical. Increments the reference count on the specified interface.
Public methodStatic memberAllocCoTaskMemSecurity Critical. Allocates a block of memory of specified size from the COM task memory allocator.
Public methodStatic memberAllocHGlobalSecurity Critical. Allocates memory from the unmanaged memory of the process by using the specified number of bytes.
Public methodStatic memberCopy(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 memberCopy(array<Char>, Int32, IntPtr, Int32)Security Critical. Copies data from a one-dimensional, managed character array to an unmanaged memory pointer.
Public methodStatic memberCopy(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 memberCopy(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 memberCopy(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 memberCopy(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 memberCopy(IntPtr, array<Byte>, Int32, Int32)Security Critical. Copies data from an unmanaged memory pointer to a managed 8-bit unsigned integer array.
Public methodStatic memberCopy(IntPtr, array<Char>, Int32, Int32)Security Critical. Copies data from an unmanaged memory pointer to a managed character array.
Public methodStatic memberCopy(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 memberCopy(IntPtr, array<Int16>, Int32, Int32)Security Critical. Copies data from an unmanaged memory pointer to a managed 16-bit signed integer array.
Public methodStatic memberCopy(IntPtr, array<Int32>, Int32, Int32)Security Critical. Copies data from an unmanaged memory pointer to a managed 32-bit signed integer array.
Public methodStatic memberCopy(IntPtr, array<Int64>, Int32, Int32)Security Critical. Copies data from an unmanaged memory pointer to a managed 64-bit signed integer array.
Public methodStatic memberCopy(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 memberCopy(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 memberFinalReleaseComObjectSecurity Critical. Releases all references to a runtime callable wrapper (RCW) by setting its reference count to 0.
Public methodStatic memberFreeCoTaskMemSecurity Critical. Frees a block of memory allocated by the unmanaged COM task memory allocator.
Public methodStatic memberFreeHGlobalSecurity Critical. Frees memory previously allocated from the unmanaged memory of the process.
Public methodStatic memberGetComInterfaceForObjectSecurity Critical. Returns a pointer to an IUnknown interface that represents the specified interface on the specified object. Custom query interface access is enabled by default.
Public methodStatic memberGetDelegateForFunctionPointerSecurity Critical. Converts an unmanaged function pointer to a delegate.
Public methodStatic memberGetExceptionForHR(Int32)Security Critical. Converts the specified HRESULT error code to a corresponding Exception object.
Public methodStatic memberGetExceptionForHR(Int32, IntPtr)Security Critical. Converts the specified HRESULT error code to a corresponding Exception object, with additional error information passed in an [4dda6909-2d9a-4727-ae0c-b5f90dcfa447] interface for the exception object.
Public methodStatic memberGetFunctionPointerForDelegateSecurity Critical. Converts a delegate into a function pointer callable from unmanaged code.
Public methodStatic memberGetHRForExceptionSecurity Critical. Converts the specified exception to an HRESULT.
Public methodStatic memberGetHRForLastWin32ErrorSecurity Critical. Returns the HRESULT corresponding to the last error incurred by Win32 code executed using Marshal.
Public methodStatic memberGetIUnknownForObjectSecurity Critical. Returns an IUnknown interface from a managed object.
Public methodStatic memberGetLastWin32ErrorSecurity Critical. Returns the error code returned by the last unmanaged function called using platform invoke that has the DllImportAttribute::SetLastError flag set.
Public methodStatic memberGetNativeVariantForObjectSecurity Critical. Converts an object to a COM VARIANT.
Public methodStatic memberGetObjectForIUnknownSecurity Critical. Returns an instance of a type that represents a COM object by a pointer to its IUnknown interface.
Public methodStatic memberGetObjectForNativeVariantSecurity Critical. Converts a COM VARIANT to an object.
Public methodStatic memberGetUniqueObjectForIUnknownSecurity Critical. Creates a unique [7e542583-1e31-4e10-b523-8cf2f29cb4a4] (RCW) object for a given IUnknown interface.
Public methodStatic memberIsComObjectIndicates whether a specified object represents a COM object.
Public methodStatic memberPrelinkSecurity Critical. Executes one-time method setup tasks without calling the method.
Public methodStatic memberPrelinkAllSecurity Critical. Performs a pre-link check for all methods on a class.
Public methodStatic memberPtrToStringAnsi(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 memberPtrToStringAnsi(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 memberPtrToStringUni(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 memberPtrToStringUni(IntPtr, Int32)Security Critical. Copies a specified number of characters from a Unicode string stored in native heap to a managed String.
Public methodStatic memberPtrToStructure(IntPtr, Object)Security Critical. Marshals data from an unmanaged block of memory to a managed object.
Public methodStatic memberPtrToStructure(IntPtr, Type)Security Critical. Marshals data from an unmanaged block of memory to a newly allocated managed object of the specified type.
Public methodStatic memberQueryInterfaceSecurity Critical. Requests a pointer to a specified interface from a COM object.
Public methodStatic memberReadByte(IntPtr)Security Critical. Reads a single byte from an unmanaged pointer.
Public methodStatic memberReadByte(IntPtr, Int32)Security Critical. Reads a single byte at a given offset (or index) from an unmanaged pointer.
Public methodStatic memberReadInt16(IntPtr)Security Critical. Reads a 16-bit signed integer from the unmanaged memory.
Public methodStatic memberReadInt16(IntPtr, Int32)Security Critical. Reads a 16-bit signed integer from unmanaged memory.
Public methodStatic memberReadInt32(IntPtr)Security Critical. Reads a 32-bit signed integer from unmanaged memory.
Public methodStatic memberReadInt32(IntPtr, Int32)Security Critical. Reads a 32-bit signed integer from unmanaged memory.
Public methodStatic memberReadInt64(IntPtr)Security Critical. Reads a 64-bit signed integer from unmanaged memory.
Public methodStatic memberReadInt64(IntPtr, Int32)Security Critical. Reads a 64-bit signed integer from unmanaged memory.
Public methodStatic memberReadIntPtr(IntPtr)Security Critical. Reads a processor native sized integer from unmanaged memory.
Public methodStatic memberReadIntPtr(IntPtr, Int32)Security Critical. Reads a processor native sized integer from unmanaged memory.
Public methodStatic memberReleaseSecurity Critical. Decrements the reference count on the specified interface.
Public methodStatic memberReleaseComObjectSecurity Critical. Decrements the reference count of the specified [7e542583-1e31-4e10-b523-8cf2f29cb4a4] (RCW) associated with the specified COM object.
Public methodStatic memberSizeOf(Object)Returns the unmanaged size of an object in bytes.
Public methodStatic memberSizeOf(Type)Returns the size of an unmanaged type in bytes.
Public methodStatic memberStructureToPtrSecurity Critical. Marshals data from a managed object to an unmanaged block of memory.
Public methodStatic memberThrowExceptionForHR(Int32)Security Critical. Throws an exception with a specific failure HRESULT value.
Public methodStatic memberThrowExceptionForHR(Int32, IntPtr)Security Critical. Throws an exception with a specific failure HRESULT.
Public methodStatic memberUnsafeAddrOfPinnedArrayElementSecurity Critical. Gets the address of the element at the specified index inside the specified array.
Public methodStatic memberWriteByte(IntPtr, Byte)Security Critical. Writes a single byte value to unmanaged memory.
Public methodStatic memberWriteByte(IntPtr, Int32, Byte)Security Critical. Writes a single byte value to unmanaged memory.
Public methodStatic memberWriteInt16(IntPtr, Int16)Security Critical. Writes a 16-bit integer value to unmanaged memory.
Public methodStatic memberWriteInt16(IntPtr, Int32, Int16)Security Critical. Writes a 16-bit signed integer value into unmanaged memory.
Public methodStatic memberWriteInt32(IntPtr, Int32)Security Critical. Writes a 32-bit signed integer value to unmanaged memory.
Public methodStatic memberWriteInt32(IntPtr, Int32, Int32)Security Critical. Writes a 32-bit signed integer value into unmanaged memory.
Public methodStatic memberWriteInt64(IntPtr, Int64)Security Critical. Writes a 64-bit signed integer value to unmanaged memory.
Public methodStatic memberWriteInt64(IntPtr, Int32, Int64)Security Critical. Writes a 64-bit signed integer value to unmanaged memory.
Public methodStatic memberWriteIntPtrSecurity Critical. Writes a processor native sized integer value into unmanaged memory.
Top

  NameDescription
Public fieldStatic memberSystemDefaultCharSizeRepresents 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

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

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

Show:
© 2017 Microsoft