C#与C++之间类型的对应{转}
Windows Data Type .NET Data Type
BOOL, BOOLEAN Boolean or Int32BSTR StringBYTE ByteCHAR CharDOUBLE DoubleDWORD Int32 or UInt32FLOAT SingleHANDLE (and all other handle types, such as HFONT and HMENU) IntPtr, UintPtr or HandleRef HRESULT Int32 or UInt32INT Int32LANGID Int16 or UInt16LCID Int32 or UInt32LONG Int32LPARAM IntPtr, UintPtr or ObjectLPCSTR StringLPCTSTR StringLPCWSTR StringLPSTR String or StringBuilder*LPTSTR String or StringBuilderLPWSTR String or StringBuilderLPVOID IntPtr, UintPtr or ObjectLRESULT IntPtrSAFEARRAY .NET array typeSHORT Int16TCHAR CharUCHAR SByteUINT Int32 or UInt32ULONG Int32 or UInt32VARIANT ObjectVARIANT_BOOL BooleanWCHAR CharWORD Int16 or UInt16WPARAM IntPtr, UintPtr or Object另: 在进行string转换时,需要加入前缀[MarshalAs(UnmanagedType.LPStr)]lpdword 对应于 ref intC/C++ C#HANDLE, LPDWORD, LPVOID, void* IntPtrLPCTSTR, LPCTSTR, LPSTR, char*, const char*, Wchar_t*, LPWSTR String [in], StringBuilder [in, out]DWORD, unsigned long, Ulong UInt32, [MarshalAs(UnmanagedType.U4)]bool boolLP<struct> [In] ref <struct>SIZE_T uintLPDWORD out uintLPTSTR [Out] StringBuilderPULARGE_INTEGER out ulongWORD uInt16Byte, unsigned char byteShort Int16Long, int Int32float singledouble doubleNULL pointer IntPtr.ZeroUint Uint32C#调用DLL文件时参数对应表Wtypes.h中的非托管类型 非托管 C语言类型 托管类名 说明 HANDLE void* System.IntPtr 32 位 BYTE unsigned char System.Byte 8 位 SHORT short System.Int16 16 位 WORD unsigned short System.UInt16 16 位 INT int System.Int32 32 位 UINT unsigned int System.UInt32 32 位 LONG long System.Int32 32 位 BOOL long System.Int32 32 位 DWORD unsigned long System.UInt32 32 位 ULONG unsigned long System.UInt32 32 位 CHAR char System.Char 用 ANSI 修饰。LPSTR char* System.String 或 System.StringBuilder 用 ANSI 修饰。 LPCSTR Const char* System.String 或System.StringBuilder 用 ANSI 修饰。 LPWSTR wchar_t* System.String 或System.StringBuilder 用 Unicode 修饰。 LPCWSTR Const wchar_t* System.String 或System.StringBuilder 用 Unicode 修饰。 FLOAT Float System.Single 32 位 DOUBLE Double System.Double 64 位习惯用C#写东西,但平时又会碰到很多要用win32 API的地方,所以经常要用DllImport,但win32函数的类型写法是很庞杂的,相信为之困扰的不止我一个,现在我整理一份我个人的理解如下,希望高人不吝赐教。我的基本原则有如下几点:1、下面都是针对32位系统的,所以int是32位.long也是32位;2、各种句柄类的(H开头),我认为一律是System.IntPtr,到目前为止没发现出错;如果哪位在使用中出错,请指出;3、LP和P,我实在不懂(对C 不太了解),对于LP和P开头的函数,如果是和STR有关的,一律写为System.String,像PLCID这样指向什么东西的,写为System.UInt32(因为指向另一个地址,那就是指针,指针是32位吧),int之类的数值型,那我就写为int[],以方便.net程序引用(写成System.UInt32的话,给API调用应该也不会出错,但.net程序就不好引用了)如有意见,欢迎指教。谢谢BOOL=System.Int32BOOLEAN=System.Int32BYTE=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.IntPtrHDDEDATA=System.IntPtrHDESK=System.IntPtrHDROP=System.IntPtrHDWP=System.IntPtrHENHMETAFILE=System.IntPtrHFILE=System.IntPtrHFONT=System.IntPtrHGDIOBJ=System.IntPtrHGLOBAL=System.IntPtrHHOOK=System.IntPtrHICON=System.IntPtrHIMAGELIST=System.IntPtrHIMC=System.IntPtrHINSTANCE=System.IntPtrHKEY=System.IntPtrHLOCAL=System.IntPtrHMENU=System.IntPtrHMETAFILE=System.IntPtrHMODULE=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.Int64LONGLONG=System.Int64LPARAM=System.IntPtrLPBOOL=System.Int16[]LPBYTE=System.UInt16[]LPCOLORREF=System.UInt32[]LPCSTR=System.StringLPCTSTR=System.StringLPCVOID=System.UInt32LPCWSTR=System.StringLPDWORD=System.UInt32[]LPHANDLE=System.UInt32LPINT=System.Int32[]LPLONG=System.Int32[]LPSTR=System.StringLPTSTR=System.StringLPVOID=System.UInt32LPWORD=System.Int32[]LPWSTR=System.StringLRESULT=System.IntPtrPBOOL=System.Int16[]PBOOLEAN=System.Int16[]PBYTE=System.UInt16[]PCHAR=System.Char[]PCSTR=System.StringPCTSTR=System.StringPCWCH=System.UInt32PCWSTR=System.UInt32PDWORD=System.Int32[]PFLOAT=System.Float[]PHANDLE=System.UInt32PHKEY=System.UInt32PINT=System.Int32[]PLCID=System.UInt32PLONG=System.Int32[]PLUID=System.UInt32PSHORT=System.Int16[]PSTR=System.StringPTBYTE=System.Char[]PTCHAR=System.Char[]PTSTR=System.StringPUCHAR=System.Char[]PUINT=System.UInt32[]PULONG=System.UInt32[]PUSHORT=System.UInt16[]PVOID=System.UInt32PWCHAR=System.Char[]PWORD=System.Int16[]PWSTR=System.StringREGSAM=System.UInt32SC_HANDLE=System.IntPtrSC_LOCK=System.IntPtrSHORT=System.Int16SIZE_T=System.UInt32SSIZE_=System.UInt32TBYTE=System.CharTCHAR=System.CharUCHAR=System.Wtypes.h 中的非托管类型 非托管 C 语言类型 托管类名 说明 HANDLE void* System.IntPtr 在 32 位 Windows 操作系统上为 32 位,在 64 位 Windows 操作系统上为 64 位。BYTE unsigned char System.Byte 8 位SHORT short System.Int16 16 位WORD unsigned short System.UInt16 16 位INT int System.Int32 32 位UINT unsigned int System.UInt32 32 位LONG long System.Int32 32 位BOOL long System.Int32 32 位DWORD unsigned long System.UInt32 32 位ULONG unsigned long System.UInt32 32 位CHAR char System.Char 用 ANSI 修饰。LPSTR char* System.String 或 System.Text.StringBuilder 用 ANSI 修饰。LPCSTR Const char* System.String 或 System.Text.StringBuilder 用 ANSI 修饰。LPWSTR wchar_t* System.String 或 System.Text.StringBuilder 用 Unicode 修饰。LPCWSTR Const wchar_t* System.String 或 System.Text.StringBuilder 用 Unicode 修饰。FLOAT Float System.Single 32 位DOUBLE Double System.Double 64 位C#与C++之间类型的对应{转}的更多相关文章
- (转)C#与C++之间类型的对应
C#与C++之间类型的对应 Windows Data Type .NET Data Type BOOL, BOOLEAN Boolean or Int32 BSTR String BYTE Byte ...
- Go语言string,int,int64 ,float之间类型转换方法
(1)int转string ? 1 2 s := strconv.Itoa(i) 等价于s := strconv.FormatInt(int64(i), 10) (2)int64转string ? 1 ...
- C/C++与C#之间类型的对应
最近在研究pos打印机相关功能, 调用winapi以及跨进程通信等,都涉及到类型之间的转换. C/C++ C# HANDLE, LPDWORD, LPVOID, void* IntPtr LPCTST ...
- C#与C++之间类型的对应
Windows Data Type .NET Data Type BOOL, BOOLEAN Boolean or Int32 BSTR String BYTE Byte CHAR Char DOUB ...
- [转]Go语言string,int,int64 ,float之间类型转换方法
1 正文 (1)int转string s := strconv.Itoa(i) 等价于s := strconv.FormatInt(int64(i), 10) (2)int64转string i := ...
- C#与C++之间类型对应关系
//C++中的DLL函数原型为 //extern "C" __declspec(dllexport) bool 方法名一(const char* 变量名1, unsigned c ...
- 【opencv基础】opencv和dlib库中rectangle类型之间的转换
前言 最近使用dlib库的同时也会用到opencv,特别是由于对dlib库的画图函数不熟悉,都想着转换到opencv进行show.本文介绍一下两种开源库中rectangle类型之间的转换. 类型说明 ...
- Oracle中的数据类型和数据类型之间的转换
Oracle中的数据类型 /* ORACLE 中的数据类型: char 长度固定 范围:1-2000 VARCHAR2 长度可变 范围:1-4000 LONG 长度可变 最大的范围2gb 长字符类型 ...
- 浩哥解析MyBatis源码(十)——Type类型模块之类型处理器
原创作品,可以转载,但是请标注出处地址:http://www.cnblogs.com/V1haoge/p/6715063.html 1.回顾 之前的两篇分别解析了类型别名注册器和类型处理器注册器,此二 ...
随机推荐
- List集合实战总结
//构造被分隔的集合 List<object> list = new List<object>(); for (int i = 0; i <= 100; i++) { l ...
- 第二十章 数据访问(In .net4.5) 之 使用LINQ
1. 概述 .net3.5中新添加给C#的LINQ查询,提供了直观便捷的数据查询方式.并且支持多种数据源的查询. 本章介绍标准的LINQ操作,如何用最优的方式使用LINQ 以及 LINQ to XML ...
- 刀哥多线程之并发队列gcd-05-dispatch_queue_concurrent
并发队列 特点 以先进先出的方式,并发调度队列中的任务执行 如果当前调度的任务是同步执行的,会等待任务执行完成后,再调度后续的任务 如果当前调度的任务是异步执行的,同时底层线程池有可用的线程资源,会再 ...
- 算法系列1《DES》
1. DES算法简介 DES算法全称为Data Encryption Standard,即数据加密算法,它是IBM公司于1975年研究成功并公开发表的.DES算法的入口参数有三个:Key.Data.M ...
- hdu 5112 A Curious Matt
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5112 A Curious Matt Description There is a curious ma ...
- MicrosoftProjectOxford 微软牛津计划
光学字符识别 上传本地图片或者提供一个图片URL,查看光学字符识别的演示. 视觉特征分析 上传本地图片或者提供一个图片URL,查看视觉特征分析的演示. 缩略图 上传本地图片或者提供一个图片URL,查看 ...
- orcherd 汉化
点击这里下载汉化包,此汉化包是在是在前人的基础上精心整理修改的,后续汉化版本随时升级更新. Orchard汉化包 下载后解压缩后打开后看到如下文件夹(App_Data.Core.Modules.The ...
- 两个有用的shell工具总结
shell工具之一:sed sed基础 sed编辑器被称作流编辑器,与常见的交互式文本编辑器刚好相反.文本编辑器可以通过键盘来交互式地插入.删除.替换文本中的数据:而流编辑器是基于一组预先的规则来编辑 ...
- [转]webrtc学习: 部署stun和turn服务器
[转]webrtc学习: 部署stun和turn服务器 http://www.cnblogs.com/lingdhox/p/4209659.html webrtc的P2P穿透部分是由libjingle ...
- 谈谈C#中的 Dispose 和 Finalize
主要有一下几点需要知道: 1. Dispose需要实现IDisposable接口. Finalize就是c#中的析构方法,方法名以~开始. 2. Dispose由开发人员代码调用,而Finalize由 ...