473,692 Members | 2,529 Online
Bytes | Software Development & Data Engineering Community
+ 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.CWPSTRUC T)Marshal.PtrTo Structure(lPara mA,
typeof(Win32.CW PSTRUCT));

then in case of WM_MOVING:
Win32.RECT rect = (Win32.CWPSTRUC T)Marshal.PtrTo Structure(cwp.l Param,
typeof(Win32.RE CT));
}

Now, the values in rect are ok.
I change them and the copy back:

// copy rect
Marshal.Structu reToPtr(rect, cwp.lParam, true);
// copy CWPSTRUCT
Marshal.Structu reToPtr(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 7675
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.Seq uential, 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(Unman agedType.ByValT Str, SizeConst = 50)]
public string captureUnits;
}
hth
bl********@wall a.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.CWPSTRUC T)Marshal.PtrTo Structure(lPara mA,
typeof(Win32.CW PSTRUCT));

then in case of WM_MOVING:
Win32.RECT rect = (Win32.CWPSTRUC T)Marshal.PtrTo Structure(cwp.l Param,
typeof(Win32.RE CT));
}

Now, the values in rect are ok.
I change them and the copy back:

// copy rect
Marshal.Structu reToPtr(rect, cwp.lParam, true);
// copy CWPSTRUCT
Marshal.Structu reToPtr(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
4750
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. I modified the class keeping a majority of his code, and built a c#(.net) front end to use this c++ built core library, passing it the hook type of EM_SETTEXTEX (WM_USER + 97) and the threadID of the richedit box, his class comes up telling me...
1
2641
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 will be appreciated. Regards, Raphael
4
2987
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 NameChange. during runtime it works fine. if the name of the control has changed the event is fireing. (for example: designtime name of the button is btnOk, on a second button
10
10591
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 looking for an effect like the following java code. Runtime.getRuntime().addShutdownHook(new Thread(this));
7
26537
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 nCode, int wParam, int lParam) {
0
2489
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 containing a Edit(textbox) and button to test at first. When I change text in Edit or press button to setText value, I want to monitor the change event. But the event code always return 0, why?
4
3340
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 the comments and clicks the save button then the date and the date will be stored in the mysql database. This is working fine. But my problem is when, after the user had made an entry the date in the calendar for which an entry has made should be...
22
6415
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
1808
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 does not work; I have to write self.val = SS.val and the same for the other members (as shown below). Is there a better way to do this? In the below self is part of a parse tree, F is the parse tree of a function f with argument x. If a node...
0
8611
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8547
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9090
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8812
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7639
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5822
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2984
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 we have to send another system
2
2242
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1962
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.