A
Andy
Hi all. My question is simple. How can I get mouse information from an
unmanaged DLL called from a C# windows application.
I have a very very simple C# windows application that simply overrides
the OnPaint command like so:
protected override void OnPaint(PaintEventArgs e)
{
Wrapper.OnIdle(this.Handle);
this.Invalidate(true);
}
And I the Wrapper class is defined as:
public class Wrapper
{
[ DllImport( "CppDLL.dll", EntryPoint="OnIdle" ) ]
public static extern void NDL_OnIdle(IntPtr hWnd);
}
In my C++ DLL, my OnIdle function looks like:
extern "C" PINVOKELIB_API int OnIdle(HWND hWnd)
{
// TESTING...
POINT kPt;
HDC hdc = ::GetDC(hWnd);
int iResult = ::GetCurrentPositionEx(hdc,&kPt);
if (kPt.x != 0 || kPt.y !=0)
{
int x;
x= 0; // My BREAKPOINT here never gets hit.
}
return 1;
}
In the above code, my x,y position of the mouse is never anything
other than zero. What is wrong???? I've asserted the the hdc and
iResult values are good. And I've also used the hWnd for doing things
like ::GetClientRect(hWnd,&rect); and it works... it seems that only
mouse calls don't work. I had attempted to use DirectInput from my
unmanaged DLL. I had keyboard and gamepad working... but the mouse
would not. That is why I've made the simple test above... even that
won't work. Any ideas??
Thanks,
Andy.
(e-mail address removed)
unmanaged DLL called from a C# windows application.
I have a very very simple C# windows application that simply overrides
the OnPaint command like so:
protected override void OnPaint(PaintEventArgs e)
{
Wrapper.OnIdle(this.Handle);
this.Invalidate(true);
}
And I the Wrapper class is defined as:
public class Wrapper
{
[ DllImport( "CppDLL.dll", EntryPoint="OnIdle" ) ]
public static extern void NDL_OnIdle(IntPtr hWnd);
}
In my C++ DLL, my OnIdle function looks like:
extern "C" PINVOKELIB_API int OnIdle(HWND hWnd)
{
// TESTING...
POINT kPt;
HDC hdc = ::GetDC(hWnd);
int iResult = ::GetCurrentPositionEx(hdc,&kPt);
if (kPt.x != 0 || kPt.y !=0)
{
int x;
x= 0; // My BREAKPOINT here never gets hit.
}
return 1;
}
In the above code, my x,y position of the mouse is never anything
other than zero. What is wrong???? I've asserted the the hdc and
iResult values are good. And I've also used the hWnd for doing things
like ::GetClientRect(hWnd,&rect); and it works... it seems that only
mouse calls don't work. I had attempted to use DirectInput from my
unmanaged DLL. I had keyboard and gamepad working... but the mouse
would not. That is why I've made the simple test above... even that
won't work. Any ideas??
Thanks,
Andy.
(e-mail address removed)