473,466 Members | 1,368 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Changing hook (WH_CALLWNDPROC) arguments


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.

Dec 5 '05 #1
1 7653
I have seen that before, when you convert, the first time everything is
fine and then it messes up. This happens because when you put together
the Struct, you need to specify the padding value, so for example:
Notice the Pack field:
[StructLayout (LayoutKind.Sequential, Pack=2)]
public class SISHalObs
{
[MarshalAs (UnmanagedType.I4)]
public int varId;//long
[MarshalAs (UnmanagedType.Struct)]
public SYSTEMTIME captureTime;
[MarshalAs (UnmanagedType.R8)]
public double captureValue;//double
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 50)]
public string captureUnits;
}
hth
bl********@walla.co.il wrote:
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.


Dec 5 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: murlbrown | last post by:
I am using a class library built by michael kennedy that creates a system wide hook on the WH_KEYBOARD_LL, but I wanted to changed it to become a hook for a RichEdit box in another application. ...
1
by: Raphael Iloh | last post by:
Hi all, I have a Web Setup Project and would like to change the installation path from the default (i.e. C:\Inetpub\wwwroot\) to some more particular path (e.g. c:\myfolder\). Any ideas on this...
4
by: Weinand Daniel | last post by:
i'd like to monitor changes of the "Control.Name" porperty during designtime. if the user changes the name in designer my event musst fire. i have created a own button control. with an event...
10
by: Steve | last post by:
Does any one know if python has the ability to run a shutdown hook. For example you set a method to run when the python process is shutting down, like it recieved a kill signal? Basically...
7
by: jpierson | last post by:
Hi, I am tryin to create a keyboard hook that sends the keystroke ctrl + pause/break. I haven't used keyboard hooks before so I'm not too sure how to use them public int MyKeyboardProc(int...
0
by: zeng.hui.stephen | last post by:
I download the demo http://msdn.microsoft.com/msdnmag/issues/02/10/cuttingedge/. I inherite the demo, and write my code. I want to use Hook to monitor C++ Edit change. I use a C# form...
4
by: gubbachchi | last post by:
Hi all, Please anybody help me solve this problem. I am stuck up with this from past 2 weeks. I am developing an application where, when the user selects date from javascript datepicker and enters...
22
by: schneider | last post by:
I need to hook the system mouse down event. I'm trying to replicate how a context menu hides when the mouse clicks outside of the control. Thanks, Schneider
6
by: Bart Kastermans | last post by:
I am playing with some trees. In one of the procedures I wrote for this I am trying to change self to a different tree. A tree here has four members (val/type/left/right). I found that self = SS...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.