Hi,
I've implemented a hook (WH_CALLWNDPRO), using the sample posted at
MSDN magazine.
( see url:
http://msdn.microsoft.com/msdnmag/is...0/CuttingEdge/
)
I succeed in intercepting the relevant messages, however if I try to
change the parameter to the original message, it doesn't work.
It seems like I'm doing something wrong with the Interop services.
E.g.
When intercepting WM_MOVING, I want keep the window, at a certain
coordinate,
which in C++ would look like:
case WM_MOVING:
{
RECT* p = (RECT*)lParam;
p->left = 10;
break;
}
in C#, in the hook proc the code looks like:
{ // "**unwrap**"
// lParamA is the argument to the hook proc, of type IntPtr
CWPSTRUCT cwp = (Win32.CWPSTRUCT)Marshal.PtrToStructure(lParamA,
typeof(Win32.CWPSTRUCT));
then in case of WM_MOVING:
Win32.RECT rect = (Win32.CWPSTRUCT)Marshal.PtrToStructure(cwp.lParam ,
typeof(Win32.RECT));
}
Now, the values in rect are ok.
I change them and the copy back:
// copy rect
Marshal.StructureToPtr(rect, cwp.lParam, true);
// copy CWPSTRUCT
Marshal.StructureToPtr(cwp, lParamA, true);
here if u look again at cwp, using the block code mark as "**unwrap**",
I get the correct (changed) value.
However, eventually it doesnt seem to affect the hooked window,
so I guess something is missing or incorrect.
Any help is appreciated.
Si.