I have to develop a C# application which needs to make use of advanced gestures to improve the user experience. In order to do so, I need to get information when a certain gesture is invoked by the user.
Because WndProc is a taboo in .NET CE, I'm using OpenNETCE's Application2 and IMessageFilter classes to receive WM-traffic.
In my MessageFilter I look for WM_GESTURE messages and that's where I'm stuck.
I just don't get any meaningful result by calling this function:
https://msdn.microsoft.com/en-us/library/ee503217.aspx
BOOL GetGestureInfo(
HGESTUREINFO hGestureInfo
PGESTUREINFO pGestureInfo
);
Here's the relevant code:
public class TestMessageFilter : IMessageFilter
{
[DllImport("coredll", SetLastError = true)]
public static extern bool GetGestureInfo(IntPtr hGesture, ref GESTUREINFO lGesture);
public static uint WM_GESTURE = 0x0119;
public bool PreFilterMessage(ref Microsoft.WindowsCE.Forms.Message m)
{
// ...
if (m.Msg == WM_GESTURE)
{
GESTUREINFO gi = new GESTUREINFO() {
cbSize = (uint)Marshal.SizeOf(typeof(GESTUREINFO))
};
bool success = GetGestureInfo(m.LParam, ref gi);
if (success)
{
// ...
}
else
{
int x = Marshal.GetLastWin32Error(); // => 87
}
}
// ...
}
[StructLayout(LayoutKind.Sequential)]
public struct POINTS
{
public short x;
public short y;
}
[StructLayout(LayoutKind.Sequential)]
public struct GESTUREINFO
{
public UInt32 cbSize;
public UInt32 dwFlags;
public UInt32 dwID;
public IntPtr hwndTarget;
public POINTS ptsLocation;
public UInt32 dwInstanceID;
public UInt32 dwSequenceID;
public UInt64 ullArguments;
public UInt32 cbExtraArguments;
}
}
It always gives me error code 87.
ERROR_INVALID_PARAMETER
Why does it not work? What's invalid? It's driving me nuts...
Many, many thanks in advance.
Edit: I found this post on the msdn forums which uses an IntPtr instead of a reference to the GestureInfo as the second parameter.
[DllImport("coredll.dll")]
static extern int GetGestureInfo(IntPtr hGestureInfo, [In, Out] IntPtr pGestureInfo);
// ...
GESTUREINFO gi = new GESTUREINFO();
gi.cbSize = 48;
IntPtr outGI = Marshal.AllocHGlobal(48);
Marshal.StructureToPtr(gi, outGI, false);
bool bResult = (GetGestureInfo(lParam, outGI) == 1);
bool bHandled = false;
Marshal.FreeHGlobal(outGI);
Marshal.PtrToStructure(outGI, gi);
// ...
But it procudes the same ERROR_INVALID_PARAMETER error for me.
Does nobody have a solution or another approach to obtain a GestureInfo from C#?