views:

139

answers:

3

We are seeing bad behavior in an application when it runs on Server 2008 (not R2). This is a WinForms application, and Control.MousePosition is returning {0,0} no matter where the mouse is on the screen... Control.MousePosition just makes a P/Invoke call to Win32 api GetCursorPos().

Followup:

I am using Control.MousePosition from WinForms, which calls GetCursorPos, and I can see that it definitely ignores the return value. Asking my question another way, "What can cause GetCursorPos() to suddenly start returning FALSE, when it worked only milliseconds before in the same process?"

// From .NET Reflector....
public static Point get_MousePosition()
{
    NativeMethods.POINT pt = new NativeMethods.POINT();
    UnsafeNativeMethods.GetCursorPos(pt);
    return new Point(pt.x, pt.y);
}

There is a control in our library that calls SetWindowsHookEx to hook WH_CALLWNDPROCRET for our entire process. I'm suspicious of this code, but tracing statements show that we're getting in + out of that hook cleanly.

What else should I be looking for?

Thanks, Dave

A: 

Not sure what could be doing that, but i've never called that function. I always just assumed it returned the position only if it was in the control, but it looks like I was wrong.

Have you tried Cursor.Position? (MSDN Link)

** I should add that this method uses the same code, basically, internally, but it might just be worth trying.

System.Windows.Forms.Cursor.Current.Position

//returns this for me:
{X = 1941 Y = 535}
    Empty: {X = 0 Y = 0}
    IsEmpty: False
    X: 1941
    Y: 535
Andrew Backer
+1  A: 

To find out what the problem is you should add some error checking. If GetCursorPos returns false, call GetLastError, then throw the resulting value as an exception.

JSBangs
+1  A: 

It turns out that this can happen with /LARGEADDRESSAWARE 32 bit applications running on 64 bit Server 2008 R1 only.

Dave Moore