Link to home
Start Free TrialLog in
Avatar of 10Pints
10Pints

asked on

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!
Avatar of DanRollins
DanRollins
Flag of United States of America image

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.
Avatar of 10Pints
10Pints

ASKER

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!

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.
Avatar of 10Pints

ASKER

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?


Avatar of 10Pints

ASKER

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
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...
Avatar of 10Pints

ASKER

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

ASKER CERTIFIED SOLUTION
Avatar of DanRollins
DanRollins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 10Pints

ASKER

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.
Avatar of 10Pints

ASKER

Thanks Dan, very professional and polite!
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.
Avatar of 10Pints

ASKER

True, very true, ah the life we lead ...