Mapping type between C++ and C#

简介:   API Data Type Type Description C# Type API Data Type Type Description C# Type WORD ...

 

API Data Type

Type Description

C# Type

API Data Type

Type Description

C# Type

WORD

16 bit unsigned int

ushort

CHAR

char

char

LONG

32 bit unsigned int

int

DWORDLONG

64 bit long int

long

DWORD

32 bit unsigned int

uint

HDC

Device decription table handle

int

HANDLE

handle,32 bit int

int

HGDIOBJ

GDI object handle

int

UINT

32 bit unsigned int

uint

HINSTANCE

Instance handle

int

BOOL

32bit bool

bool

HWM

Window handle

int

LPSTR

32-bit pointer pointing to the character

string

HPARAM

32 bit message parameters

int

LPCSTR

32-bit pointer pointing to the  const character

String

LPARAM

32 bit message parameters

int

BYTE

byte

byte

WPARAM

32 bit message parameters

int

 

Unmanaged Types in Wtypes.h

Unmanaged C Types

 Managed class name

Comment

HANDLE

void* 

System.IntPtr

32 bit

BYTE

unsigned char

System.Byte

8 bit

SHORT

short

System.Int16

16 bit

WORD

unsigned short

System.UInt16

16 bit

INT

 int

System.Int32

32 bit

UINT

unsigned int

System.UInt32

32 bit

LONG

long

System.Int32

32 bit

BOOL

long

System.Int32

32 bit

DWORD

unsigned long

System.UInt32

32

ULONG

unsigned long

System.UInt32

32

CHAR

char

System.Char

use ANSI

LPSTR

char*

System.String System.StringBuilder

use ANSI

LPCSTR

Const char*

System.String System.StringBuilder

use ANSI

LPWSTR 

wchar_t*

System.String System.StringBuilder

use Unicode

LPCWSTR

Const wchar_t*

System.String System.StringBuilder

use Unicode

FLOAT 

Float

System.Single

32 bit

DOUBLE 

Double

System.Double

64 bit

 

 

Types map to System namespace in C++

 

 

 

 

BOOL=System.Int32

HGDIOBJ=System.IntPtr

LONG32=System.Int32

PCHAR=System.Char[]

PWORD=System.Int16[]

BOOLEAN=System.Int32

HGLOBAL=System.IntPtr

LONG64=System.Int64

PCSTR=System.String

PWSTR=System.String

BYTE=System.UInt16

HHOOK=System.IntPtr

LONGLONG=System.Int64

PCTSTR=System.String

REGSAM=System.UInt32

CHAR=System.Int16

HICON=System.IntPtr

LPARAM=System.IntPtr

PCWCH=System.UInt32

SC_HANDLE=System.IntPtr

COLORREF=System.UInt32

HIMAGELIST=System.IntPtr

LPBOOL=System.Int16[]

PCWSTR=System.UInt32

SC_LOCK=System.IntPtr

DWORD=System.UInt32

HIMC=System.IntPtr

LPBYTE=System.UInt16[]

PDWORD=System.Int32[]

SHORT=System.Int16

DWORD32=System.UInt32

HINSTANCE=System.IntPtr

LPCOLORREF=System.UInt32[]

PFLOAT=System.Float[]

SIZE_T=System.UInt32

DWORD64=System.UInt64

HKEY=System.IntPtr

LPCSTR=System.String

PHANDLE=System.UInt32

SSIZE_=System.UInt32

FLOAT=System.Float

HLOCAL=System.IntPtr

LPCTSTR=System.String

PHKEY=System.UInt32

TBYTE=System.Char

HACCEL=System.IntPtr

HMENU=System.IntPtr

LPCVOID=System.UInt32

PINT=System.Int32[]

TCHAR=System.Char

HANDLE=System.IntPtr

HMETAFILE=System.IntPtr

LPCWSTR=System.String

PLCID=System.UInt32

UCHAR=System.Byte

HBITMAP=System.IntPtr

HMODULE=System.IntPtr

LPDWORD=System.UInt32[]

PLONG=System.Int32[]

UINT=System.UInt32

HBRUSH=System.IntPtr

HMONITOR=System.IntPtr

LPHANDLE=System.UInt32

PLUID=System.UInt32

UINT32=System.UInt32

HCONV=System.IntPtr

HPALETTE=System.IntPtr

LPINT=System.Int32[]

PSHORT=System.Int16[]

UINT64=System.UInt64

HCONVLIST=System.IntPtr

HPEN=System.IntPtr

LPLONG=System.Int32[]

PSTR=System.String

ULONG=System.UInt32

HCURSOR=System.IntPtr

HRGN=System.IntPtr

LPSTR=System.String

PTBYTE=System.Char[]

ULONG32=System.UInt32

HDC=System.IntPtr

HRSRC=System.IntPtr

LPTSTR=System.String

PTCHAR=System.Char[]

ULONG64=System.UInt64

HDDEDATA=System.IntPtr

HSZ=System.IntPtr

LPVOID=System.UInt32

PTSTR=System.String

ULONGLONG=System.UInt64

HDESK=System.IntPtr

HWINSTA=System.IntPtr

LPWORD=System.Int32[]

PUCHAR=System.Char[]

USHORT=System.UInt16

HDROP=System.IntPtr

HWND=System.IntPtr

LPWSTR=System.String

PUINT=System.UInt32[]

WORD=System.UInt16

HDWP=System.IntPtr

INT=System.Int32

LRESULT=System.IntPtr

PULONG=System.UInt32[]

WPARAM=System.IntPtr

HENHMETAFILE=System.IntPtr

INT32=System.Int32

PBOOL=System.Int16[]

PUSHORT=System.UInt16[]

 

HFILE=System.IntPtr

INT64=System.Int64

PBOOLEAN=System.Int16[]

PVOID=System.UInt32

 

HFONT=System.IntPtr

LONG=System.Int32

PBYTE=System.UInt16[]

PWCHAR=System.Char[]

 

 

An example:

C# Method

IDL Equivalent

Calling semantics in C#

public void Method(String strInput);

HRESULT Method([in] BSTR strInput);

obj.Method("Hello There");

public String Method();

HRESULT Method([out, retval] BSTR* pRetVal);

String strOutput = obj.Method();

public String Method(ref String strPassAndModify);

HRESULT Method([in, out] BSTR* strPassAndModify, [out, retval] BSTR* pRetVal);

String strHello = "Hello There";

String strOutput = obj.Method(ref strHello);

public String Method(out String strReturn);

HRESULT Method([out] BSTR* strReturn, [out, retval] BSTR* pRetVal);

//Need not initialize strHello

String strHello;

String strOutput = obj.Method(out strHello);

public String Method(String strFirst, out String strSecond, ref String strThird);

HRESULT Method([in] BSTR bstrFirst, [out] BSTR* strSecond, [in, out] BSTR* strThird, [out, retval] BSTR* pRetVal);

String strFirst = "Hi There";

String strSecond;

String strThird = "Hello World";

String strOutput = obj.Method(strFirst,out strSecond, ref strThird);

 

COM Data Types From Microsoft

 

Pasted from <http://msdn.microsoft.com/en-us/library/sak564ww(v=VS.71).aspx>

 

COM value type

COM reference type

System type

bool

bool *

System.Int32

char, small

char *, small *

System.SByte

short

short *

System.Int16

long, int

long *, int *

System.Int32

Hyper

hyper *

System.Int64

unsigned char, byte

unsigned char *, byte *

System.Byte

wchar_t, unsigned short

wchar_t *, unsigned short *

System.UInt16

unsigned long, unsigned int

unsigned long *, unsigned int *

System.UInt32

unsigned hyper

unsigned hyper *

System.UInt64

float

float *

System.Single

double

double *

System.Double

VARIANT_BOOL

VARIANT_BOOL *

System.Boolean

void *

void **

System.IntPtr

HRESULT

HRESULT *

System.Int16 or System.IntPtr

SCODE

SCODE *

System.Int32

BSTR

BSTR *

System.String

LPSTR or [string, ...] char *

LPSTR *

System.String

LPWSTR or [string, ...] wchar_t *

LPWSTR *

System.String

VARIANT

VARIANT *

System.Object

DECIMAL

DECIMAL *

System.Decimal

DATE

DATE *

System.DateTime

GUID

GUID *

System.Guid

CURRENCY

CURRENCY *

System.Decimal

IUnknown *

IUnknown **

System.Object

IDispatch *

IDispatch **

System.Object

SAFEARRAY(type)

SAFEARRAY(type) *

type[]

The following table lists COM value and reference types that convert to corresponding element types. For example, a COM coclass automatically maps to a managed class with the same name.

COM value type

COM reference type

Element type

typedef BaseType MyType

ByRef BaseType

BaseType

MyStruct

ByRef VALUETYPE<MyStruct>

valuetype<MyStruct>

MyEnum

ByRef VALUETYPE<MyEnum>

valuetype<MyEnum>

MyInterface *

ByRef CLASS <MyInterface>

Class <MyInterface>

MyCoClass

ByRef CLASS <_Class>

class <_Class>

 

Pasted from <http://msdn.microsoft.com/en-us/library/sak564ww(v=VS.71).aspx>

 

目录
相关文章
|
6月前
|
Java
【ES异常】mapper [sortNum] of different type, current_type [long], merged_type [keyword]
【ES异常】mapper [sortNum] of different type, current_type [long], merged_type [keyword]
49 0
|
3月前
|
前端开发
【前端】解决: Property 'inline' does not exist on type 'ClassAttributes<HTMLElement> & HTMLAttribut...
【前端】解决: Property 'inline' does not exist on type 'ClassAttributes<HTMLElement> & HTMLAttribut...
38 0
|
5月前
|
Java
jstl错误:According to TLD or attribute directive in tag file, attribute value does not accept any expr
jstl错误:According to TLD or attribute directive in tag file, attribute value does not accept any expr
|
8月前
|
Scala
TYPE
TYPE
81 0
使用pageHelper报错 Type definition error: [simple type, classXXXX]
使用pageHelper报错 Type definition error: [simple type, classXXXX]
|
Java 数据库连接 mybatis
mybatis报错:Type handler was null on parameter mapping or property ‘__frch_xxx_0’
mybatis报错:Type handler was null on parameter mapping or property ‘__frch_xxx_0’
1577 0
mybatis报错:Type handler was null on parameter mapping or property ‘__frch_xxx_0’
|
10月前
|
Java 关系型数据库 MySQL
15. 成功解决:java: Can't generate mapping method with primitive return type.
今天启动 SpringBoot 项目时,报了如下错误:`java: Can't generate mapping method with primitive return type.`
460 0
‘DebugConfig‘ only refers to a type, but is being used as a value here.
‘DebugConfig‘ only refers to a type, but is being used as a value here.
317 0
‘DebugConfig‘ only refers to a type, but is being used as a value here.
When will the reference ATTRIBUTE_REF of an BOL entity be cleared
When will the reference ATTRIBUTE_REF of an BOL entity be cleared
When will the reference ATTRIBUTE_REF of an BOL entity be cleared
|
中间件
equipment header attribute mapping - two settypes in middleware
equipment header attribute mapping - two settypes in middleware
equipment header attribute mapping - two settypes in middleware