Marshaling COM Types to the .NET Framework


During the course of importing information from a type library, the importer makes various data type conversions. Any type not explicitly identified in the following tables is converted to an I4 element type. You can manipulate these types with the helper routines in the System.Runtime.InteropServices.Marshal class.

Value Types

Type library types

Imported element types

System types

Visual Basic

C#

Managed C++

char, Boolean, small I1 System.SByte N/A byte sbyte
wchar_t, short I2 System.Int16 short short short
long, int I4 System.Int32 integer long int
Hyper I8 System.Int64 long __int64 long
unsigned char, byte UI1 System.Byte byte byte byte
unsigned short UI2 System.UInt16 N/A unsigned short ushort
unsigned long, unsigned int UI4 System.UInt32 N/A unsigned long uint
unsigned hyper UI8 System.UInt64 N/A unsigned __int64 ulong
single R4 System.Single single float float
double R8 System.Double double double double
VARIANT_BOOL Boolean N/A Boolean bool bool
void * UI4 N/A N/A N/A N/A
HRESULT I4 N/A N/A unsigned long uint
SCODE I4         unsigned long uint
BSTR String System.String string     string
LPSTR or
[string, …] char *
String System.String string N/A string
LPWSTR or
[string, …] wchar_t *
String System.String string     string
VARIANT Object System.Object            
DECIMAL valuetype
<System.
Decimal>
System.Decimal            
DATE valuetype
<System.
DateTime>
System.DateTime            
GUID valuetype
<System.
Guid>
System.Guid            
CURRENCY valuetype
<System.
Decimal>
System.Decimal            
IUnknown * Object System.Object            
IDispatch * Object System.Object            
SAFEARRAY
(type)
SZARRAY
(type)
type[]            
typedef BaseType MyType BaseType                
MyStruct valuetype
<MyStruct>
               
MyEnum valuetype
<MyEnum>
               
MyInterface * Class <MyInterface>                
MyCoClass class
<_Class>
               

Reference Types

Type library types

Imported element types

System types

Visual Basic

C#

Managed C++

char *, Boolean *, small * ByRef I1 System.SByte     byte sbyte
wchar_t *, short * ByRef I2 System.Int16 short short short
long *, int * ByRef I4 System.Int32 integer long int
hyper * ByRef I8 System.Int64 long __int64 long
unsigned char *, byte * ByRef UI1 System.Byte byte byte byte
unsigned short * ByRef UI2 System.UInt16     unsigned short ushort
unsigned long *, unsigned int * ByRef UI4 System.UInt32     unsigned long uint
unsigned hyper * ByRef UI8 System.UInt64     unsigned __int64 ulong
single * ByRef R4 System.Single single float float
double * ByRef R8 System.Double double double double
VARIANT_
BOOL *
ByRef Boolean     Boolean bool bool
void ** ByRef I4                
HRESULT * ByRef I4         unsigned short ushort
SCODE * ByRef I4         unsigned short ushort
BSTR * ByRef STRING System.String string     string
LPSTR * ByRef STRING System.String string     string
LPWSTR * ByRef STRING System.String string     string
VARIANT * ByRef OBJECT System.Object            
DECIMAL * ByRef VALUETYPE
<System.
Decimal>
System.Decimal            
DATE * ByRef VALUETYPE
<System.
DateTime>
System.DateTime            
GUID * ByRef VALUETYPE
<System.
Guid>
System.Guid            
CURRENCY * ByRef VALUETYPE
<System.
Decimal>
System. Decimal            
IUnknown ** ByRef OBJECT System.Object            
IDispatch ** ByRef OBJECT System.Object            
SAFEARRAY
(type) *
ByRef SZARRAY
(type)
type[]            
typedef BaseType MyType ByRef BaseType                
MyStruct * ByRef VALUETYPE
<MyStruct>
               
MyEnum * ByRef VALUETYPE
<MyEnum>
               
MyInterface ** ByRef CLASS <MyInterface>                
MyCoClass * ByRef CLASS
<_Class>
               
Advertisements

Thanks a lot for visiting this site .. Please leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s