Subclassing foreign window and changing memory in it 
Author Message
 Subclassing foreign window and changing memory in it

Can anybody tell me how to subclass a window from another process, i.e.
how to receive its messages?
SpyWorks (for VB) can do this, how to they do that?

And I have another problem: One of the messages I receive from the window
is a pointer to a structure which is (of course) in the memory space of
the other application. How can i change this structure before the message
is processed by the standard window message function.

Jan



Fri, 26 Jul 2002 03:00:00 GMT  
 Subclassing foreign window and changing memory in it
Jan,

Quote:
> Can anybody tell me how to subclass a window from another process, i.e.
> how to receive its messages?
> SpyWorks (for VB) can do this, how to they do that?

The easiest way is not to subclass the window at all, but to insert a
WH_GETMESSAGE hook into the window's owner thread. Look up
SetWindowsHookEx() for details.

Quote:

> And I have another problem: One of the messages I receive from the window
> is a pointer to a structure which is (of course) in the memory space of
> the other application. How can i change this structure before the message
> is processed by the standard window message function.

You are using the wrong approach here. It would be easier to use a real IPC
method, say a memory mapped file would work. Also, you might want to use
WM_COPYDATA instead, which will give you a real copy of the memory to work
with, and then you can send it back with another WM_COPYDATA message.

--
Tomas Restrepo
http://members.xoom.com/trestrep/



Fri, 26 Jul 2002 03:00:00 GMT  
 Subclassing foreign window and changing memory in it

Quote:
> The easiest way is not to subclass the window at all, but to insert a
> WH_GETMESSAGE hook into the window's owner thread. Look up
> SetWindowsHookEx() for details.

OK, I will try that!

Quote:
> You are using the wrong approach here. It would be easier to use a real IPC
> method, say a memory mapped file would work. Also, you might want to use
> WM_COPYDATA instead, which will give you a real copy of the memory to work
> with, and then you can send it back with another WM_COPYDATA message.

No, you misunderstood my problem.
The other application is not mine? It's not my code and not my compiled
EXE file. I really need to influence a 'foreign' application!

Jan



Sat, 27 Jul 2002 03:00:00 GMT  
 Subclassing foreign window and changing memory in it
Jan,

Quote:
> No, you misunderstood my problem.
> The other application is not mine? It's not my code and not my compiled
> EXE file. I really need to influence a 'foreign' application!

The your only options are to either hook into the app, where your own code
can execute localy and access the memory directly, or use
ReadProcessMemory()/WriteProcessMemory().

However, I'd urge you to try to avoid this, since there's no way you can
synchronize access to that memory between threads in both processes, and you
might easily cause the app to read an invalid value from the memory, or
simply crash allright.

--
Tomas Restrepo
http://members.xoom.com/trestrep/



Sat, 27 Jul 2002 03:00:00 GMT  
 Subclassing foreign window and changing memory in it

Quote:

> Jan,
> > No, you misunderstood my problem.
> > The other application is not mine? It's not my code and not my compiled
> > EXE file. I really need to influence a 'foreign' application!
> The your only options are to either hook into the app, where your own code
> can execute localy and access the memory directly, or use
> ReadProcessMemory()/WriteProcessMemory().

How can i 'hook into an app'? Can i use normal hooks there?

And do you have an example for ReadProcessMemory? Does it work with all
pointer of other apps??

Quote:
> However, I'd urge you to try to avoid this, since there's no way you can
> synchronize access to that memory between threads in both processes, and you
> might easily cause the app to read an invalid value from the memory, or
> simply crash allright.

I am consciously that i will probably have lots of problems but i have to
do it!

Jan



Sat, 27 Jul 2002 03:00:00 GMT  
 Subclassing foreign window and changing memory in it
Jan,

Quote:
> How can i 'hook into an app'? Can i use normal hooks there?

Sure. In fact, that's the easiest way, although there are others. Jeffrey
Richter's "Advanced Windows" book covers some others.

Quote:

> And do you have an example for ReadProcessMemory? Does it work with all
> pointer of other apps??

It's straightforward to use. However, ReadProcessMemory() has no knowledge
of structure or anything, it simply reads an area of contigous bytes of a
certain length, or your choosing.

--
Tomas Restrepo
http://members.xoom.com/trestrep/



Sat, 27 Jul 2002 03:00:00 GMT  
 Subclassing foreign window and changing memory in it

Quote:

> > How can i 'hook into an app'? Can i use normal hooks there?

> Sure. In fact, that's the easiest way, although there are others. Jeffrey
> Richter's "Advanced Windows" book covers some others.

But, how can i get access to the app's memory space?? I thought a hook
just catches the window messages?!

Quote:
> > And do you have an example for ReadProcessMemory? Does it work with all
> > pointer of other apps??

> It's straightforward to use. However, ReadProcessMemory() has no knowledge
> of structure or anything, it simply reads an area of contigous bytes of a
> certain length, or your choosing.

But I believe these functions only work with apps that are supposed to
use them or to be accessed by these functions, right??

Jan



Sun, 28 Jul 2002 03:00:00 GMT  
 Subclassing foreign window and changing memory in it
Jan,

Quote:
> But, how can i get access to the app's memory space??

They can because a hook has to run on the same process context as the window
it has hooked, that's why they are called hooks in the first place. It's
alseo teh reason why the hook function has to be on a dll.

Quote:
> But I believe these functions only work with apps that are supposed to
> use them or to be accessed by these functions, right??Jan

The functions will work for any app that has enough rights to open the
target process using OpenProcess() with PROCESS_VM_READ/PROCESS_VM_WRITE
access. There's no other requirement.

--
Tomas Restrepo
http://members.xoom.com/trestrep/



Sun, 28 Jul 2002 03:00:00 GMT  
 Subclassing foreign window and changing memory in it
OK, thank you very much for your help!

Jan



Mon, 29 Jul 2002 03:00:00 GMT  
 Subclassing foreign window and changing memory in it
Oh, i have one question left. What's the best way to hook into an
application? SetWindowsHookEx? Are there other ways?

Jan



Mon, 29 Jul 2002 03:00:00 GMT  
 Subclassing foreign window and changing memory in it
Jan,

Quote:
> Oh, i have one question left. What's the best way to hook into an
> application? SetWindowsHookEx?

Depends on what you want to do... SWHE() is useful if you need to do things
having to do with keeping track of windows, hooking messages, etc, but are
not so good when you simply need to execute some small code in another
process' context. Also, SWHE() won't work for, say, console applications,
since you can't hook the console.

Another way is, on NT, to use Read/WriteProcessMemory(), and
CreateRemoteThread(), or use one registry key that's available that can get
your dll loaded by any process that loads user32.dll... there are others,
too.

--
Tomas Restrepo
http://members.xoom.com/trestrep/



Mon, 29 Jul 2002 03:00:00 GMT  
 Subclassing foreign window and changing memory in it


Quote:
> Jan,
> > Can anybody tell me how to subclass a window from another process,
i.e.
> > how to receive its messages?
> > SpyWorks (for VB) can do this, how to they do that?

> The easiest way is not to subclass the window at all, but to insert a
> WH_GETMESSAGE hook into the window's owner thread. Look up
> SetWindowsHookEx() for details.

Is this necessary even for subclassing windows' controls? I have been
trying to do it with the usual subclassing/superclassing and it looks
like I am missing some messages (e.g. when the user adds/changes the
contents of an edit control it looks like windows is not reflecting
this internally).

Thanks for any help you can give me, Hernan.

Sent via Deja.com http://www.deja.com/
Before you buy.



Fri, 23 Aug 2002 03:00:00 GMT  
 
 [ 12 post ] 

 Relevant Pages 

1. Change a foreign language string to upper case

2. Getting HICON for foreign window?

3. Writing to foreign windows...

4. OnClose of foreign window

5. Bitmap Color Change when I changed from Windows 98 to Windows 2000

6. to Scott McPhillips(changing a view window of a frame window to another view window)

7. Subclassing window

8. Subclassing a window in different process

9. Subclassing window

10. Subclassing Problem with Unicode Windows

11. Q: subclassing problem, with hook and windows messages

12. Problems subclassing a window

 

 
Powered by phpBB® Forum Software