Search notes:

System.Runtime.InteropServices.UnmanagedType (enum)

The System.Runtime.InteropServices.UnmanagedType enum specifies how managed data is marshalled to unmanaged code.
The enum has the following fields:
AnsiBStr 35 An ANSI character string that is a length-prefixed single byte. You can use this member on the String data type. Compare with BStr
AsAny 40 A dynamic type that determines the type of an object at run time and marshals the object as that type. This member is valid for platform invoke methods only.
Bool 2 A 4-byte Boolean value (true != 0, false = 0). This is the Win32 BOOL type.
BStr 19 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. Compare with AnsiBStr.
ByValArray 30 When the Value property is set to ByValArray, the SizeConst field 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 use this UnmanagedType only on an array that whose elements appear as fields in a structure.
ByValTStr 23 Used for in-line, fixed-length character arrays that appear within a structure. ByValTStr types behave like C-style, fixed-size strings inside a structure (for example, char s[5]). The character type used with ByValTStr is determined by the CharSet argument of the System.Runtime.InteropServices.StructLayoutAttribute attribute applied to the containing structure. Always use the SizeConst field to indicate the size of the array.
Currency 15 A currency type. Used on a Decimal to marshal the decimal value as a COM currency type instead of as a Decimal.
CustomMarshaler 44 Specifies the custom marshaler class when used with the MarshalType or MarshalTypeRef field. The MarshalCookie field can be used to pass additional information to the custom marshaler. You can use this member on any reference type. This member is valid for parameters and return values only. It cannot be used on fields.
Error 45 A native type that is associated with an I4 or an U4 and that causes the parameter to be exported as an HRESULT in the exported type library.
FunctionPtr 38 An integer that can be used as a C-style function pointer. You can use this member on a Delegate data type or on a type that inherits from a Delegate.
HString 47 A Windows Runtime string. You can use this member on the String data type.
I1 3 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 5 A 2-byte signed integer.
I4 7 A 4-byte signed integer.
I8 9 An 8-byte signed integer.
IDispatch 26 A COM IDispatch pointer. Compare with IUnknown.
IInspectable 46 A Windows Runtime interface pointer. You can use this member on the Object data type.
Interface 28 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 the same behavior as IUnknown when you apply it to the Object data type.
IUnknown 25 A COM IUnknown pointer. You can use this member on the Object data type. Compare with IDispatch
LPArray 42 A pointer to the first element of a C-style array. When marshaling from managed to unmanaged code, the length of the array is determined by the length of the managed array. When marshaling from unmanaged to managed code, the length of the array is determined from the SizeConst and SizeParamIndex fields, optionally followed by the unmanaged type of the elements within the array when it is necessary to differentiate among string types.
LPStr 20 A single byte, null-terminated ANSI character string. You can use this member on the System.String and System.Text.StringBuilder data types.
LPStruct 43 A pointer to a C-style structure that you use to marshal managed formatted classes. This member is valid for platform invoke methods only.
LPTStr 22 A Unicode character string. This value is supported only for platform invoke and not for COM interop, because exporting a string of type LPTStr is not supported.
LPUTF8Str 48 A pointer to a UTF-8 encoded string.
LPWStr 21 A 2-byte, null-terminated Unicode character string. You cannot use the LPWStr value with an unmanaged string unless the string was created by using the unmanaged CoTaskMemAlloc function.
R4 11 A 4-byte floating-point number.
R8 12 An 8-byte floating-point number.
SafeArray 29 A SafeArray, which is a self-describing array that carries the type, rank, and bounds of the associated array data. You can use this member with the SafeArraySubType field to override the default element type.
Struct 27 A VARIANT, which is used to marshal managed formatted classes and value types.
SysInt 31 A platform-dependent, signed integer: 4 bytes on 32-bit Windows, 8 bytes on 64-bit Windows.
SysUInt 32 A platform-dependent, unsigned integer: 4 bytes on 32-bit Windows, 8 bytes on 64-bit Windows.
TBStr 36 A length-prefixed, Unicode char string. You rarely use this BSTR-like member.
U1 4 A 1-byte unsigned integer.
U2 6 A 2-byte unsigned integer.
U4 8 A 4-byte unsigned integer.
U8 10 An 8-byte unsigned integer.
VariantBool 37 A 2-byte, OLE-defined VARIANT_BOOL type (true = -1, false = 0).
VBByRefStr 34 A value that enables Visual Basic to change a string in unmanaged code and have the results reflected in managed code. This value is only supported for platform invoke.

See also

One of the two constructors of System.Runtime.InteropServices.MarshalAsAttribute taks an instance of UnmanagedType as parameter.

Index