首页 > 开发 > .Net > 正文

Win32类型和.net类型的对应表

2020-02-03 15:57:26
字体:
来源:转载
供稿:网友
习惯用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.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






附:举一个声明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
);

最大的网站源码资源下载站,

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表