yulei's blog

有梦想更有要有行动,每天前进一小步,那么每年可以迈出一大步 QQ:65072096 MSN:coolsoft2001@sina.com

导航

关于C#调用winAPI参数类型对应关系的不完全总结

接连做了几个c# winform的程序,,都用到了调用API或着C++开发的dll,,对于调用其中方法时,相对应到c#中时,参数类型的变化做了个如下总结,以备自己日后查用,也贴出来大家共享。

引用Dll:
using System.Runtime.InteropServices;
[DllImport("xxx.dll")]
public static extern 返回类型 方法名(参数1,参数2,......);

参数对照:
char* ->string(或字节数组:ref byte[])
const char->string
int->int
int*->ref int
byte*->ref byte [址址引用的,一般在C#中相应的用ref 变量名]
序列结构要给c#加上特性:[StructLayout(LayoutKind.Sequential,Pack=1)]
结构内部的定长字符如:char str[11] ->[MarshalAs(UnmanagedType.ByValTStr,SizeConst=11)] string str;
不能用string[]类型去接收。
DWORD->int

posted on 2007-06-13 16:16  yulei  阅读(885)  评论(0编辑  收藏  举报