Ok, found out that the function signature was indeed incorrect on that web
site example, and I am now doing this:
[DllImport("user32.dll", EntryPoint = "GetDesktopWindow")]
public static extern IntPtr GetDesktopWindow();
[DllImport("user32.dll", EntryPoint = "GetDC")]
public static extern IntPtr GetDC(IntPtr ptr);
[DllImport("user32.dll", EntryPoint = "ReleaseDC")]
public static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDc);
and this is the relevant code for getting color at mouse position:
Point p = Control.MousePosition;
IntPtr dc = GetDC(GetDesktopWindow());
Color c = ColorTranslator.FromWin32(GetPixel(dc, p.X, p.Y));
panel.BackColor = c;
panel.Refresh();
ReleaseDC(GetDesktopWindow(), dc);
now it doesn't throw an exception but the problem now is that GetPixel
function seems to always be returning White, no matter what I mouse over. I
can confirm it's getting a correct mouse position and it's moving, and I am
mousing ove rimages which contain almost no white at all.