Original Post
Hi, I am trying to call the winapi function GetCursorPos from C# However it throws a NullReferenceException, claiming that the "object reference has not been set to an instance of an object" (shouldn't that be instance of a class?) I largely followed a tutorial doing something very similar found here And cannot figure out what I am doing wrong.
[DllImport("user32.dll"),CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall]
public static extern int GetCursorPos(ref POINTL lpPoint);
[StructLayout(LayoutKind.Sequential)]
public class POINTL
{
public int x;
public int y;
}
...
public POINTL test()
{
POINTL p = new POINTL();
GetCursorPos(ref p);
return p.x;
}