Early Preview
This is currently very much a preview. Please feel free to try things out,
but don't be upset if anything is not yet working. Feedback is welcome over on our
GitHub Dicussions page.
enum System.Runtime.InteropServices.UnmanagedType
Assembly: System.Runtime
Identifies how to marshal parameters or fields to unmanaged code.
Values
Bool
A 4-byte Boolean value ( <see langword="true" /> != 0, <see langword="false" /> = 0). This is the Win32 BOOL type.
I1
A 1-byte signed integer. You can use this member to transform a Boolean value into a 1-byte, C-style <see langword="bool" /> ( <see langword="true" /> = 1, <see langword="false" /> = 0).
U1
A 1-byte unsigned integer.
I2
A 2-byte signed integer.
U2
A 2-byte unsigned integer.
I4
A 4-byte signed integer.
U4
A 4-byte unsigned integer.
I8
An 8-byte signed integer.
U8
An 8-byte unsigned integer.
R4
A 4-byte floating-point number.
R8
An 8-byte floating-point number.
Currency
A currency type. Used on a <see cref="T:System.Decimal" /> to marshal the decimal value as a COM currency type instead of as a <see langword="Decimal" /> .
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 <see cref="T:System.String" /> data type.
LPStr
A single byte, null-terminated ANSI character string. You can use this member on the <see cref="T:System.String" /> and <see cref="T:System.Text.StringBuilder" /> data types.
LPWStr
A 2-byte, null-terminated Unicode character string. You cannot use the <see langword="LPWStr" /> value with an unmanaged string unless the string was created by using the unmanaged <see langword="CoTaskMemAlloc" /> function.
LPTStr
A Unicode character string. This value is supported only for platform invoke and not for COM interop, because exporting a string of type <see langword="LPTStr" /> is not supported.
ByValTStr
Used for in-line, fixed-length character arrays that appear within a structure. <see langword="ByValTStr" /> types behave like C-style, fixed-size strings inside a structure (for example, <c>char s[5]</c> ). The character type used with <see langword="ByValTStr" /> is determined by the <see cref="T:System.Runtime.InteropServices.CharSet" /> argument of the <see cref="T:System.Runtime.InteropServices.StructLayoutAttribute" /> attribute applied to the containing structure. Always use the <see cref="F:System.Runtime.InteropServices.MarshalAsAttribute.SizeConst" /> field to indicate the size of the array.
IUnknown
A COM <see langword="IUnknown" /> pointer. You can use this member on the <see cref="T:System.Object" /> data type.
IDispatch
A COM <see langword="IDispatch" /> pointer ( <see langword="Object" /> in Microsoft Visual Basic 6.0).
Struct
A VARIANT, which is used to marshal managed formatted classes and value types.
Interface
A COM interface pointer. The <see cref="T:System.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 <see cref="F:System.Runtime.InteropServices.UnmanagedType.IUnknown" /> when you apply it to the <see cref="T:System.Object" /> data type.
SafeArray
A <see langword="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 <see cref="F:System.Runtime.InteropServices.MarshalAsAttribute.SafeArraySubType" /> field to override the default element type.
ByValArray
When the <see cref="P:System.Runtime.InteropServices.MarshalAsAttribute.Value" /> property is set to <see langword="ByValArray" /> , the <see cref="F:System.Runtime.InteropServices.MarshalAsAttribute.SizeConst" /> field must be set to indicate the number of elements in the array. The <see cref="F:System.Runtime.InteropServices.MarshalAsAttribute.ArraySubType" /> field can optionally contain the <see cref="T:System.Runtime.InteropServices.UnmanagedType" /> of the array elements when it is necessary to differentiate among string types. You can use this <see cref="T:System.Runtime.InteropServices.UnmanagedType" /> only on an array that whose elements appear as fields in a structure.
SysInt
A platform-dependent, signed integer: 4 bytes on 32-bit Windows, 8 bytes on 64-bit Windows.
SysUInt
A platform-dependent, unsigned integer: 4 bytes on 32-bit Windows, 8 bytes on 64-bit Windows.
VBByRefStr
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.
AnsiBStr
An ANSI character string that is a length-prefixed single byte. You can use this member on the <see cref="T:System.String" /> data type.
TBStr
A length-prefixed, Unicode <see langword="char" /> string. You rarely use this BSTR-like member.
VariantBool
A 2-byte, OLE-defined VARIANT_BOOL type ( <see langword="true" /> = -1, <see langword="false" /> = 0).
FunctionPtr
An integer that can be used as a C-style function pointer. You can use this member on a <see cref="T:System.Delegate" /> data type or on a type that inherits from a <see cref="T:System.Delegate" /> .
AsAny
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.
LPArray
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 <see cref="F:System.Runtime.InteropServices.MarshalAsAttribute.SizeConst" /> and <see cref="F:System.Runtime.InteropServices.MarshalAsAttribute.SizeParamIndex" /> fields, optionally followed by the unmanaged type of the elements within the array when it is necessary to differentiate among string types.
LPStruct
A pointer to a C-style structure that you use to marshal managed formatted classes. This member is valid for platform invoke methods only.
CustomMarshaler
Specifies the custom marshaler class when used with the <see cref="F:System.Runtime.InteropServices.MarshalAsAttribute.MarshalType" /> or <see cref="F:System.Runtime.InteropServices.MarshalAsAttribute.MarshalTypeRef" /> field. The <see cref="F:System.Runtime.InteropServices.MarshalAsAttribute.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
A native type that is associated with an <see cref="F:System.Runtime.InteropServices.UnmanagedType.I4" /> or an <see cref="F:System.Runtime.InteropServices.UnmanagedType.U4" /> and that causes the parameter to be exported as an HRESULT in the exported type library.
IInspectable
A Windows Runtime interface pointer. You can use this member on the <see cref="T:System.Object" /> data type. Built-in support for WinRT was removed in .NET 5.
HString
A Windows Runtime string. You can use this member on the <see cref="T:System.String" /> data type. Built-in support for WinRT was removed in .NET 5. See Formerly built-in supported types for workaround.
LPUTF8Str
A pointer to a UTF-8 encoded string.