Groups | Blog | Home
all groups > dotnet sdk > november 2006 >

dotnet sdk : How to use Win32 MOUSEHOOKSTRUCT structure with C# ?


aimoz NO[at]SPAM intechinfo.fr
11/13/2006 7:05:02 AM
Hello,
I'm writing a .NET program which is using a mouse hook but everytime the
filter function is invoked a argumentException is thrown.
Here is the part of code i'm using to convert the structure :

this.MouseData = (MouseHookStruct)Marshal.PtrToStructure(lParam,
typeof(MouseHookStruct));

And here my declaration of the structure :

//Declare the wrapper managed MouseHookStruct class.
[StructLayout(LayoutKind.Sequential)]
public class MouseHookStruct
{
public POINT pt;
public int hwnd;
public int wHitTestCode;
public int dwExtraInfo;
}

Am i doing something wrong, do I forgot something... ?

Mattias Sjögren
11/13/2006 7:13:56 PM
[quoted text, click to view]

How did you declare the POINT type? What about the callback method
signature?


Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
aimoz NO[at]SPAM intechinfo.fr
11/14/2006 1:39:01 AM
Here is the POINT type declaration :

public class POINT
{
public int x;
public int y;
}

and the callback function signature :

// Filter function delegate
public delegate int HookProc(int code, IntPtr wParam, IntPtr lParam);

Ben Voigt
11/14/2006 8:27:25 AM

"aimoz@intechinfo.fr" <aimozintechinfofr@discussions.microsoft.com> wrote in
message news:9719EE2C-C0CD-4FB6-8B87-0E30F104837F@microsoft.com...
[quoted text, click to view]

Should definitely be a struct, not a class:
http://pinvoke.net/default.aspx/Structures.POINT

[quoted text, click to view]

That looks mostly ok:
http://pinvoke.net/default.aspx/user32/SetWindowsHookEx.html
http://www.pinvoke.net/default.aspx/Delegates/HookProc.html

[quoted text, click to view]

aimoz NO[at]SPAM intechinfo.fr
11/14/2006 12:35:01 PM
I've tried with your information, now it works.
AddThis Social Bookmark Button