views:

18

answers:

1

I am creating a program that interacts with another program and I would like to "inject" my program into this program as an MDI Child window. Is this even possible, and if so can it be done in VB.NET? What kind of pitfalls are associated with doing this?

A: 

It could be done, in two ways, the first way, by obtaining a copy of Detours, and use pinvoke to inject your process into that parent process with MDI controller, the second way, although more dangerous, is to hook into the MDI controller's window messages and inject code that will execute - the dangerous part is that, since MDI controller is running in a separate process, you may incur a "Access violation" when trying to access another process's memory, namely the MDI controller.

You can most certainly hook into that process and trap the messages, have a look at this sample found here (written in C#, but you can easily add a reference to your VB.NET project) and here also.

It depends on how far you want to go, you may have to allow your process to access the protected memory space by your MDI controller which is in the other process by elevating it... try those example hooks in the links provided and see how it goes...

tommieb75
Interesting. Thanks for the links; I'll definitely be looking into them!
Steven
Tommie, try to focus on what it takes to inject the CLR, and get it initialized properly, so it can run the managed code in the target process. A good follow-up question to the OP could be: "is it a managed process? What version of the CLR does it load?"
Hans Passant
@Hans: Good point actually despite mentioning VB.NET, and tagged as such.... am in absolute agreement...
tommieb75