---
title: "c++库c#调用开发时需要注意的一点"
author: "Fangrn"
date: "2011-08-11T18:37:35Z"
tags: []
categories: ["行业应用"]
slug: "c-c"
draft: false
lastmod: "2011-08-11T18:37:35Z"
id: 1146765
url: "https://fangrn.iteye.com/blog/1146765"
---

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

 

Unmanaged type in Wtypes.h

Unmanaged C language type

Managed class name

Description

**HANDLE**

**void\***

[System. IntPtr](http://msdn.microsoft.com/en-us/library/system.intptr.aspx)

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

**BYTE**

**unsigned char**

[System. Byte](http://msdn.microsoft.com/en-us/library/system.byte.aspx)

8 bits

**SHORT**

**short**

[System. Int16](http://msdn.microsoft.com/en-us/library/system.int16.aspx)

16 bits

**WORD**

**unsigned short**

[System. UInt16](http://msdn.microsoft.com/en-us/library/system.uint16.aspx)

16 bits

**INT**

**int**

[System. Int32](http://msdn.microsoft.com/en-us/library/system.int32.aspx)

32 bits

**UINT**

**unsigned int**

[System. UInt32](http://msdn.microsoft.com/en-us/library/system.uint32.aspx)

32 bits

**LONG**

**long**

[System. Int32](http://msdn.microsoft.com/en-us/library/system.int32.aspx)

32 bits

**BOOL**

**long**

[System.Int32](http://msdn.microsoft.com/en-us/library/system.sbyte.aspx)

32 bits

**DWORD**

**unsigned long**

[System. UInt32](http://msdn.microsoft.com/en-us/library/system.uint32.aspx)

32 bits

**ULONG**

**unsigned long**

[System. UInt32](http://msdn.microsoft.com/en-us/library/system.uint32.aspx)

32 bits

**CHAR**

**char**

[System. Char](http://msdn.microsoft.com/en-us/library/system.char.aspx)

Decorate with ANSI.

**WCHAR**

**wchar\_t**

[System. Char](http://msdn.microsoft.com/en-us/library/system.char.aspx)

Decorate with Unicode.

**LPSTR**

**char\***

[System. String](http://msdn.microsoft.com/en-us/library/system.string.aspx) or [System.Text. StringBuilder](http://msdn.microsoft.com/en-us/library/system.text.stringbuilder.aspx)

Decorate with ANSI.

**LPCSTR**

**Const char\***

[System. String](http://msdn.microsoft.com/en-us/library/system.string.aspx) or [System.Text. StringBuilder](http://msdn.microsoft.com/en-us/library/system.text.stringbuilder.aspx)

Decorate with ANSI.

**LPWSTR**

**wchar\_t\***

[System. String](http://msdn.microsoft.com/en-us/library/system.string.aspx) or [System.Text. StringBuilder](http://msdn.microsoft.com/en-us/library/system.text.stringbuilder.aspx)

Decorate with Unicode.

**LPCWSTR**

**Const wchar\_t\***

[System. String](http://msdn.microsoft.com/en-us/library/system.string.aspx) or [System.Text. StringBuilder](http://msdn.microsoft.com/en-us/library/system.text.stringbuilder.aspx)

Decorate with Unicode.

**FLOAT**

**Float**

[System. Single](http://msdn.microsoft.com/en-us/library/system.single.aspx)

32 bits

**DOUBLE**

**Double**

[System. Double](http://msdn.microsoft.com/en-us/library/system.double.aspx)

64 bits

For corresponding types in Visual Basic 2005, C#, and C++, see the [Introduction to the .NET Framework Class Library](http://msdn.microsoft.com/en-us/library/hfa3fa08.aspx) .