Type Support
[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]
The following tables describe categories of types and the results of marshaling types from managed to unmanaged contexts.
Type Categories
The following table provides descriptions and clarifications for several of the types mentioned in the following sections.
Type |
Description |
---|---|
Value types |
Value types directly contain the data described and the memory for the value type is allocated from the stack. |
Built-in value types |
Int32, UInt32, Boolean, Single, and so on. For a complete list, see .NET Framework Class Library Overview. |
User-defined value types |
Derived from System.ValueType. In C#, a user-defined value type is defined using the struct keyword. |
Enumerations |
Enumerations are also value types. The underlying type of an enumeration in the .NET Framework is Int32. However, you can explicitly define an enumeration to have another underlying type. The supported underlying types are any integral base types except Char. |
Reference type |
Reference types store a reference to an object's memory that was allocated on the heap. These can be built-in classes, user-defined classes, arrays, boxed value types, delegates, and so forth. |
Managed to Unmanaged Types
The following table describes the result of marshaling managed types to unmanaged types.
Managed type |
Unmanaged type |
---|---|
Value type (including greater than 32 bits) |
Unmodified. |
Reference to value type |
Pointer to the value type. |
64-bit integer |
Pointer to array of value types. |
Floating-point number |
Floating-point number. |
Array of value types |
Pointer to array of value types. |
Underlying value type of the enumeration. |
|
ANSI string |
Only supported if passed as an array of bytes. |
Pointer to a null-terminated array of Unicode (wchar_t) characters. Unmanaged code should not modify the array. |
|
Reference type |
Pointer to the underlying data fields of the object. Reference types are always marshaled sequentially. You can marshal only objects that contain value-type members. |
Reference to reference type |
Not supported. |
Array of reference types |
Not supported. |
Delegate |
Function pointer |
Pointer to a null-terminated array of Unicode (wchart_t) characters. Unmanaged code can modify the array. |
C# and Visual Basic Marshaling Results
The following table lists C# and Visual Basic types used by the marshaler for managed types, with Windows CE as the operating system hosting the unmanaged code. This list is not comprehensive.
Managed code C# types |
Managed code Visual Basic types |
Unmanaged code ByVal |
Unmanaged code ByRef |
---|---|---|---|
bool |
Boolean |
BYTE |
BYTE * |
int |
Integer |
INT32 |
INT32 * |
short |
Short |
SHORT |
SHORT * |
long |
Long |
LONG |
INT64 * |
char |
Char |
WCHAR |
WCHAR * |
float |
Single |
FLOAT |
FLOAT * |
double |
Double |
DOUBLE |
DOUBLE * |
string |
String |
WCHAR * |
Not supported |
WCHAR * |
Not supported |
||
DATE |
DATE * |
||
int[] |
Integer() |
INT32 *, INT32[] |
Not supported |
Variant Type Support
The following table lists the types from the VARENUM enumeration supported by the IDispatch marshaler for marshaling from managed to unmanaged code. In all cases, the types are supported both for parameters and return types. The unsupported types include those not applicable to variant types.
Supported types |
Unsupported types |
---|---|
VT_I2 VT_I4 VT_CY VT_DATE VT_BSTR VT_DISPATCH VT_ERROR VT_BOOL VT_VARIANT VT_UNKNOWN VT_DECIMAL VT_I1 VT_UI1 VT_UI2 VT_UI4 VT_INT VT_UINT VT_ARRAY VT_R8 VT_R4 VT_CF VT_CLSID |
VT_EMPTY VT_NULL VT_I8 VT_UI8 VT_USERDEFINED VT_RECORD VT_SAFEARRAY (use VT_ARRAY) VT_PTR VT_HRESULT VT_VOID VT_CARRAY VT_LPSTR (use VT_BSTR) VT_LPWSTR (use VT_BSTR) VT_FILETIME VT_BLOB VT_STREAM VT_STORAGE VT_STREAMED_OBJECT VT_STORED_OBJECT VT_BLOB_OBJECT VT_VECTOR |