虚方法达成多态承袭,API时的数据类型对应关系

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

BOOL=System.Int32  

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

前不久做WinForm项目时,要调用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
 

虚方法达成多态承袭,API时的数据类型对应关系。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
 

附:举七个扬言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 );

//所谓被覆写,就是派生类中存在同名函数,且使用了关键字override。
namespace 虚方法实现多态继承
{
    public class Animal
    {
        public virtual void eat()//virtual关键字,定义虚方法
        {
            Console.WriteLine("动物都是用嘴吃\n");
        }
    }
    public class peopel:Animal
    {
        public override void eat()//override关键字,重写基类中的虚方法
        {
            Console.WriteLine("人:煮熟了吃\n");
        }
    }
    public class dog : Animal
    {
        public override void eat()
        {
            Console.WriteLine("狗:怎么都能吃\n");
        }
    }
    class Program
    {
        //下面的这三种方式是一样的结果
        static void Main(string[] args)
        {
            Animal peopel = new peopel();//实例化基类的子类对象
            Animal dog = new dog();
            Animal animel = new Animal();
            peopel.eat();
            dog.eat();
            animel.eat();

           /******************************/ 

            Animal[] a=new Animal[3];
            a[0] = new peopel();
            a[1] = new dog();
            a[2] = new Animal();
            a[0].eat();
            a[1].eat();
            a[2].eat();

            /******************************/            

            foreach(Animal aa in a)
            {
                if (aa == null)
                {
                    Console.ReadKey();
                    return;
                }
                aa.eat();
            }
            Console.ReadKey();

        }
    }
}

BOOLEAN=System.Int32  

在C#中做过多运用必要选取win3二API,但开采原型函数的局地数据类型看起来13分讨厌,乃至在C#中“未有”那种数据类型,查阅了一下材质,数据类型对应关系整理如下,希望对大家有用:

BYTE=System.UInt16  

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

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
UCHA途观             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

 

附:举3个宣称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

 );

 

转:

 

 

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 位

网站地图xml地图