原文 C#中调用Windows API时的数据类型对应关系

BOOL=System.Int32

BOOLEAN=System.Int32

BYTE=System.UInt16

CHAR=System.Int16

COLORREF=System.UInt32

DWORD=System.UInt32

DWORD32=System.UInt32

DWORD64=System.UInt64

FLOAT=System.Float

HACCEL=System.IntPtr

HANDLE=System.IntPtr

HBITMAP=System.IntPtr

HBRUSH=System.IntPtr

HCONV=System.IntPtr

HCONVLIST=System.IntPtr

HCURSOR=System.IntPtr

HDC=System.IntPtr

HDDEDATA=System.IntPtr

HDESK=System.IntPtr

HDROP=System.IntPtr

HDWP=System.IntPtr

HENHMETAFILE=System.IntPtr

HFILE=System.IntPtr

HFONT=System.IntPtr

HGDIOBJ=System.IntPtr

HGLOBAL=System.IntPtr

HHOOK=System.IntPtr

HICON=System.IntPtr

HIMAGELIST=System.IntPtr

HIMC=System.IntPtr

HINSTANCE=System.IntPtr

HKEY=System.IntPtr

HLOCAL=System.IntPtr

HMENU=System.IntPtr

HMETAFILE=System.IntPtr

HMODULE=System.IntPtr

HMONITOR=System.IntPtr

HPALETTE=System.IntPtr

HPEN=System.IntPtr

HRGN=System.IntPtr

HRSRC=System.IntPtr

HSZ=System.IntPtr

HWINSTA=System.IntPtr

HWND=System.IntPtr

INT=System.Int32

INT32=System.Int32

INT64=System.Int64

LONG=System.Int32

LONG32=System.Int32

LONG64=System.Int64

LONGLONG=System.Int64

LPARAM=System.IntPtr

LPBOOL=System.Int16[]

LPBYTE=System.UInt16[]

LPCOLORREF=System.UInt32[]

LPCSTR=System.String

LPCTSTR=System.String

LPCVOID=System.UInt32

LPCWSTR=System.String

LPDWORD=System.UInt32[]

LPHANDLE=System.UInt32

LPINT=System.Int32[]

LPLONG=System.Int32[]

LPSTR=System.String

LPTSTR=System.String

LPVOID=System.UInt32

LPWORD=System.Int32[]

LPWSTR=System.String

LRESULT=System.IntPtr

PBOOL=System.Int16[]

PBOOLEAN=System.Int16[]

PBYTE=System.UInt16[]

PCHAR=System.Char[]

PCSTR=System.String

PCTSTR=System.String

PCWCH=System.UInt32

PCWSTR=System.UInt32

PDWORD=System.Int32[]

PFLOAT=System.Float[]

PHANDLE=System.UInt32

PHKEY=System.UInt32

PINT=System.Int32[]

PLCID=System.UInt32

PLONG=System.Int32[]

PLUID=System.UInt32

PSHORT=System.Int16[]

PSTR=System.String

PTBYTE=System.Char[]

PTCHAR=System.Char[]

PTSTR=System.String

PUCHAR=System.Char[]

PUINT=System.UInt32[]

PULONG=System.UInt32[]

PUSHORT=System.UInt16[]

PVOID=System.UInt32

PWCHAR=System.Char[]

PWORD=System.Int16[]

PWSTR=System.String

REGSAM=System.UInt32

SC_HANDLE=System.IntPtr

SC_LOCK=System.IntPtr

SHORT=System.Int16

SIZE_T=System.UInt32

SSIZE_=System.UInt32

TBYTE=System.Char

TCHAR=System.Char

UCHAR=System.Byte

UINT=System.UInt32

UINT32=System.UInt32

UINT64=System.UInt64

ULONG=System.UInt32

ULONG32=System.UInt32

ULONG64=System.UInt64

ULONGLONG=System.UInt64

USHORT=System.UInt16

WORD=System.UInt16

WPARAM=System.IntPtr

C++            C#
=====================================
WORD              ushort
DWORD             uint
UCHAR             int/byte   大部分情况都可以使用int代替,而如果需要严格对齐的话则应该用bytebyte 
UCHAR*            string/IntPtr
unsigned char*    [MarshalAs(UnmanagedType.LPArray)]byte[]/?(Intptr)
char*             string/StringBuilder
LPCTSTR           string
LPTSTR            [MarshalAs(UnmanagedType.LPTStr)] string
long              int
ulong             uint
Handle            IntPtr
HWND              IntPtr
void*             IntPtr
int               int
int*              ref int
*int              IntPtr
unsigned int      uint
COLORREF          uint

附:举一个声明API的例子

[ DllImport( "Kernel32.dll" )]

public static extern System.UInt32 VirtualAllocEx(

System.IntPtr hProcess,

System.UInt32 lpAddress,

System.UInt32 dwSize,

System.UInt32 flAllocationType,

System.UInt32 flProtect

);

转:http://www.cnblogs.com/ausoldier/archive/2007/12/07/986141.html

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#中调用Windows API时的数据类型对应关系的更多相关文章

  1. C#中调用Windows API的要点 .

    介绍 API(Application Programming Interface),我想大家不会陌生,它是我们Windows编程的常客,虽然基于.Net平台的C#有了强大的类库,但是,我们还是不能否认 ...

  2. [windows菜鸟]C#中调用Windows API的技术要点说明

    在.Net Framework SDK文档中,关于调用Windows API的指示比较零散,并且其中稍全面一点的是针对Visual Basic .net讲述的.本文将C#中调用API的要点汇集如下,希 ...

  3. [windows菜鸟]C#中调用Windows API参考工具

    很多windows API都不知道签名,可以从下面几种方式进行查询 1.微软出的工具 P/Invoke Interop Assistant version 1.0 2.网站 pinvoke.net 3 ...

  4. MFC中调用Windows API函数的方式

    windows aoi 函数的调用前面加::

  5. 在VBA中使用Windows API

    VBA是一种强大的编程语言,可用于自定义Microsoft Office解决方案.通过使用VBA处理一个或多个Office应用程序对象模型,可以容易地修改Office应用程序的功能或者能够使两个或多个 ...

  6. VBS调用Windows API函数

    Demon's Blog 忘记了,喜欢一个人的感觉 Demon's Blog  »  程序设计  »  VBS调用Windows API函数 « 用VBS修改Windows用户密码 在VB中创建和使用 ...

  7. 浅议Delphi中的Windows API调用(举的两个例子分别是String和API,都不错,挺具有代表性)

    浅议Delphi中的Windows API调用http://tech.163.com/school • 2005-08-15 10:57:41 • 来源: 天极网为了能在Windows下快速开发应用程 ...

  8. 在Angular.js中的H5页面调用Web api时跨域问题处理

    /// <summary> /// 被请求时 /// 在Angular.js中的H5页面调用Web api时跨域问题处理 /// </summary> /// <para ...

  9. C#调用windows API的一些方法

    使用C#调用windows API(从其它地方总结来的,以备查询) C#调用windows API也可以叫做C#如何直接调用非托管代码,通常有2种方法: 1.  直接调用从 DLL 导出的函数. 2. ...

随机推荐

  1. struts的常用配置

    struts.xml <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUB ...

  2. URAL 1009 K-based Numbers

    题目:Click here #include <bits/stdc++.h> using namespace std; typedef long long ll; const int IN ...

  3. java多线程——同步块synchronized详解

    Java 同步块(synchronized block)用来标记方法或者代码块是同步的.Java同步块用来避免竞争.本文介绍以下内容: Java同步关键字(synchronzied) 实例方法同步 静 ...

  4. django 基础入门(二)

    一.关于数据库 1.首先django 1.9以上等版本不支持pymysql,因此需要做一些调整. 比如在settings.py 加入一段代码: import pymysql pymysql.insta ...

  5. float与position

    使用float会使块级元素的宽高表现为包裹内容(在不设定宽高的情况下)  这是当然的  我们使用float就是使几个div排在一行 当然不可能在宽度上撑满父元素啦  至于高度 不论有没有float 高 ...

  6. python 中 json的处理

    python中的json对象,其实就是字典类型. 利用json模块,可以将字符串类型的json串转换为 json对象(字典对象),也可以将json对象(字典对象)转换为字符串对象. 代码如: #cod ...

  7. Apache BeanUtils 1.9.2 官方入门文档

    为什么需要Apache BeanUtils? Apache BeanUtils 是 Apache开源软件组织下面的一个项目,被广泛使用于Spring.Struts.Hibernate等框架,有数千个j ...

  8. error: property&#39;s synthesized getter follows Cocoa naming convention for returning &#39;owned&#39; objects

    出现这样的情况,主要是属性名中包括  keyword. You can solve this by: Renaming that property: @property (strong, nonato ...

  9. LoadImage()的使用

    系统中的定义是: WINUSERAPIHANDLEWINAPILoadImageA(    HINSTANCE,    LPCSTR,    UINT,    int,    int,    UINT ...

  10. [置顶] C++ Pirate: Lambda vs Bind

    Lambda 与 Bind的性能比较 转载请说明出处:http://blog.csdn.net/cywosp/article/details/9379403 先让我们看看下面函数: template ...