Marshal Members
.NET Framework 3.5
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.
The Marshal type exposes the following members.
| Name | Description | |
|---|---|---|
|
AddRef | Increments the reference count on the specified interface. |
|
AllocCoTaskMem | Allocates a block of memory of specified size from the COM task memory allocator. |
|
AllocHGlobal | Overloaded. Allocates a block of memory using LocalAlloc. |
|
BindToMoniker | Gets an interface pointer identified by the specified moniker. |
|
ChangeWrapperHandleStrength | Changes the strength of a COM callable wrapper's (CCW) handle on the object it contains. |
|
Copy | Overloaded. Copies data from a managed array to an unmanaged memory pointer, or from an unmanaged memory pointer to a managed array. |
|
CreateAggregatedObject | Aggregates a managed object with the specified COM object. |
|
CreateWrapperOfType | Wraps the specified COM object in an object of the specified type. |
|
DestroyStructure | Frees all substructures pointed to by the specified unmanaged memory block. |
|
FinalReleaseComObject | Releases all references to a runtime callable wrapper (RCW) by setting the reference count of the supplied RCW to 0. |
|
FreeBSTR | Frees a BSTR using SysFreeString. |
|
FreeCoTaskMem | Frees a block of memory allocated by the unmanaged COM task memory allocator with Marshal.AllocCoTaskMem. |
|
FreeHGlobal | Frees memory previously allocated from the unmanaged memory of the process with AllocHGlobal. |
|
GenerateGuidForType | 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). |
|
GenerateProgIdForType | Returns a programmatic identifier (ProgID) for the specified type. |
|
GetActiveObject | Obtains a running instance of the specified object from the Running Object Table (ROT). |
|
GetComInterfaceForObject | Returns an interface pointer that represents the specified interface for an object. |
|
GetComInterfaceForObjectInContext | Returns an interface pointer that represents the specified interface for an object, if the caller is in the same context as that object. |
|
GetComObjectData | Gets data referenced by the specified key from the specified COM object. |
|
GetComSlotForMethodInfo | Gets the virtual function table (VTBL) slot for a specified System.Reflection.MemberInfo when exposed to COM. |
|
GetDelegateForFunctionPointer | Converts an unmanaged function pointer to a delegate. |
|
GetEndComSlot | Gets the last slot in the virtual function table (VTBL) of a type when exposed to COM. |
|
GetExceptionCode | Retrieves a code that identifies the type of the exception that occurred. |
|
GetExceptionForHR | Overloaded. Converts an HRESULT error code to a corresponding Exception object. |
|
GetExceptionPointers | Retrieves a computer-independent description of an exception, and information about the state that existed for the thread when the exception occurred. |
|
GetFunctionPointerForDelegate | Converts a delegate into a function pointer callable from unmanaged code. |
|
GetHINSTANCE | Returns the instance handle (HINSTANCE) for the specified module. |
|
GetHRForException | Converts the specified exception to an HRESULT. |
|
GetHRForLastWin32Error | Returns the HRESULT corresponding to the last error incurred by Win32 code executed using Marshal. |
|
GetIDispatchForObject | Returns an IDispatch interface from a managed object. |
|
GetIDispatchForObjectInContext | Returns an IDispatch interface pointer from a managed object, if the caller is in the same context as that object. |
|
GetITypeInfoForType | Returns an ITypeInfo interface from a managed type. |
|
GetIUnknownForObject | Returns an IUnknown interface from a managed object. |
|
GetIUnknownForObjectInContext | Returns an IUnknown interface from a managed object, if the caller is in the same context as that object. |
|
GetLastWin32Error | Returns the error code returned by the last unmanaged function called using platform invoke that has the DllImportAttribute.SetLastError flag set. |
|
GetManagedThunkForUnmanagedMethodPtr | Obsolete. Gets a pointer to a thunk that marshals a call from managed to unmanaged code. |
|
GetMethodInfoForComSlot | Retrieves MethodInfo for the specified virtual function table (VTBL) slot. |
|
GetNativeVariantForObject | Converts an object to a COM VARIANT. |
|
GetObjectForIUnknown | Returns an instance of a type that represents a COM object by a pointer to its IUnknown interface. |
|
GetObjectForNativeVariant | Converts a COM VARIANT to an object. |
|
GetObjectsForNativeVariants | Converts an array of COM VARIANTs to an array of objects. |
|
GetStartComSlot | Gets the first slot in the virtual function table (VTBL) that contains user defined methods. |
|
GetThreadFromFiberCookie | Obsolete. Converts a fiber cookie into the corresponding System.Threading.Thread instance. |
|
GetTypedObjectForIUnknown | Returns a managed object of a specified type that represents a COM object. |
|
GetTypeForITypeInfo | Converts an ITypeInfo into a managed Type object. |
|
GetTypeInfoName | Overloaded. Retrieves the name of the type represented by an ITypeInfo. |
|
GetTypeLibGuid | Overloaded. Retrieves the library identifier (LIBID) of a type library. |
|
GetTypeLibGuidForAssembly | Retrieves the library identifier (LIBID) that is assigned to a type library when it was exported from the specified assembly. |
|
GetTypeLibLcid | Overloaded. Retrieves the LCID of a type library. |
|
GetTypeLibName | Overloaded. Retrieves the name of a type library. |
|
GetTypeLibVersionForAssembly | Retrieves the version number of a type library that will be exported from the specified assembly. |
|
GetUniqueObjectForIUnknown | Creates a unique runtime callable wrapper (RCW) object for a given IUnknown. |
|
GetUnmanagedThunkForManagedMethodPtr | Obsolete. Gets a pointer to a thunk that marshals a call from unmanaged to managed code. |
|
IsComObject | Indicates whether a specified object represents a COM object. |
|
IsTypeVisibleFromCom | Indicates whether a type is visible to COM clients. |
|
NumParamBytes | Calculates the number of bytes in unmanaged memory that are required to hold the parameters for the specified method. |
|
OffsetOf | Returns the field offset of the unmanaged form of the managed class. |
|
Prelink | Executes one-time method setup tasks without calling the method. |
|
PrelinkAll | Performs a pre-link check for all methods on a class. |
|
PtrToStringAnsi | Overloaded. Allocates a managed String and copies all or part of an unmanaged ANSI string into it. |
|
PtrToStringAuto | Overloaded. Allocates a managed String and copies a specified number of characters from an unmanaged string into it. |
|
PtrToStringBSTR | Allocates a managed String and copies a BSTR string stored in unmanaged memory into it. |
|
PtrToStringUni | Overloaded. Allocates a managed String and copies a specified number of characters from an unmanaged Unicode string into it. |
|
PtrToStructure | Overloaded. Marshals data from an unmanaged block of memory to a managed object. |
|
QueryInterface | Requests a pointer to a specified interface from a COM object. |
|
ReadByte | Overloaded. Reads a single byte from an unmanaged pointer. Reading from unaligned memory locations is supported. |
|
ReadInt16 | Overloaded. Reads a 16-bit signed integer from unmanaged memory. Reading from unaligned memory locations is supported. |
|
ReadInt32 | Overloaded. Reads a 32-bit signed integer from unmanaged memory. Reading from unaligned memory locations is supported. |
|
ReadInt64 | Overloaded. Reads a 64-bit signed integer from unmanaged memory. Reading from unaligned memory locations is supported. |
|
ReadIntPtr | Overloaded. Reads a processor native sized integer from unmanaged memory. Reading from unaligned memory locations is supported. |
|
ReAllocCoTaskMem | Resizes a block of memory previously allocated with AllocCoTaskMem. |
|
ReAllocHGlobal | Resizes a block of memory previously allocated with AllocHGlobal. |
|
Release | Decrements the reference count on the specified interface. |
|
ReleaseComObject | Decrements the reference count of the supplied runtime callable wrapper. |
|
ReleaseThreadCache | Obsolete. Releases the thread cache. |
|
SecureStringToBSTR | Allocates a BSTR and copies the contents of a managed SecureString object into it. |
|
SecureStringToCoTaskMemAnsi | Copies the contents of a managed SecureString object to a block of memory allocated from the unmanaged COM task allocator. |
|
SecureStringToCoTaskMemUnicode | Copies the contents of a managed SecureString object to a block of memory allocated from the unmanaged COM task allocator. |
|
SecureStringToGlobalAllocAnsi | Copies the contents of a managed SecureString into unmanaged memory, converting into ANSI format as it copies. |
|
SecureStringToGlobalAllocUnicode | Copies the contents of a managed SecureString object into unmanaged memory. |
|
SetComObjectData | Sets data referenced by the specified key in the specified COM object. |
|
SizeOf | Overloaded. Returns the unmanaged size, in bytes, of a class using Marshal. |
|
StringToBSTR | Allocates a BSTR and copies the contents of a managed String into it. |
|
StringToCoTaskMemAnsi | Copies the contents of a managed String to a block of memory allocated from the unmanaged COM task allocator. |
|
StringToCoTaskMemAuto | Copies the contents of a managed String to a block of memory allocated from the unmanaged COM task allocator. |
|
StringToCoTaskMemUni | Copies the contents of a managed String to a block of memory allocated from the unmanaged COM task allocator. |
|
StringToHGlobalAnsi | Copies the contents of a managed String into unmanaged memory, converting into ANSI format as it copies. |
|
StringToHGlobalAuto | Copies the contents of a managed String into unmanaged memory, converting into ANSI format if required. |
|
StringToHGlobalUni | Copies the contents of a managed String into unmanaged memory. |
|
StructureToPtr | Marshals data from a managed object to an unmanaged block of memory. |
|
ThrowExceptionForHR | Overloaded. Throws an exception with a specific failure HRESULT value. |
|
UnsafeAddrOfPinnedArrayElement | Gets the address of the element at the specified index inside the specified array. |
|
WriteByte | Overloaded. Writes a single byte value to unmanaged memory. |
|
WriteInt16 | Overloaded. Writes a 16-bit signed integer value to unmanaged memory. Writing to unaligned memory locations is supported. |
|
WriteInt32 | Overloaded. Writes a 32-bit signed integer value to unmanaged memory. Writing to unaligned memory locations is supported. |
|
WriteInt64 | Overloaded. Writes a 64-bit signed integer value to unmanaged memory. Writing to unaligned memory locations is supported. |
|
WriteIntPtr | Overloaded. Writes a processor native sized integer value to unmanaged memory. Writing to unaligned memory locations is supported. |
|
ZeroFreeBSTR | Frees a BSTR pointer that was allocated using the SecureStringToBSTR method. |
|
ZeroFreeCoTaskMemAnsi | Frees an unmanaged string pointer that was allocated using the SecureStringToCoTaskMemAnsi method. |
|
ZeroFreeCoTaskMemUnicode | Frees an unmanaged string pointer that was allocated using the SecureStringToCoTaskMemUnicode method. |
|
ZeroFreeGlobalAllocAnsi | Frees an unmanaged string pointer that was allocated using the SecureStringToGlobalAllocAnsi method. |
|
ZeroFreeGlobalAllocUnicode | Frees an unmanaged string pointer that was allocated using the SecureStringToGlobalAllocUnicode method. |
| Name | Description | |
|---|---|---|
|
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. |
|
SystemMaxDBCSCharSize | Represents the maximum size of a double byte character set (DBCS) size, in bytes, for the current operating system. This field is read-only. |