Export (0) Print
Expand All
Expand Minimize

UnmanagedType Enumeration

Identifies how to marshal parameters or fields to unmanaged code.

[Visual Basic]
<Serializable>
Public Enum UnmanagedType
[C#]
[Serializable]
public enum UnmanagedType
[C++]
[Serializable]
__value public enum UnmanagedType
[JScript]
public
   Serializable
enum UnmanagedType

Remarks

This enumeration is used by System.Runtime.InteropServices.MarshalAsAttribute to specify nondefault values for Array, Boolean, and String data types or to make the default behavior explicit. You can also use the enumeration members to specify simple value types (I1, I2, I4, I8, R4, R8, U2, U4, and U8), unmanaged types that are unavailable in the .NET Framework, and various miscellaneous types. Some members represent types to be use with platform invoke methods only.

Members

Member name Description
AnsiBStr

Supported by the .NET Compact Framework.

An ANSI character string that is a length prefixed, single byte. You can use this member on the String data type.
AsAny

Supported by the .NET Compact Framework.

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

Supported by the .NET Compact Framework.

A 4-byte Boolean value (true != 0, false = 0). This is the Win32 BOOL type.
BStr

Supported by the .NET Compact Framework.

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

Supported by the .NET Compact Framework.

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

Supported by the .NET Compact Framework.

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

Currency Used on a System.Decimal to marshal the decimal value as a COM currency type instead of as a Decimal.
CustomMarshaler

Supported by the .NET Compact Framework.

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

Supported by the .NET Compact Framework.

This native type associated with an I4 or a U4 causes the parameter to be exported as a HRESULT in the exported type library.
FunctionPtr

Supported by the .NET Compact Framework.

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

Supported by the .NET Compact Framework.

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

Supported by the .NET Compact Framework.

A 2-byte signed integer.
I4

Supported by the .NET Compact Framework.

A 4-byte signed integer.
I8

Supported by the .NET Compact Framework.

An 8-byte signed integer.
IDispatch

Supported by the .NET Compact Framework.

A COM IDispatch pointer (Object in Microsoft Visual Basic 6.0).
Interface

Supported by the .NET Compact Framework.

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

Supported by the .NET Compact Framework.

A COM IUnknown pointer. You can use this member on the Object data type.
LPArray

Supported by the .NET Compact Framework.

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

Supported by the .NET Compact Framework.

A single byte, null-terminated ANSI character string. You can use this member on the System.String or System.Text.StringBuilder data types
LPStruct

Supported by the .NET Compact Framework.

A pointer to a C-style structure that you use to marshal managed formatted classes. Valid for platform invoke methods only.
LPTStr

Supported by the .NET Compact Framework.

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

Supported by the .NET Compact Framework.

A 2-byte, null-terminated Unicode character string.
R4

Supported by the .NET Compact Framework.

A 4-byte floating point number.
R8

Supported by the .NET Compact Framework.

An 8-byte floating point number.
SafeArray

Supported by the .NET Compact Framework.

A SafeArray is a self-describing array that carries the type, rank, and bounds of the associated array data. You can use this member with the MarshalAsAttribute.SafeArraySubType field to override the default element type.
Struct

Supported by the .NET Compact Framework.

A VARIANT, which is used to marshal managed formatted classes and value types.
SysInt

Supported by the .NET Compact Framework.

A platform-dependent, signed integer. 4-bytes on 32 bit Windows, 8-bytes on 64 bit Windows.
SysUInt

Supported by the .NET Compact Framework.

A platform-dependent, unsigned integer. 4-bytes on 32 bit Windows, 8-bytes on 64 bit Windows.
TBStr

Supported by the .NET Compact Framework.

A length-prefixed, platform-dependent char string. ANSI on Windows 98, Unicode on Windows NT. You rarely use this BSTR-like member.
U1

Supported by the .NET Compact Framework.

A 1-byte unsigned integer.
U2

Supported by the .NET Compact Framework.

A 2-byte unsigned integer.
U4

Supported by the .NET Compact Framework.

A 4-byte unsigned integer.
U8

Supported by the .NET Compact Framework.

An 8-byte unsigned integer.
VariantBool

Supported by the .NET Compact Framework.

A 2-byte, OLE-defined VARIANT_BOOL type (true = -1, false = 0).
VBByRefStr

Supported by the .NET Compact Framework.

Allows Visual Basic .NET to change a string in unmanaged code, and have the results reflected in managed code. This value is only supported for platform invoke.

Requirements

Namespace: System.Runtime.InteropServices

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

Assembly: Mscorlib (in Mscorlib.dll)

See Also

System.Runtime.InteropServices Namespace | MarshalAsAttribute | ComImportAttribute

Show:
© 2014 Microsoft