• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 337
  • Last Modified:

Debugging hooked App

Hi folks, can someone remind me: I have a C++ app that has an exe (Monitor App: debug) and a dll (Hook DLL)

I want to inject the Dll into another (target app: release) using SetWindowsHookEx - which I know the method for and have working - in an old version, now I need to upgrade the monitor.

So I would like to debug the dll in the context of the target not the monitor.
I have both VC6 and VS2008.
I can inject it, but can't debug it - I am sure it can be done - any ideas folks?

Thanks!
0
10Pints
Asked:
10Pints
  • 7
  • 5
1 Solution
 
DanRollinsCommented:
Use VS menu:
    Debug / Attach to Process...
You can also insert a
   DebugBreak Function
   http://msdn.microsoft.com/en-us/library/ms679297(VS.85).aspx
into your hook code.  But it's very messy because global hook code ends up in all programs.
0
 
10PintsAuthor Commented:
I tried the attach to process, but did not get anywhere ... but ahh, if I call debug break in h the ook code ... mmm
Right I am using WH_CALLWND hook which needs to b ethread specific, so no worries there then.
So I use the DebugBreak which will throw the Break, dialog: then I hit the debug button and a sepsarate instance of VS2008 will be launched?

Sorry it is late Xmas day will check out when the festivitities have abated.

Thanks for yur help, let me get into this when we are both sober, may need your help on getting going here!

0
 
DanRollinsCommented:
Yes.  A Just-in-time debugger prompt pops up.   Select "debug in a new instance of VS 2008"
Of course, unless the app into which you are injecting is one that you wrote and complied for debug build, there's not much you can do about it.  But (assuming the hook is a debug build) you can single-step and otherwise debug your hook dll code.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
10PintsAuthor Commented:
Mornin!

mmm I seem to get on much better with VC6: Using the old gal all I seem to have to do is build a debug dll
Set the dll debug exe to my target dll eomui.exe (release)
set the working directory to where the dll pdb is
Put a F9  break in the Dll hook code
Run the injector app separately
Inject the DLL
Bingo the VC6 debugger picksup on the break.

When i try similar with ( a similar app) in VS2008 the debug break points go disabled.
I will persverewith the DebugBreak() call in VS 2008 - or maybe I should swing the new app back into VC6

there are differences between the 2 apps (VS2008 and the VC6 one). I would just like to get a break with VS2008 then I can what is ging on

What am I doing wrong?


0
 
10PintsAuthor Commented:
I have migrated most of my VS2008 code to the VC6 Project and I can break in in easily as above, but still no joy with VS2008
0
 
DanRollinsCommented:
I haven't tried your scenario... I avoid programming Windiowss Hooks.  
Did you take a look at all of the VS2008 settings under Tools/Options/Debugging?  A couple of them look promising...
0
 
10PintsAuthor Commented:
Hi Dan
Many thanks, I hadgotten the VC6 app going and i have forgotten how much quicker one goes around the debug/code/debug loop with VC6 - its fantastic!

I have got to the stage where the hook works: I can subclass a Winforms tree control and populate a Property Cotrol accordingly. I think my effort will be better aimed at trying to get a service up and running to populate the hook --- or soemthing like it - rather than a cumbersome MFC dialog app and a batch script to fire both exes!

If you have any advice on that I would love to hear. I promised this piece of code as a freebie to a client and now am beginning to wish that idea further - got behind, so coding over Xmas I am afraid!

Would a service be best? or is there another mechanism?

Thanks!

T

0
 
DanRollinsCommented:
I'd personally avoid a system Service -- mainly because I hate having a lot of Services running on my own box.  There might be no need for a separate batch file, etc.  Just have your dialog-based app launch the target program (if it is not already running).
0
 
10PintsAuthor Commented:
Thanks Dan, yes that would be the easiest way, and I agree that too many services are a pain.
What I could do then is to launch the monitor app as a window based app, but hide it on launch so that it still has a window and therfore I can use it and WM_TIMER messages to make sure the app is rehooked when it reappears, or something 'nasty' happens.
The injected DLL can handle everything else bar the closeure of the app and subsequent relaunch.
VC6 was far superior to VS2008 when it came to debugging on the fly, and I certainly needed lots of that!

Thanks again, please accept thepoints.
0
 
10PintsAuthor Commented:
Thanks Dan, very professional and polite!
0
 
DanRollinsCommented:
I had to use VS6 this week, and yes... it was like "going home."  My fingers did the right things automatically.  However, I really miss the cool stuff from the later versions -- hover the mouse over an object variable and immediately see its value and be able to drill-down into its members -- without using a diffferent window.
0
 
10PintsAuthor Commented:
True, very true, ah the life we lead ...
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 7
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now