System.Runtime.InteropServices.Marshal: Method Members

The methods of System.Runtime.InteropServices.Marshal are listed below. For a list of all members, see the Marshal Members list.

See Also: Inherited members from System.Object

Public Methods

static
AddRef(IntPtr) : int

Increments the reference count on the specified interface.

static
AllocCoTaskMem(int) : IntPtr

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

static
AllocHGlobal(int) : IntPtr

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

static
AllocHGlobal(IntPtr) : IntPtr

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

static
BindToMoniker(string) : object

Gets an interface pointer identified by the specified moniker.

static
ChangeWrapperHandleStrength(object, bool)

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

static
Copy(byte[], int, IntPtr, int)

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

static
Copy(char[], int, IntPtr, int)

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

static
Copy(double[], int, IntPtr, int)

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

static
Copy(short[], int, IntPtr, int)

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

static
Copy(int[], int, IntPtr, int)

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

static
Copy(long[], int, IntPtr, int)

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

static
Copy(IntPtr, byte[], int, int)

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

static
Copy(IntPtr, char[], int, int)

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

static
Copy(IntPtr, double[], int, int)

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

static
Copy(IntPtr, short[], int, int)

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

static
Copy(IntPtr, int[], int, int)

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

static
Copy(IntPtr, long[], int, int)

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

static
Copy(IntPtr, IntPtr[], int, int)

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

static
Copy(IntPtr, float[], int, int)

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

static
Copy(IntPtr[], int, IntPtr, int)

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

static
Copy(float[], int, IntPtr, int)

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

static
CreateAggregatedObject(IntPtr, object) : IntPtr

Aggregates a managed object with the specified COM object.

static
CreateAggregatedObject<T>(IntPtr, T) : IntPtr
Documentation for this section has not yet been entered.
static
CreateWrapperOfType(object, Type) : object

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

static
CreateWrapperOfType<T,TWrapper>(T) : TWrapper
Documentation for this section has not yet been entered.
static
DestroyStructure(IntPtr, Type)

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

static
DestroyStructure<T>(IntPtr)

[Supported in the .NET Framework 4.5.1 only]

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

static
FinalReleaseComObject(object) : int

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

static
FreeBSTR(IntPtr)

Frees a BSTR using the COM tp://go.microsoft.com/fwlink/?LinkID=148633 function.

static
FreeCoTaskMem(IntPtr)

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

static
FreeHGlobal(IntPtr)

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

static
GenerateGuidForType(Type) : Guid

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

static
GenerateProgIdForType(Type) : string

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

static
GetActiveObject(string) : object

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

static
GetComInterfaceForObject(object, Type) : IntPtr

Returns a pointer to an tp://go.microsoft.com/fwlink/?LinkId=148003 interface that represents the specified interface on the specified object. Custom query interface access is enabled by default.

static
GetComInterfaceForObject<T,TInterface>(T) : IntPtr
Documentation for this section has not yet been entered.
static
GetComInterfaceForObjectInContext(object, Type) : IntPtr

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

static
GetComObjectData(object, object) : object

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

static
GetComSlotForMethodInfo(System.Reflection.MemberInfo) : int

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

static
GetDelegateForFunctionPointer(IntPtr, Type) : Delegate

Converts an unmanaged function pointer to a delegate.

static
GetDelegateForFunctionPointer<TDelegate>(IntPtr) : TDelegate

[Supported in the .NET Framework 4.5.1 only]

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

static
GetEndComSlot(Type) : int

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

static
GetExceptionCode() : int

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

static
GetExceptionForHR(int) : Exception

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

static
GetExceptionForHR(int, IntPtr) : Exception

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

static
GetExceptionPointers() : IntPtr

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

static
GetFunctionPointerForDelegate(Delegate) : IntPtr

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

static
GetFunctionPointerForDelegate<TDelegate>(TDelegate) : IntPtr
Documentation for this section has not yet been entered.
static
GetHINSTANCE(System.Reflection.Module) : IntPtr

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

static
GetHRForException(Exception) : int

Converts the specified exception to an HRESULT.

static
GetHRForLastWin32Error() : int

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

static
GetIDispatchForObject(object) : IntPtr

Returns an IDispatch interface from a managed object.

static
GetIDispatchForObjectInContext(object) : IntPtr

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

static
GetITypeInfoForType(Type) : IntPtr

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

static
GetIUnknownForObject(object) : IntPtr

Returns an tp://go.microsoft.com/fwlink/?LinkId=148003 interface from a managed object.

static
GetIUnknownForObjectInContext(object) : IntPtr

Returns an tp://go.microsoft.com/fwlink/?LinkId=148003 interface from a managed object, if the caller is in the same context as that object.

static
GetLastWin32Error() : int

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

static
GetManagedThunkForUnmanagedMethodPtr(IntPtr, IntPtr, int) : IntPtr

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

static
GetMethodInfoForComSlot(Type, int, ref ComMemberType) : System.Reflection.MemberInfo
Documentation for this section has not yet been entered.
static
GetNativeVariantForObject(object, IntPtr)

Converts an object to a COM VARIANT.

static
GetNativeVariantForObject<T>(T, IntPtr)
Documentation for this section has not yet been entered.
static
GetObjectForIUnknown(IntPtr) : object

Returns an instance of a type that represents a COM object by a pointer to its tp://go.microsoft.com/fwlink/?LinkId=148003 interface.

static
GetObjectForNativeVariant(IntPtr) : object

Converts a COM VARIANT to an object.

static
GetObjectForNativeVariant<T>(IntPtr) : T

[Supported in the .NET Framework 4.5.1 only]

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

static
GetObjectsForNativeVariants(IntPtr, int) : object[]

Converts an array of COM tp://go.microsoft.com/fwlink/?LinkId=148670 to an array of objects.

static
GetObjectsForNativeVariants<T>(IntPtr, int) : T[]

[Supported in the .NET Framework 4.5.1 only]

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

static
GetStartComSlot(Type) : int

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

static
GetThreadFromFiberCookie(int) : System.Threading.Thread

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

static
GetTypedObjectForIUnknown(IntPtr, Type) : object

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

static
GetTypeForITypeInfo(IntPtr) : Type

Converts an unmanaged ITypeInfo object into a managed Type object.

static
GetTypeInfoName(System.Runtime.InteropServices.ComTypes.ITypeInfo) : string

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

static
GetTypeInfoName(UCOMITypeInfo) : string

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

static
GetTypeLibGuid(System.Runtime.InteropServices.ComTypes.ITypeLib) : Guid

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

static
GetTypeLibGuid(UCOMITypeLib) : Guid

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

static
GetTypeLibGuidForAssembly(System.Reflection.Assembly) : Guid

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

static
GetTypeLibLcid(System.Runtime.InteropServices.ComTypes.ITypeLib) : int

Retrieves the LCID of a type library.

static
GetTypeLibLcid(UCOMITypeLib) : int

Retrieves the LCID of a type library.

static
GetTypeLibName(System.Runtime.InteropServices.ComTypes.ITypeLib) : string

Retrieves the name of a type library.

static
GetTypeLibName(UCOMITypeLib) : string

Retrieves the name of a type library.

static
GetTypeLibVersionForAssembly(System.Reflection.Assembly, out int, out int)
Documentation for this section has not yet been entered.
static
GetUniqueObjectForIUnknown(IntPtr) : object

Creates a unique Runtime Callable Wrapper (RCW) object for a given tp://go.microsoft.com/fwlink/?LinkId=148003 interface.

static
GetUnmanagedThunkForManagedMethodPtr(IntPtr, IntPtr, int) : IntPtr

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

static
IsComObject(object) : bool

Indicates whether a specified object represents a COM object.

static
IsTypeVisibleFromCom(Type) : bool

Indicates whether a type is visible to COM clients.

static
NumParamBytes(System.Reflection.MethodInfo) : int

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

static
OffsetOf(Type, string) : IntPtr

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

static
OffsetOf<T>(string) : IntPtr

[Supported in the .NET Framework 4.5.1 only]

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

static
Prelink(System.Reflection.MethodInfo)

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

static
PrelinkAll(Type)

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

static
PtrToStringAnsi(IntPtr) : string

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.

static
PtrToStringAnsi(IntPtr, int) : string

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

static
PtrToStringAuto(IntPtr) : string

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

static
PtrToStringAuto(IntPtr, int) : string

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

static
PtrToStringBSTR(IntPtr) : string

Allocates a managed string and copies a BSTR string stored in unmanaged memory into it.

static
PtrToStringUni(IntPtr) : string

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

static
PtrToStringUni(IntPtr, int) : string

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

static
PtrToStructure(IntPtr, object)

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

static
PtrToStructure(IntPtr, Type) : object

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

static
PtrToStructure<T>(IntPtr) : T

[Supported in the .NET Framework 4.5.1 only]

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

static
PtrToStructure<T>(IntPtr, T)
Documentation for this section has not yet been entered.
static
QueryInterface(IntPtr, ref Guid, out IntPtr) : int
Documentation for this section has not yet been entered.
static
ReadByte(IntPtr) : byte

Reads a single byte from unmanaged memory.

static
ReadByte(IntPtr, int) : byte

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

static
ReadByte(object, int) : byte

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

static
ReadInt16(IntPtr) : short

Reads a 16-bit signed integer from unmanaged memory.

static
ReadInt16(IntPtr, int) : short

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

static
ReadInt16(object, int) : short

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

static
ReadInt32(IntPtr) : int

Reads a 32-bit signed integer from unmanaged memory.

static
ReadInt32(IntPtr, int) : int

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

static
ReadInt32(object, int) : int

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

static
ReadInt64(IntPtr) : long

Reads a 64-bit signed integer from unmanaged memory.

static
ReadInt64(IntPtr, int) : long

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

static
ReadInt64(object, int) : long

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

static
ReadIntPtr(IntPtr) : IntPtr

Reads a processor native-sized integer from unmanaged memory.

static
ReadIntPtr(IntPtr, int) : IntPtr

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

static
ReadIntPtr(object, int) : IntPtr

Reads a processor native sized integer from unmanaged memory.

static
ReAllocCoTaskMem(IntPtr, int) : IntPtr

Resizes a block of memory previously allocated with Marshal.AllocCoTaskMem(int).

static
ReAllocHGlobal(IntPtr, IntPtr) : IntPtr

Resizes a block of memory previously allocated with Marshal.AllocHGlobal(IntPtr).

static
Release(IntPtr) : int

Decrements the reference count on the specified interface.

static
ReleaseComObject(object) : int

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

static
ReleaseThreadCache()

Releases the thread cache.

static
SecureStringToBSTR(System.Security.SecureString) : IntPtr

Allocates a BSTR and copies the contents of a managed System.Security.SecureString object into it.

static
SecureStringToCoTaskMemAnsi(System.Security.SecureString) : IntPtr

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

static
SecureStringToCoTaskMemUnicode(System.Security.SecureString) : IntPtr

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

static
SecureStringToGlobalAllocAnsi(System.Security.SecureString) : IntPtr

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

static
SecureStringToGlobalAllocUnicode(System.Security.SecureString) : IntPtr

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

static
SetComObjectData(object, object, object) : bool

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

static
SizeOf(object) : int

Returns the unmanaged size of an object in bytes.

static
SizeOf(Type) : int

Returns the size of an unmanaged type in bytes.

static
SizeOf<T>() : int

[Supported in the .NET Framework 4.5.1 only]

Returns the size of an unmanaged type in bytes.

static
SizeOf<T>(T) : int
Documentation for this section has not yet been entered.
static
StringToBSTR(string) : IntPtr

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

static
StringToCoTaskMemAnsi(string) : IntPtr

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

static
StringToCoTaskMemAuto(string) : IntPtr

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

static
StringToCoTaskMemUni(string) : IntPtr

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

static
StringToHGlobalAnsi(string) : IntPtr

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

static
StringToHGlobalAuto(string) : IntPtr

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

static
StringToHGlobalUni(string) : IntPtr

Copies the contents of a managed string into unmanaged memory.

static
StructureToPtr(object, IntPtr, bool)

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

static
StructureToPtr<T>(T, IntPtr, bool)
Documentation for this section has not yet been entered.
static
ThrowExceptionForHR(int)

Throws an exception with a specific failure HRESULT value.

static
ThrowExceptionForHR(int, IntPtr)

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

static
UnsafeAddrOfPinnedArrayElement(Array, int) : IntPtr

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

static
UnsafeAddrOfPinnedArrayElement<T>(T[], int) : IntPtr
Documentation for this section has not yet been entered.
static
WriteByte(IntPtr, byte)

Writes a single byte value to unmanaged memory.

static
WriteByte(IntPtr, int, byte)

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

static
WriteByte(object, int, byte)

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

static
WriteInt16(IntPtr, char)

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

static
WriteInt16(IntPtr, short)

Writes a 16-bit integer value to unmanaged memory.

static
WriteInt16(IntPtr, int, char)

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

static
WriteInt16(IntPtr, int, short)

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

static
WriteInt16(object, int, char)

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

static
WriteInt16(object, int, short)

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

static
WriteInt32(IntPtr, int)

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

static
WriteInt32(IntPtr, int, int)

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

static
WriteInt32(object, int, int)

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

static
WriteInt64(IntPtr, long)

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

static
WriteInt64(IntPtr, int, long)

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

static
WriteInt64(object, int, long)

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

static
WriteIntPtr(IntPtr, IntPtr)

Writes a processor native sized integer value into unmanaged memory.

static
WriteIntPtr(IntPtr, int, IntPtr)

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

static
WriteIntPtr(object, int, IntPtr)

Writes a processor native sized integer value to unmanaged memory.

static
ZeroFreeBSTR(IntPtr)

Frees a BSTR pointer that was allocated using the Marshal.SecureStringToBSTR(System.Security.SecureString) method.

static
ZeroFreeCoTaskMemAnsi(IntPtr)

Frees an unmanaged string pointer that was allocated using the Marshal.SecureStringToCoTaskMemAnsi(System.Security.SecureString) method.

static
ZeroFreeCoTaskMemUnicode(IntPtr)

Frees an unmanaged string pointer that was allocated using the Marshal.SecureStringToCoTaskMemUnicode(System.Security.SecureString) method.

static
ZeroFreeGlobalAllocAnsi(IntPtr)

Frees an unmanaged string pointer that was allocated using the Marshal.SecureStringToGlobalAllocAnsi(System.Security.SecureString) method.

static
ZeroFreeGlobalAllocUnicode(IntPtr)

Frees an unmanaged string pointer that was allocated using the Marshal.SecureStringToGlobalAllocUnicode(System.Security.SecureString) method.