日期:2014-05-18  浏览次数:20643 次

关于API函数的声明,一头雾水
我现在要用一个函数user32.dll,在C#中有两种不同的申明,虽然都可以用,但很想搞清楚两个的区别,还有以后要用的别的函数的时候,要怎么写申明块?


[DllImport("user32.dll")]
static extern bool SetCursorPos(int X, int Y);


[System.Runtime.InteropServices.DllImport("user32.dll" , EntryPoint="SetCursorPos")]
public extern static int SetCursorPos ( int x , int y );


上面都个都可以用,为什么都可以?别的函数,这个函数的其他方法要怎么申明?

------解决方案--------------------
都一样,只不过第一个在程序代码最开始写有 using System.Runtime.InteropServices
所以不用每次都写全
EntryPoint="SetCursorPos" 这个是参数,代表函数的入口点。另外还有一些特性参数,你可以上网查一下

 SetLastError=true,CharSet=CharSet.Auto , ExactSpelling=false,CallingConvention=CallingConvention.StdCall)