Sdílet prostřednictvím


UnmanagedType Enumeration

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

This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.

Identifies how to marshal parameters or fields to unmanaged code.

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

Syntax

'Declaration
<ComVisibleAttribute(True)> _
Public Enumeration UnmanagedType
[ComVisibleAttribute(true)]
public enum UnmanagedType

Members

Member name Description
Supported by Silverlight for Windows PhoneSupported by Xbox 360 Bool A 4-byte Boolean value (true != 0, false = 0). This is the Win32 BOOL type.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 I1 A 1-byte signed integer. You can use this member to transform a Boolean value into a 1-byte, C-style bool (true = 1, false = 0).
Supported by Silverlight for Windows PhoneSupported by Xbox 360 U1 A 1-byte unsigned integer.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 I2 A 2-byte signed integer.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 U2 A 2-byte unsigned integer.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 I4 A 4-byte signed integer.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 U4 A 4-byte unsigned integer.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 I8 An 8-byte signed integer.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 U8 An 8-byte unsigned integer.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 R4 A 4-byte floating point number.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 R8 An 8-byte floating point number.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 Currency Used on a System.Decimal to marshal the decimal value as a COM currency type instead of as a Decimal.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 LPStr A single byte, null-terminated ANSI character string. You can use this member on the System.String or System.Text.StringBuilder data types
Supported by Silverlight for Windows PhoneSupported by Xbox 360 LPWStr A 2-byte, null-terminated Unicode character string.

Note that you cannot use the LPWStr value with an unmanaged string unless the string was created using the unmanaged CoTaskMemAlloc function.

Supported by Silverlight for Windows PhoneSupported by Xbox 360 LPTStr A platform-dependent character string: ANSI on Windows 98 and Unicode on Windows NT and Windows XP. This value is only supported for platform invoke, and not COM interop, because exporting a string of type LPTStr is not supported.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 ByValTStr Used for in-line, fixed-length character arrays that appear within a structure. The character type used with ByValTStr is determined by the System.Runtime.InteropServices.CharSet argument of the System.Runtime.InteropServices.StructLayoutAttribute applied to the containing structure. Always use the MarshalAsAttribute.SizeConst field to indicate the size of the array.

.NET Framework ByValTStr types behave like C-style, fixed-size strings inside a structure (for example, char s[5]). The behavior in managed code differs from the Microsoft Visual Basic 6.0 behavior, which is not null terminated (for example, MyString As String * 5).

Supported by Silverlight for Windows PhoneSupported by Xbox 360 IUnknown A COM IUnknown pointer. You can use this member on the Object data type.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 Struct A VARIANT, which is used to marshal managed formatted classes and value types.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 ByValArray When MarshalAsAttribute.Value is set to ByValArray, the SizeConst must be set to indicate the number of elements in the array. The ArraySubType field can optionally contain the UnmanagedType of the array elements when it is necessary to differentiate among string types. You can only use this UnmanagedType on an array that appear as fields in a structure.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 SysInt A platform-dependent, signed integer. 4-bytes on 32 bit Windows, 8-bytes on 64 bit Windows.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 SysUInt A platform-dependent, unsigned integer. 4-bytes on 32 bit Windows, 8-bytes on 64 bit Windows.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 FunctionPtr An integer that can be used as a C-style function pointer. You can use this member on a Delegate data type or a type that inherits from a Delegate.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 AsAny A dynamic type that determines the type of an object at run time and marshals the object as that type. Valid for platform invoke methods only.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 LPArray A pointer to the first element of a C-style array. When marshaling from managed to unmanaged, the length of the array is determined by the length of the managed array. When marshaling from unmanaged to managed, the length of the array is determined from the MarshalAsAttribute.SizeConst and the MarshalAsAttribute.SizeParamIndex fields, optionally followed by the unmanaged type of the elements within the array when it is necessary to differentiate among string types.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 LPStruct A pointer to a C-style structure that you use to marshal managed formatted classes. Valid for platform invoke methods only.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 Error This native type associated with an I4 or a U4 causes the parameter to be exported as a HRESULT in the exported type library.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 BStr A Unicode character string that is a length-prefixed double byte. You can use this member, which is the default string in COM, on the String data type.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 IDispatch A COM IDispatch pointer (Object in Microsoft Visual Basic 6.0).
Supported by Silverlight for Windows PhoneSupported by Xbox 360 Interface A COM interface pointer. The Guid of the interface is obtained from the class metadata. Use this member to specify the exact interface type or the default interface type if you apply it to a class. This member produces UnmanagedType.IUnknown behavior when you apply it to the Object data type.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 SafeArray A SafeArray is a self-describing array that carries the type, rank, and bounds of the associated array data.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 VBByRefStr Allows Visual Basic 2005 to change a string in unmanaged code, and have the results reflected in managed code. This value is only supported for platform invoke.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 AnsiBStr An ANSI character string that is a length prefixed, single byte. You can use this member on the String data type.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 TBStr A length-prefixed, platform-dependent char string. ANSI on Windows 98, Unicode on Windows NT. You rarely use this BSTR-like member.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 VariantBool A 2-byte, OLE-defined VARIANT_BOOL type (true = -1, false = 0).
Supported by Silverlight for Windows PhoneSupported by Xbox 360 CustomMarshaler Specifies the custom marshaler class when used with MarshalAsAttribute.MarshalType or MarshalAsAttribute.MarshalTypeRef. The MarshalAsAttribute.MarshalCookie field can be used to pass additional information to the custom marshaler. You can use this member on any reference type.

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.