c++库c#调用开发时需要注意的一点

因为业务需要,需要将一个  c++写的 dll库由 C# 来调用,于是乎google了很多相关的文章,照着写了个  C#程序,结果发现很多时候很简单调用,结果都错了,经过很多次的失败和郁闷,最后发现有个关键点,就是我们c++ 和  c#的数据类型要一一对照起来才可以,如下是从msdn上摘抄一段对照列表,很有用的

 

Unmanaged type in Wtypes.h

Unmanaged C language type

Managed class name

Description

HANDLE

void*

System. IntPtr

32 bits on 32-bit Windows operating systems, 64 bits on 64-bit Windows operating systems.

BYTE

unsigned char

System. Byte

8 bits

SHORT

short

System. Int16

16 bits

WORD

unsigned short

System. UInt16

16 bits

INT

int

System. Int32

32 bits

UINT

unsigned int

System. UInt32

32 bits

LONG

long

System. Int32

32 bits

BOOL

long

System.Int32

32 bits

DWORD

unsigned long

System. UInt32

32 bits

ULONG

unsigned long

System. UInt32

32 bits

CHAR

char

System. Char

Decorate with ANSI.

WCHAR

wchar_t

System. Char

Decorate with Unicode.

LPSTR

char*

System. String or System.Text. StringBuilder

Decorate with ANSI.

LPCSTR

Const char*

System. String or System.Text. StringBuilder

Decorate with ANSI.

LPWSTR

wchar_t*

System. String or System.Text. StringBuilder

Decorate with Unicode.

LPCWSTR

Const wchar_t*

System. String or System.Text. StringBuilder

Decorate with Unicode.

FLOAT

Float

System. Single

32 bits

DOUBLE

Double

System. Double

64 bits

For corresponding types in Visual Basic 2005, C#, and C++, see the Introduction to the .NET Framework Class Library .

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值