Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / .NET SDK / November 2006

Tip: Looking for answers? Try searching our database.

How to use Win32 MOUSEHOOKSTRUCT structure with C# ?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
aimoz@intechinfo.fr - 13 Nov 2006 15:05 GMT
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... ?

Thanks for your answer
Mattias Sjögren - 13 Nov 2006 18:13 GMT
>Am i doing something wrong, do I forgot something... ?

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

Mattias

Signature

Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

aimoz@intechinfo.fr - 14 Nov 2006 09:39 GMT
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);

Thanks for your answer.
Ben Voigt - 14 Nov 2006 14:27 GMT
> Here is the POINT type declaration :
>
[quoted text clipped - 3 lines]
>        public int y;
>    }

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

> and the callback function signature :
>
>        // Filter function delegate
>        public delegate int HookProc(int code, IntPtr wParam, IntPtr
> lParam);

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

> Thanks for your answer.
aimoz@intechinfo.fr - 14 Nov 2006 20:35 GMT
I've tried with your information, now it works.
Thank for your help.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.