HI i have a following code that reads mouse event
using System;
using System.Drawing;
using System.Reflection;
using System.Runtime.InteropServices;
public enum MouseKeyType
{
MouseMoveOnly=512,
MouseLeftKeyDown=513,
MouseLeftKeyup=514,
MouseRightKeyDown = 516,
MouseRightKeyup = 517,
MouseMiddleKeyDown = 519,
MouseMiddleKeyup = 520,
MouseScroll=522
}
[StructLayout(LayoutKind.Sequential)]
public class MouseEventData
{
public Point point;
private int mouseData;
private int flags;
public int time;
//public int dwExtraInfo;
public bool IsScrollUp
{
get
{
return mouseData > -1;
}
}
public MouseKeyType mouseKeyType;
}
public class gc
{
// Event
public delegate void gcMouseEvents(object source, MouseEventData e);
public event gcMouseEvents gcevent;
// WIN32 hook
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall, SetLastError = true)]
private static extern int SetWindowsHookEx( int idHook, HookProc lpfn, IntPtr hMod, int dwThreadId);
//just a delegate to simplify the type of
private delegate int HookProc(int nCode,int wParam, IntPtr lParam);
private HookProc _hookCallback;
public gc()
{
_hookCallback = new HookProc((x,y,z)=>
{
//string output = JsonConvert.SerializeObject(ptr);
//Console.WriteLine(output);
if (gcevent!=null)
{
MouseEventData ptr = (MouseEventData)Marshal.PtrToStructure(z, typeof(MouseEventData));
ptr.mouseKeyType = (MouseKeyType)y;
gcevent(this, ptr);
}
return 0;
});
SetWindowsHookEx(
14,
_hookCallback,
Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0]),
0);
}
}
This seems to work fine in a form application when code placed in that project. BUt when code is placed in an console library and and a reference added then it dosent work.. I tried adding dlls to windows form etc and played with static etc but nothing seems to work when its placed in a dll