Marshal Class
TOC
Collapse the table of content
Expand the table of content

Marshal Class

 

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.

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

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

public ref class Marshal abstract sealed 

NameDescription
System_CAPS_pubmethodSystem_CAPS_staticAddRef(IntPtr)

Increments the reference count on the specified interface.

System_CAPS_pubmethodSystem_CAPS_staticAllocCoTaskMem(Int32)

Allocates a block of memory of specified size from the COM task memory allocator.

System_CAPS_pubmethodSystem_CAPS_staticAllocHGlobal(Int32)

Allocates memory from the unmanaged memory of the process by using the specified number of bytes.

System_CAPS_pubmethodSystem_CAPS_staticAllocHGlobal(IntPtr)

Allocates memory from the unmanaged memory of the process by using the pointer to the specified number of bytes.

System_CAPS_pubmethodSystem_CAPS_staticAreComObjectsAvailableForCleanup()

Indicates whether runtime callable wrappers (RCWs) from any context are available for cleanup.

System_CAPS_pubmethodSystem_CAPS_staticBindToMoniker(String^)

Gets an interface pointer identified by the specified moniker.

System_CAPS_pubmethodSystem_CAPS_staticChangeWrapperHandleStrength(Object^, Boolean)

Changes the strength of an object's COM Callable Wrapper (CCW) handle.

System_CAPS_pubmethodSystem_CAPS_staticCleanupUnusedObjectsInCurrentContext()

Notifies the runtime to clean up all (RCWs) allocated in the current context.

System_CAPS_pubmethodSystem_CAPS_staticCopy(array<Byte>^, Int32, IntPtr, Int32)

Copies data from a one-dimensional, managed 8-bit unsigned integer array to an unmanaged memory pointer.

System_CAPS_pubmethodSystem_CAPS_staticCopy(array<Char>^, Int32, IntPtr, Int32)

Copies data from a one-dimensional, managed character array to an unmanaged memory pointer.

System_CAPS_pubmethodSystem_CAPS_staticCopy(array<Double>^, Int32, IntPtr, Int32)

Copies data from a one-dimensional, managed double-precision floating-point number array to an unmanaged memory pointer.

System_CAPS_pubmethodSystem_CAPS_staticCopy(array<Int16>^, Int32, IntPtr, Int32)

Copies data from a one-dimensional, managed 16-bit signed integer array to an unmanaged memory pointer.

System_CAPS_pubmethodSystem_CAPS_staticCopy(array<Int32>^, Int32, IntPtr, Int32)

Copies data from a one-dimensional, managed 32-bit signed integer array to an unmanaged memory pointer.

System_CAPS_pubmethodSystem_CAPS_staticCopy(array<Int64>^, Int32, IntPtr, Int32)

Copies data from a one-dimensional, managed 64-bit signed integer array to an unmanaged memory pointer.

System_CAPS_pubmethodSystem_CAPS_staticCopy(IntPtr, array<Byte>^, Int32, Int32)

Copies data from an unmanaged memory pointer to a managed 8-bit unsigned integer array.

System_CAPS_pubmethodSystem_CAPS_staticCopy(IntPtr, array<Char>^, Int32, Int32)

Copies data from an unmanaged memory pointer to a managed character array.

System_CAPS_pubmethodSystem_CAPS_staticCopy(IntPtr, array<Double>^, Int32, Int32)

Copies data from an unmanaged memory pointer to a managed double-precision floating-point number array.

System_CAPS_pubmethodSystem_CAPS_staticCopy(IntPtr, array<Int16>^, Int32, Int32)

Copies data from an unmanaged memory pointer to a managed 16-bit signed integer array.

System_CAPS_pubmethodSystem_CAPS_staticCopy(IntPtr, array<Int32>^, Int32, Int32)

Copies data from an unmanaged memory pointer to a managed 32-bit signed integer array.

System_CAPS_pubmethodSystem_CAPS_staticCopy(IntPtr, array<Int64>^, Int32, Int32)

Copies data from an unmanaged memory pointer to a managed 64-bit signed integer array.

System_CAPS_pubmethodSystem_CAPS_staticCopy(IntPtr, array<IntPtr>^, Int32, Int32)

Copies data from an unmanaged memory pointer to a managed IntPtr array.

System_CAPS_pubmethodSystem_CAPS_staticCopy(IntPtr, array<Single>^, Int32, Int32)

Copies data from an unmanaged memory pointer to a managed single-precision floating-point number array.

System_CAPS_pubmethodSystem_CAPS_staticCopy(array<IntPtr>^, Int32, IntPtr, Int32)

Copies data from a one-dimensional, managed IntPtr array to an unmanaged memory pointer.

System_CAPS_pubmethodSystem_CAPS_staticCopy(array<Single>^, Int32, IntPtr, Int32)

Copies data from a one-dimensional, managed single-precision floating-point number array to an unmanaged memory pointer.

System_CAPS_pubmethodSystem_CAPS_staticCreateAggregatedObject(IntPtr, Object^)

Aggregates a managed object with the specified COM object.

System_CAPS_pubmethodSystem_CAPS_staticCreateAggregatedObject<T>(IntPtr, T)

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

Aggregates a managed object of the specified type with the specified COM object.

System_CAPS_pubmethodSystem_CAPS_staticCreateWrapperOfType(Object^, Type^)

Wraps the specified COM object in an object of the specified type.

System_CAPS_pubmethodSystem_CAPS_staticCreateWrapperOfType<T, TWrapper>(T)

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

Wraps the specified COM object in an object of the specified type.

System_CAPS_pubmethodSystem_CAPS_staticDestroyStructure(IntPtr, Type^)

Frees all substructures that the specified unmanaged memory block points to.

System_CAPS_pubmethodSystem_CAPS_staticDestroyStructure<T>(IntPtr)

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

Frees all substructures of a specified type that the specified unmanaged memory block points to.

System_CAPS_pubmethodSystem_CAPS_staticFinalReleaseComObject(Object^)

Releases all references to a Runtime Callable Wrapper (RCW) by setting its reference count to 0.

System_CAPS_pubmethodSystem_CAPS_staticFreeBSTR(IntPtr)

Frees a BSTR using the COM SysFreeString function.

System_CAPS_pubmethodSystem_CAPS_staticFreeCoTaskMem(IntPtr)

Frees a block of memory allocated by the unmanaged COM task memory allocator.

System_CAPS_pubmethodSystem_CAPS_staticFreeHGlobal(IntPtr)

Frees memory previously allocated from the unmanaged memory of the process.

System_CAPS_pubmethodSystem_CAPS_staticGenerateGuidForType(Type^)

Returns the globally unique identifier (GUID) for the specified type, or generates a GUID using the algorithm used by the Type Library Exporter (Tlbexp.exe).

System_CAPS_pubmethodSystem_CAPS_staticGenerateProgIdForType(Type^)

Returns a programmatic identifier (ProgID) for the specified type.

System_CAPS_pubmethodSystem_CAPS_staticGetActiveObject(String^)

Obtains a running instance of the specified object from the running object table (ROT).

System_CAPS_pubmethodSystem_CAPS_staticGetComInterfaceForObject(Object^, Type^)

Returns a pointer to an IUnknown interface that represents the specified interface on the specified object. Custom query interface access is enabled by default.

System_CAPS_pubmethodSystem_CAPS_staticGetComInterfaceForObject(Object^, Type^, CustomQueryInterfaceMode)

Returns a pointer to an IUnknown interface that represents the specified interface on the specified object. Custom query interface access is controlled by the specified customization mode.

System_CAPS_pubmethodSystem_CAPS_staticGetComInterfaceForObject<T, TInterface>(T)

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

Returns a pointer to an IUnknown interface that represents the specified interface on an object of the specified type. Custom query interface access is enabled by default.

System_CAPS_pubmethodSystem_CAPS_staticGetComInterfaceForObjectInContext(Object^, Type^)

Returns an interface pointer that represents the specified interface for an object, if the caller is in the same context as that object.

System_CAPS_pubmethodSystem_CAPS_staticGetComObjectData(Object^, Object^)

Retrieves data that is referenced by the specified key from the specified COM object.

System_CAPS_pubmethodSystem_CAPS_staticGetComSlotForMethodInfo(MemberInfo^)

Retrieves the virtual function table (v-table or VTBL) slot for a specified System.Reflection::MemberInfo type when that type is exposed to COM.

System_CAPS_pubmethodSystem_CAPS_staticGetDelegateForFunctionPointer(IntPtr, Type^)

Converts an unmanaged function pointer to a delegate.

System_CAPS_pubmethodSystem_CAPS_staticGetDelegateForFunctionPointer<TDelegate>(IntPtr)

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

Converts an unmanaged function pointer to a delegate of a specified type.

System_CAPS_pubmethodSystem_CAPS_staticGetEndComSlot(Type^)

Retrieves the last slot in the virtual function table (v-table or VTBL) of a type when exposed to COM.

System_CAPS_pubmethodSystem_CAPS_staticGetExceptionCode()

Retrieves a code that identifies the type of the exception that occurred.

System_CAPS_pubmethodSystem_CAPS_staticGetExceptionForHR(Int32)

Converts the specified HRESULT error code to a corresponding Exception object.

System_CAPS_pubmethodSystem_CAPS_staticGetExceptionForHR(Int32, IntPtr)

Converts the specified HRESULT error code to a corresponding Exception object, with additional error information passed in an IErrorInfo interface for the exception object.

System_CAPS_pubmethodSystem_CAPS_staticGetExceptionPointers()

Retrieves a computer-independent description of an exception, and information about the state that existed for the thread when the exception occurred.

System_CAPS_pubmethodSystem_CAPS_staticGetFunctionPointerForDelegate(Delegate^)

Converts a delegate into a function pointer that is callable from unmanaged code.

System_CAPS_pubmethodSystem_CAPS_staticGetFunctionPointerForDelegate<TDelegate>(TDelegate)

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

Converts a delegate of a specified type to a function pointer that is callable from unmanaged code.

System_CAPS_pubmethodSystem_CAPS_staticGetHINSTANCE(Module^)

Returns the instance handle (HINSTANCE) for the specified module.

System_CAPS_pubmethodSystem_CAPS_staticGetHRForException(Exception^)

Converts the specified exception to an HRESULT.

System_CAPS_pubmethodSystem_CAPS_staticGetHRForLastWin32Error()

Returns the HRESULT corresponding to the last error incurred by Win32 code executed using Marshal.

System_CAPS_pubmethodSystem_CAPS_staticGetIDispatchForObject(Object^)

Returns an IDispatch interface from a managed object.

System_CAPS_pubmethodSystem_CAPS_staticGetIDispatchForObjectInContext(Object^)

Returns an IDispatch interface pointer from a managed object, if the caller is in the same context as that object.

System_CAPS_pubmethodSystem_CAPS_staticGetITypeInfoForType(Type^)

Returns a System.Runtime.InteropServices.ComTypes::ITypeInfo interface from a managed type.

System_CAPS_pubmethodSystem_CAPS_staticGetIUnknownForObject(Object^)

Returns an IUnknown interface from a managed object.

System_CAPS_pubmethodSystem_CAPS_staticGetIUnknownForObjectInContext(Object^)

Returns an IUnknown interface from a managed object, if the caller is in the same context as that object.

System_CAPS_pubmethodSystem_CAPS_staticGetLastWin32Error()

Returns the error code returned by the last unmanaged function that was called using platform invoke that has the DllImportAttribute::SetLastError flag set.

System_CAPS_pubmethodSystem_CAPS_staticGetManagedThunkForUnmanagedMethodPtr(IntPtr, IntPtr, Int32)

Obsolete.Gets a pointer to a runtime-generated function that marshals a call from managed to unmanaged code.

System_CAPS_pubmethodSystem_CAPS_staticGetMethodInfoForComSlot(Type^, Int32, ComMemberType%)

Retrieves a MemberInfo object for the specified virtual function table (v-table or VTBL) slot.

System_CAPS_pubmethodSystem_CAPS_staticGetNativeVariantForObject(Object^, IntPtr)

Converts an object to a COM VARIANT.

System_CAPS_pubmethodSystem_CAPS_staticGetNativeVariantForObject<T>(T, IntPtr)

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

Converts an object of a specified type to a COM VARIANT.

System_CAPS_pubmethodSystem_CAPS_staticGetObjectForIUnknown(IntPtr)

Returns an instance of a type that represents a COM object by a pointer to its IUnknown interface.

System_CAPS_pubmethodSystem_CAPS_staticGetObjectForNativeVariant(IntPtr)

Converts a COM VARIANT to an object.

System_CAPS_pubmethodSystem_CAPS_staticGetObjectForNativeVariant<T>(IntPtr)

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

Converts a COM VARIANT to an object of a specified type.

System_CAPS_pubmethodSystem_CAPS_staticGetObjectsForNativeVariants(IntPtr, Int32)

Converts an array of COM VARIANTs to an array of objects.

System_CAPS_pubmethodSystem_CAPS_staticGetObjectsForNativeVariants<T>(IntPtr, Int32)

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

Converts an array of COM VARIANTs to an array of a specified type.

System_CAPS_pubmethodSystem_CAPS_staticGetStartComSlot(Type^)

Gets the first slot in the virtual function table (v-table or VTBL) that contains user-defined methods.

System_CAPS_pubmethodSystem_CAPS_staticGetThreadFromFiberCookie(Int32)

Obsolete.Converts a fiber cookie into the corresponding System.Threading::Thread instance.

System_CAPS_pubmethodSystem_CAPS_staticGetTypedObjectForIUnknown(IntPtr, Type^)

Returns a managed object of a specified type that represents a COM object.

System_CAPS_pubmethodSystem_CAPS_staticGetTypeForITypeInfo(IntPtr)

Converts an unmanaged ITypeInfo object into a managed System::Type object.

System_CAPS_pubmethodSystem_CAPS_staticGetTypeFromCLSID(Guid)

Returns the type associated with the specified class identifier (CLSID).

System_CAPS_pubmethodSystem_CAPS_staticGetTypeInfoName(ITypeInfo^)

Retrieves the name of the type represented by an ITypeInfo object.

System_CAPS_pubmethodSystem_CAPS_staticGetTypeInfoName(UCOMITypeInfo^)

Obsolete.Retrieves the name of the type represented by an ITypeInfo object.

System_CAPS_pubmethodSystem_CAPS_staticGetTypeLibGuid(ITypeLib^)

Retrieves the library identifier (LIBID) of a type library.

System_CAPS_pubmethodSystem_CAPS_staticGetTypeLibGuid(UCOMITypeLib^)

Obsolete.Retrieves the library identifier (LIBID) of a type library.

System_CAPS_pubmethodSystem_CAPS_staticGetTypeLibGuidForAssembly(Assembly^)

Retrieves the library identifier (LIBID) that is assigned to a type library when it was exported from the specified assembly.

System_CAPS_pubmethodSystem_CAPS_staticGetTypeLibLcid(ITypeLib^)

Retrieves the LCID of a type library.

System_CAPS_pubmethodSystem_CAPS_staticGetTypeLibLcid(UCOMITypeLib^)

Obsolete.Retrieves the LCID of a type library.

System_CAPS_pubmethodSystem_CAPS_staticGetTypeLibName(ITypeLib^)

Retrieves the name of a type library.

System_CAPS_pubmethodSystem_CAPS_staticGetTypeLibName(UCOMITypeLib^)

Obsolete.Retrieves the name of a type library.

System_CAPS_pubmethodSystem_CAPS_staticGetTypeLibVersionForAssembly(Assembly^, Int32%, Int32%)

Retrieves the version number of a type library that will be exported from the specified assembly.

System_CAPS_pubmethodSystem_CAPS_staticGetUniqueObjectForIUnknown(IntPtr)

Creates a unique Runtime Callable Wrapper (RCW) object for a given IUnknown interface.

System_CAPS_pubmethodSystem_CAPS_staticGetUnmanagedThunkForManagedMethodPtr(IntPtr, IntPtr, Int32)

Obsolete.Gets a pointer to a runtime-generated function that marshals a call from unmanaged to managed code.

System_CAPS_pubmethodSystem_CAPS_staticIsComObject(Object^)

Indicates whether a specified object represents a COM object.

System_CAPS_pubmethodSystem_CAPS_staticIsTypeVisibleFromCom(Type^)

Indicates whether a type is visible to COM clients.

System_CAPS_pubmethodSystem_CAPS_staticNumParamBytes(MethodInfo^)

Calculates the number of bytes in unmanaged memory that are required to hold the parameters for the specified method.

System_CAPS_pubmethodSystem_CAPS_staticOffsetOf(Type^, String^)

Returns the field offset of the unmanaged form of the managed class.

System_CAPS_pubmethodSystem_CAPS_staticOffsetOf<T>(String^)

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

Returns the field offset of the unmanaged form of a specified managed class.

System_CAPS_pubmethodSystem_CAPS_staticPrelink(MethodInfo^)

Executes one-time method setup tasks without calling the method.

System_CAPS_pubmethodSystem_CAPS_staticPrelinkAll(Type^)

Performs a pre-link check for all methods on a class.

System_CAPS_pubmethodSystem_CAPS_staticPtrToStringAnsi(IntPtr)

Copies all characters up to the first null character from an unmanaged ANSI string to a managed String, and widens each ANSI character to Unicode.

System_CAPS_pubmethodSystem_CAPS_staticPtrToStringAnsi(IntPtr, Int32)

Allocates a managed String, copies a specified number of characters from an unmanaged ANSI string into it, and widens each ANSI character to Unicode.

System_CAPS_pubmethodSystem_CAPS_staticPtrToStringAuto(IntPtr)

Allocates a managed String and copies all characters up to the first null character from a string stored in unmanaged memory into it.

System_CAPS_pubmethodSystem_CAPS_staticPtrToStringAuto(IntPtr, Int32)

Allocates a managed String and copies the specified number of characters from a string stored in unmanaged memory into it.

System_CAPS_pubmethodSystem_CAPS_staticPtrToStringBSTR(IntPtr)

Allocates a managed String and copies a binary string (BSTR) stored in unmanaged memory into it.

System_CAPS_pubmethodSystem_CAPS_staticPtrToStringUni(IntPtr)

Allocates a managed String and copies all characters up to the first null character from an unmanaged Unicode string into it.

System_CAPS_pubmethodSystem_CAPS_staticPtrToStringUni(IntPtr, Int32)

Allocates a managed String and copies a specified number of characters from an unmanaged Unicode string into it.

System_CAPS_pubmethodSystem_CAPS_staticPtrToStructure(IntPtr, Object^)

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

System_CAPS_pubmethodSystem_CAPS_staticPtrToStructure(IntPtr, Type^)

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

System_CAPS_pubmethodSystem_CAPS_staticPtrToStructure<T>(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.

System_CAPS_pubmethodSystem_CAPS_staticPtrToStructure<T>(IntPtr, T)

[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.

System_CAPS_pubmethodSystem_CAPS_staticQueryInterface(IntPtr, Guid%, IntPtr%)

Requests a pointer to a specified interface from a COM object.

System_CAPS_pubmethodSystem_CAPS_staticReadByte(IntPtr)

Reads a single byte from unmanaged memory.

System_CAPS_pubmethodSystem_CAPS_staticReadByte(IntPtr, Int32)

Reads a single byte at a given offset (or index) from unmanaged memory.

System_CAPS_pubmethodSystem_CAPS_staticReadByte(Object^, Int32)

Reads a single byte at a given offset (or index) from unmanaged memory.

System_CAPS_pubmethodSystem_CAPS_staticReadInt16(IntPtr)

Reads a 16-bit signed integer from unmanaged memory.

System_CAPS_pubmethodSystem_CAPS_staticReadInt16(IntPtr, Int32)

Reads a 16-bit signed integer at a given offset from unmanaged memory.

System_CAPS_pubmethodSystem_CAPS_staticReadInt16(Object^, Int32)

Reads a 16-bit signed integer at a given offset from unmanaged memory.

System_CAPS_pubmethodSystem_CAPS_staticReadInt32(IntPtr)

Reads a 32-bit signed integer from unmanaged memory.

System_CAPS_pubmethodSystem_CAPS_staticReadInt32(IntPtr, Int32)

Reads a 32-bit signed integer at a given offset from unmanaged memory.

System_CAPS_pubmethodSystem_CAPS_staticReadInt32(Object^, Int32)

Reads a 32-bit signed integer at a given offset from unmanaged memory.

System_CAPS_pubmethodSystem_CAPS_staticReadInt64(IntPtr)

Reads a 64-bit signed integer from unmanaged memory.

System_CAPS_pubmethodSystem_CAPS_staticReadInt64(IntPtr, Int32)

Reads a 64-bit signed integer at a given offset from unmanaged memory.

System_CAPS_pubmethodSystem_CAPS_staticReadInt64(Object^, Int32)

Reads a 64-bit signed integer at a given offset from unmanaged memory.

System_CAPS_pubmethodSystem_CAPS_staticReadIntPtr(IntPtr)

Reads a processor native-sized integer from unmanaged memory.

System_CAPS_pubmethodSystem_CAPS_staticReadIntPtr(IntPtr, Int32)

Reads a processor native sized integer at a given offset from unmanaged memory.

System_CAPS_pubmethodSystem_CAPS_staticReadIntPtr(Object^, Int32)

Reads a processor native sized integer from unmanaged memory.

System_CAPS_pubmethodSystem_CAPS_staticReAllocCoTaskMem(IntPtr, Int32)

Resizes a block of memory previously allocated with AllocCoTaskMem.

System_CAPS_pubmethodSystem_CAPS_staticReAllocHGlobal(IntPtr, IntPtr)

Resizes a block of memory previously allocated with AllocHGlobal.

System_CAPS_pubmethodSystem_CAPS_staticRelease(IntPtr)

Decrements the reference count on the specified interface.

System_CAPS_pubmethodSystem_CAPS_staticReleaseComObject(Object^)

Decrements the reference count of the specified Runtime Callable Wrapper (RCW) associated with the specified COM object.

System_CAPS_pubmethodSystem_CAPS_staticReleaseThreadCache()

Obsolete.Releases the thread cache.

System_CAPS_pubmethodSystem_CAPS_staticSecureStringToBSTR(SecureString^)

Allocates an unmanaged binary string (BSTR) and copies the contents of a managed SecureString object into it.

System_CAPS_pubmethodSystem_CAPS_staticSecureStringToCoTaskMemAnsi(SecureString^)

Copies the contents of a managed SecureString object to a block of memory allocated from the unmanaged COM task allocator.

System_CAPS_pubmethodSystem_CAPS_staticSecureStringToCoTaskMemUnicode(SecureString^)

Copies the contents of a managed SecureString object to a block of memory allocated from the unmanaged COM task allocator.

System_CAPS_pubmethodSystem_CAPS_staticSecureStringToGlobalAllocAnsi(SecureString^)

Copies the contents of a managed SecureString into unmanaged memory, converting into ANSI format as it copies.

System_CAPS_pubmethodSystem_CAPS_staticSecureStringToGlobalAllocUnicode(SecureString^)

Copies the contents of a managed SecureString object into unmanaged memory.

System_CAPS_pubmethodSystem_CAPS_staticSetComObjectData(Object^, Object^, Object^)

Sets data referenced by the specified key in the specified COM object.

System_CAPS_pubmethodSystem_CAPS_staticSizeOf(Object^)

Returns the unmanaged size of an object in bytes.

System_CAPS_pubmethodSystem_CAPS_staticSizeOf(Type^)

Returns the size of an unmanaged type in bytes.

System_CAPS_pubmethodSystem_CAPS_staticSizeOf<T>()

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

Returns the size of an unmanaged type in bytes.

System_CAPS_pubmethodSystem_CAPS_staticSizeOf<T>(T)

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

Returns the unmanaged size of an object of a specified type in bytes.

System_CAPS_pubmethodSystem_CAPS_staticStringToBSTR(String^)

Allocates a BSTR and copies the contents of a managed String into it.

System_CAPS_pubmethodSystem_CAPS_staticStringToCoTaskMemAnsi(String^)

Copies the contents of a managed String to a block of memory allocated from the unmanaged COM task allocator.

System_CAPS_pubmethodSystem_CAPS_staticStringToCoTaskMemAuto(String^)

Copies the contents of a managed String to a block of memory allocated from the unmanaged COM task allocator.

System_CAPS_pubmethodSystem_CAPS_staticStringToCoTaskMemUni(String^)

Copies the contents of a managed String to a block of memory allocated from the unmanaged COM task allocator.

System_CAPS_pubmethodSystem_CAPS_staticStringToHGlobalAnsi(String^)

Copies the contents of a managed String into unmanaged memory, converting into ANSI format as it copies.

System_CAPS_pubmethodSystem_CAPS_staticStringToHGlobalAuto(String^)

Copies the contents of a managed String into unmanaged memory, converting into ANSI format if required.

System_CAPS_pubmethodSystem_CAPS_staticStringToHGlobalUni(String^)

Copies the contents of a managed String into unmanaged memory.

System_CAPS_pubmethodSystem_CAPS_staticStructureToPtr(Object^, IntPtr, Boolean)

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

System_CAPS_pubmethodSystem_CAPS_staticStructureToPtr<T>(T, IntPtr, Boolean)

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

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

System_CAPS_pubmethodSystem_CAPS_staticThrowExceptionForHR(Int32)

Throws an exception with a specific failure HRESULT value.

System_CAPS_pubmethodSystem_CAPS_staticThrowExceptionForHR(Int32, IntPtr)

Throws an exception with a specific failure HRESULT, based on the specified IErrorInfo interface.

System_CAPS_pubmethodSystem_CAPS_staticUnsafeAddrOfPinnedArrayElement(Array^, Int32)

Gets the address of the element at the specified index inside the specified array.

System_CAPS_pubmethodSystem_CAPS_staticUnsafeAddrOfPinnedArrayElement<T>(array<T>^, Int32)

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

Gets the address of the element at the specified index in an array of a specified type.

System_CAPS_pubmethodSystem_CAPS_staticWriteByte(IntPtr, Byte)

Writes a single byte value to unmanaged memory.

System_CAPS_pubmethodSystem_CAPS_staticWriteByte(IntPtr, Int32, Byte)

Writes a single byte value to unmanaged memory at a specified offset.

System_CAPS_pubmethodSystem_CAPS_staticWriteByte(Object^, Int32, Byte)

Writes a single byte value to unmanaged memory at a specified offset.

System_CAPS_pubmethodSystem_CAPS_staticWriteInt16(IntPtr, Char)

Writes a character as a 16-bit integer value to unmanaged memory.

System_CAPS_pubmethodSystem_CAPS_staticWriteInt16(IntPtr, Int16)

Writes a 16-bit integer value to unmanaged memory.

System_CAPS_pubmethodSystem_CAPS_staticWriteInt16(IntPtr, Int32, Char)

Writes a 16-bit signed integer value to unmanaged memory at a specified offset.

System_CAPS_pubmethodSystem_CAPS_staticWriteInt16(IntPtr, Int32, Int16)

Writes a 16-bit signed integer value into unmanaged memory at a specified offset.

System_CAPS_pubmethodSystem_CAPS_staticWriteInt16(Object^, Int32, Char)

Writes a 16-bit signed integer value to unmanaged memory at a specified offset.

System_CAPS_pubmethodSystem_CAPS_staticWriteInt16(Object^, Int32, Int16)

Writes a 16-bit signed integer value to unmanaged memory at a specified offset.

System_CAPS_pubmethodSystem_CAPS_staticWriteInt32(IntPtr, Int32)

Writes a 32-bit signed integer value to unmanaged memory.

System_CAPS_pubmethodSystem_CAPS_staticWriteInt32(IntPtr, Int32, Int32)

Writes a 32-bit signed integer value into unmanaged memory at a specified offset.

System_CAPS_pubmethodSystem_CAPS_staticWriteInt32(Object^, Int32, Int32)

Writes a 32-bit signed integer value to unmanaged memory at a specified offset.

System_CAPS_pubmethodSystem_CAPS_staticWriteInt64(IntPtr, Int32, Int64)

Writes a 64-bit signed integer value to unmanaged memory at a specified offset.

System_CAPS_pubmethodSystem_CAPS_staticWriteInt64(IntPtr, Int64)

Writes a 64-bit signed integer value to unmanaged memory.

System_CAPS_pubmethodSystem_CAPS_staticWriteInt64(Object^, Int32, Int64)

Writes a 64-bit signed integer value to unmanaged memory at a specified offset.

System_CAPS_pubmethodSystem_CAPS_staticWriteIntPtr(IntPtr, Int32, IntPtr)

Writes a processor native-sized integer value to unmanaged memory at a specified offset.

System_CAPS_pubmethodSystem_CAPS_staticWriteIntPtr(IntPtr, IntPtr)

Writes a processor native sized integer value into unmanaged memory.

System_CAPS_pubmethodSystem_CAPS_staticWriteIntPtr(Object^, Int32, IntPtr)

Writes a processor native sized integer value to unmanaged memory.

System_CAPS_pubmethodSystem_CAPS_staticZeroFreeBSTR(IntPtr)

Frees a BSTR pointer that was allocated using the SecureStringToBSTR method.

System_CAPS_pubmethodSystem_CAPS_staticZeroFreeCoTaskMemAnsi(IntPtr)

Frees an unmanaged string pointer that was allocated using the SecureStringToCoTaskMemAnsi method.

System_CAPS_pubmethodSystem_CAPS_staticZeroFreeCoTaskMemUnicode(IntPtr)

Frees an unmanaged string pointer that was allocated using the SecureStringToCoTaskMemUnicode method.

System_CAPS_pubmethodSystem_CAPS_staticZeroFreeGlobalAllocAnsi(IntPtr)

Frees an unmanaged string pointer that was allocated using the SecureStringToGlobalAllocAnsi method.

System_CAPS_pubmethodSystem_CAPS_staticZeroFreeGlobalAllocUnicode(IntPtr)

Frees an unmanaged string pointer that was allocated using the SecureStringToGlobalAllocUnicode method.

NameDescription
System_CAPS_pubfieldSystem_CAPS_staticSystemDefaultCharSize

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.

System_CAPS_pubfieldSystem_CAPS_staticSystemMaxDBCSCharSize

Represents the maximum size of a double byte character set (DBCS) size, in bytes, for the current operating system. This field is read-only.

The static methods defined on the Marshal class are essential to working with unmanaged code. Most methods defined in this class are typically used by developers who want to provide a bridge between the managed and unmanaged programming models. For example, the StringToHGlobalAnsi method copies ANSI characters from a specified string (in the managed heap) to a buffer in the unmanaged heap. It also allocates the target heap of the right size.

The common language runtime provides specific marshaling capabilities. For details on marshaling behavior, see Interop Marshaling.

The Read and Write methods in the Marshal class support both aligned and unaligned access.

The following example shows how to use various methods defined by the Marshal class.

using namespace System;
using namespace System::Runtime::InteropServices;

public value struct Point
{
public:
    property int X;
    property int Y;
};
extern bool CloseHandle(IntPtr h);

int main()
{
    // Demonstrate the use of public static fields of the Marshal
    // class.
    Console::WriteLine(
        "SystemDefaultCharSize={0},SystemMaxDBCSCharSize={1}",
        Marshal::SystemDefaultCharSize,
        Marshal::SystemMaxDBCSCharSize);

    // Demonstrate the use of the SizeOf method of the Marshal
    // class.
    Console::WriteLine("Number of bytes needed by a Point object: {0}",
        Marshal::SizeOf(Point::typeid));
    Point point;
    Console::WriteLine("Number of bytes needed by a Point object: {0}",
        Marshal::SizeOf(point));

    // Demonstrate how to call GlobalAlloc and 
    // GlobalFree using the Marshal class.
    IntPtr hglobal = Marshal::AllocHGlobal(100);
    Marshal::FreeHGlobal(hglobal);

    // Demonstrate how to use the Marshal class to get the Win32
    // error code when a Win32 method fails.
    bool isCloseHandleSuccess = CloseHandle(IntPtr(-1));
    if (!isCloseHandleSuccess)
    {
        Console::WriteLine(
            "CloseHandle call failed with an error code of: {0}",
            Marshal::GetLastWin32Error());
    }
};

// This is a platform invoke prototype. SetLastError is true,
// which allows the GetLastWin32Error method of the Marshal class
// to work correctly.    
[DllImport("Kernel32", ExactSpelling = true, SetLastError = true)]
extern bool CloseHandle(IntPtr h);

// This code produces the following output.
// 
// SystemDefaultCharSize=2, SystemMaxDBCSCharSize=1
// Number of bytes needed by a Point object: 8
// Number of bytes needed by a Point object: 8
// CloseHandle call failed with an error code of: 6

Universal Windows Platform
Available since 4.5
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1

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

Return to top
Show:
© 2016 Microsoft