0
Reply

Global WH_MOUSE Hook can't read MOUSEHOOKSTRUCT from LParam

Ask a question
Jon

Jon

17y
4.2k
1
I have a C++ DLL that sends my C# application global messages that are hooked with WH_MOUSE (not WH_MOUSE_LL).  However, when I try to do this:

MOUSEHOOKSTRUCT MyMouseHookStruct = (MOUSEHOOKSTRUCT)Marshal.PtrToStructure(m.LParam, typeof(MOUSEHOOKSTRUCT));

For a message that belongs to a window other than mine I get this error:
"AccessVioliationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

Is this by design?  "m.LParam" isn't 0 (or null), it is above zero, so I'm assuming it should be pointing to a valid memory location, but it fails everytime, unless it's for my own window.

Does anyone have any thoughts?

Thanks,
Jon

Next Recommended Forum