版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、C+与.net数据类型对应表 (在硬件开发时很重要)C#调用DLL文件时参数对应表Wtypes.h 中的非托管类型非托管 C 语言类型托管类名说明HANDLEvoid*System.IntPtr32 位BYTEunsigned charSystem.Byte8 位SHORTshortSystem.Int1616 位WORDunsigned shortSystem.UInt1616 位INTintSystem.Int3232 位UINTunsigned intSystem.UInt3232 位LONGlongSystem.Int3232 位BOOLlongSystem.Int3232 位DWOR
2、Dunsigned longSystem.UInt3232 位ULONGunsigned longSystem.UInt3232 位CHARcharSystem.Char用 ANSI 修饰。LPSTRchar*System.String 或 System.StringBuilder用 ANSI 修饰。LPCSTRConst char*System.String 或 System.StringBuilder用 ANSI 修饰。LPWSTRwchar_t*System.String 或 System.StringBuilder用 Unicode 修饰。LPCWSTRConst wchar_t*Sy
3、stem.String 或 System.StringBuilder用 Unicode 修饰。FLOATFloatSystem.Single32 位DOUBLEDoubleSystem.Double64 位 类别类名说明Visual Basic 数据类型C# 数据类型C+ 托管扩展数据类型JScript 数据类型整数Byte8 位的无符号整数。BytebytecharByte SByte8 位的有符号整数。 不符合 CLS。SByte 无内置类型。sbytesigned charSByte Int1616
4、 位的有符号整数。Shortshortshortshort Int3232 位的有符号整数。Integerintint - 或 -longint Int6464 位的有符号整数。Longlong_int64long UInt1616 位的无符号整数。 不符合 CLS。UInt16 无内置类型。ushortunsigned shortUInt16 UInt3232 位的无符号整数。 不符合 CLS。UInt32 无内置类型。uintunsigned int -
5、或 -unsigned longUInt32 UInt6464 位的无符号整数。 不符合 CLS。UInt64 无内置类型。ulongunsigned _int64UInt64浮点Single单精度(32 位)浮点数字。Singlefloatfloatfloat Double双精度(64 位)浮点数字。Doubledoubledoubledouble逻辑Boolean布尔值(真或假)。Booleanboolboolbool其他CharUnicode(16 位)字符。Charcharwchar_tchar
6、 Decimal96 位十进制值。DecimaldecimalDecimalDecimal IntPtr大小取决于基础平台(32 位平台上为 32 位值,64 位平台上为 64 位值)的有符号整数。IntPtr 无内置类型。IntPtr 无内置类型。IntPtr 无内置类型。IntPtr UIntPtr大小取决于基础平台的无符号整数(32 位平台上为 32 位值,64 位平台上为 64 位值)。 不符合 CLS。UIntPtr 无内置类型。UIntPtr 无内置类型。UIntPtr 无内置类型。UIntPtr类对象O
7、bject对象层次结构的根。ObjectobjectObject*Object StringUnicode 字符的不变的定长串。StringstringString*StringC# 与 C+ 数据类型比较及结构体转换作者:菜鸟的宣言 来源:博客园 发布时间:2009-10-27 17:33 阅读:583 次 原文链接 收藏 C+
8、; C#=WORD ushortDWORD uintUCHAR int/byte 大部分情况都可以使用int代替,而如果需要严格对齐的话则应该用bytebyte UCHAR*
9、160; string/IntPtrunsigned char* MarshalAs(UnmanagedType.LPArray)byte/?(Intptr)char* stringLPCTSTR stringLPTSTR
10、0; MarshalAs(UnmanagedType.LPTStr) stringlong intulong uintHandle
11、 IntPtrHWND IntPtrvoid* IntPtrint intint* ref int*int
12、; IntPtrunsigned int uintCOLORREF uint API与C#的数据类型对应关系表API数据类型类型描述C#类型API数据类型类型描述C#类型WORD16位无符号整数ushortCHAR字符charLONG32位无符号
13、整数intDWORDLONG64位长整数longDWORD32位无符号整数uintHDC设备描述表句柄intHANDLE句柄,32位整数intHGDIOBJGDI对象句柄intUINT32位无符号整数uintHINSTANCE实例句柄intBOOL32位布尔型整数boolHWM窗口句柄intLPSTR指向字符的32位指针stringHPARAM32位消息参数intLPCSTR指向常字符的32位指针StringLPARAM32位消息参数intBYTE字节byteWPARAM32位消息参数int BOOL=System.Int32BOOLEAN=System.In
14、t32BYTE=System.UInt16CHAR=System.Int16COLORREF=System.UInt32DWORD=System.UInt32DWORD32=System.UInt32DWORD64=System.UInt64FLOAT=System.FloatHACCEL=System.IntPtrHANDLE=System.IntPtrHBITMAP=System.IntPtrHBRUSH=System.IntPtrHCONV=System.IntPtrHCONVLIST=System.IntPtrHCURSOR=System.IntPtrHDC=System.IntPtr
15、HDDEDATA=System.IntPtrHDESK=System.IntPtrHDROP=System.IntPtrHDWP=System.IntPtrHENHMETAHHFONT=System.IntPtrHGDIOBJ=System.IntPtrHGLOBAL=System.IntPtrHHOOK=System.IntPtrHICON=System.IntPtrHIMAGELIST=System.IntPtrHIMC=System.IntPtrHINSTANCE=System.IntPtrHKEY=System.IntPtrHLOCAL=System.IntPtrHMENU=Syste
16、m.IntPtrHMETAHMODULE=System.IntPtrHMONITOR=System.IntPtrHPALETTE=System.IntPtrHPEN=System.IntPtrHRGN=System.IntPtrHRSRC=System.IntPtrHSZ=System.IntPtrHWINSTA=System.IntPtrHWND=System.IntPtrINT=System.Int32INT32=System.Int32INT64=System.Int64LONG=System.Int32LONG32=System.Int32LONG64=System.Int64LONG
17、LONG=System.Int64LPARAM=System.IntPtrLPBOOL=System.Int16LPBYTE=System.UInt16LPCOLORREF=System.UInt32LPCSTR=System.StringLPCTSTR=System.StringLPCVOID=System.UInt32LPCWSTR=System.StringLPDWORD=System.UInt32LPHANDLE=System.UInt32LPINT=System.Int32LPLONG=System.Int32LPSTR=System.StringLPTSTR=System.Stri
18、ngLPVOID=System.UInt32LPWORD=System.Int32LPWSTR=System.StringLRESULT=System.IntPtrPBOOL=System.Int16PBOOLEAN=System.Int16PBYTE=System.UInt16PCHAR=System.CharPCSTR=System.StringPCTSTR=System.StringPCWCH=System.UInt32PCWSTR=System.UInt32PDWORD=System.Int32PFLOAT=System.FloatPHANDLE=System.UInt32PHKEY=
19、System.UInt32PINT=System.Int32PLCID=System.UInt32PLONG=System.Int32PLUID=System.UInt32PSHORT=System.Int16PSTR=System.StringPTBYTE=System.CharPTCHAR=System.CharPTSTR=System.StringPUCHAR=System.CharPUINT=System.UInt32PULONG=System.UInt32PUSHORT=System.UInt16PVOID=System.UInt32PWCHAR=System.CharPWORD=S
20、ystem.Int16PWSTR=System.StringREGSAM=System.UInt32SC_HANDLE=System.IntPtrSC_LOCK=System.IntPtrSHORT=System.Int16SIZE_T=System.UInt32SSIZE_=System.UInt32TBYTE=System.CharTCHAR=System.CharUCHAR=System.ByteUINT=System.UInt32UINT32=System.UInt32UINT64=System.UInt64ULONG=System.UInt32ULONG32=System.UInt3
21、2ULONG64=System.UInt64ULONGLONG=System.UInt64USHORT=System.UInt16WORD=System.UInt16WPARAM=System.IntPtr<-补充->Wtypes.h 中的非托管类型 非托管C 语言类型 托管类名 说明 HANDLE
22、 void* System.IntPtr 32 位 BYTE &
23、#160; unsigned char System.Byte 8 位 SHORT
24、160; short System.Int16 16 位 WORD
25、0; unsigned short System.UInt16 16 位 INT int
26、 System.Int32 32 位 UINT &
27、#160; unsigned int System.UInt32 32 位 LONG long
28、60; System.Int32 32 位 BOOL
29、0; long System.Int32 32 位 DWORD
30、 unsigned long System.UInt32 32 位 ULONG unsigned long Sys
31、tem.UInt32 32 位 CHAR char
32、 System.Char 用 ANSI 修饰。 LPSTR char*
33、160; System.String 或 System.StringBuilder 用 ANSI 修饰。 LPCSTR Const char* System.
34、String 或 System.StringBuilder 用 ANSI 修饰。 LPWSTR wchar_t* System.String 或 System.Strin
35、gBuilder 用 Unicode 修饰。 LPCWSTR Const wchar_t* System.String 或 System.StringBuilder 用 Unicode 修饰。 FLOAT
36、160; Float System.Single 32 位 DOUBLE &
37、#160; Double System.Double 64 位 C/C+中的结构类型数据在C#下的转换 在做项目移植的时候,经常会碰到数据类型的转换,而我这一次碰到的是C/
38、C+中的结构怎样转换到C#。折腾了一个晚上终于有一个完美的方案。例如我们在C/C+下的结构数据如下:typedef struct char sLibName 256 ; char sPathToLibrary 256 ; INT32 iEntries; INT32 iUsed;
39、160; UINT16 iSort; UINT16 iVersion; BOOLEAN fContainsSubDirectories; INT32 iReserved; LIBHEADER;我们想把它转成C#下的结构类型如下: public struct LIBHEADE
40、R public char sLibName; public char sPathToLibrary; public Int32 iEntries; public Int32 iUsed; p
41、ublic UInt16 iSort; public UInt16 iVersion; public Boolean fContainsSubDirectories; public Int32 iReserved; 看上去好像没问题了,呵呵呵,其实这样是不行的,我们得再给C#编译器一些信息,告诉它一些字符数组的大小。然后它们在C#下面长得样
42、子就变成这样: StructLayout(LayoutKind.Sequential) public struct LIBHEADER MarshalAs(UnmanagedType.ByValArray, SizeConst = 256) public char sLibName;
43、0; MarshalAs(UnmanagedType.ByValArray, SizeConst = 256) public char sPathToLibrary; public Int32 iEntries; public Int32 iUsed; public UInt16 iSort
44、; public UInt16 iVersion; public Boolean fContainsSubDirectories; public Int32 iReserved; 然后写一个函数负责转换。public StructType ConverBytesToStructure<StructType>(byte bytes
45、Buffer) / 检查长度。 if (bytesBuffer.Length != Marshal.SizeOf(typeof(StructType)
46、 throw new ArgumentException("bytesBuffer参数和structObject参数字节长度不一致。"); IntPtr bufferHandler = Marshal.AllocHGlobal(bytesB
47、uffer.Length); for (int index = 0; index < bytesBuffer.Length; index+) Marshal.WriteByte(bufferHandler, index, bytesBufferindex); StructType structObject = (StructTyp
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年起降场地勤人员待命室与设备储藏间设置
- 2026年高频电火花修整实现砂轮在线修锐成形
- 浙江省宁波市鄞州区重点中学2026年初三年级摸底考试(化学试题)试卷含解析
- 2026届江苏省重点中学初三5月月考(化学试题文)试题含解析
- 广西壮族自治区南宁市2026届初三下-(期中)化学试题试卷含解析
- 2026年河南省郑州市七十三中学初三中考保温金卷生物试题试卷含解析
- 2026年无人机航行服务系统数据安全技术要求解读
- 辽宁省大连市2026年中考化学试题模拟(三诊)试题含解析
- 2026年广西南宁马山县联考初三下期终教学质量监控测化学试题含解析
- 2026届河北省保定市级名校初三下学期联考综合试卷含解析
- 2026年甘肃事业单位联考笔试易考易错模拟试题(共500题)试卷后附参考答案
- 《化工HSE与清洁生产》课件-项目6 危险化学品
- 2026年六安职业技术学院单招职业适应性考试题库含答案详解(考试直接用)
- 运输企业物流标准化管理制度
- 2026年《禁毒法》知识测试题及答案(全优)
- 2026陕煤集团榆林化学有限责任公司招聘(162人)笔试模拟试题及答案解析
- 人工智能与文学创作的未来
- 【544】人际心理治疗(IPT)
- 2026中国藏语系高级佛学院招聘应届高校毕业生6人考试备考试题及答案解析
- 2026年春季学期统编版三年级下册语文教学计划(含进度表)(2024新教材)
- 2023年边缘计算相关项目实施方案
评论
0/150
提交评论