Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Debugging DLLs... 1

Status
Not open for further replies.

Milby7

Programmer
Dec 5, 2003
67
GB
Hi,

Does anyone know if it's possible to debug a c/c++ function library in a similar way to how you debug com libraries in vb6?? i.e. leave your dll in 'debug mode' in the IDE and step through the code when any calls are made to it from (already built) exe's.

I've been trying it by entering the executable in the projects debug details and running it, but it just loads, & immediately unloads the exe because the dll isn't loaded (or called) straight away!!

Thanks!
 
you should specify an executable what uses your dll.

Ion Filipski
1c.bmp
 
I have specified the exe that uses it, BUT because the dll/project isn't loaded immediately the exe loads & unloads straight away, so in other words the project comes out of debug mode before the exe gets the chance to call it.

Is there a way round this???
 
>but it just loads, & immediately unloads the exe because the dll isn't loaded (or called) straight away!!

Shouldn't matter. As long as the exe is running the debugging should be attached to it, regardless of something's been called or not. Are you sure the exe loads the dll at all? Is the still exe running after "immediately unloads". The debugging will of course end if the exe exits.

/Per

"It was a work of art, flawless, sublime. A triumph equaled only by its monumental failure."
 
there's only one exported function in the dll i'm trying to debug & i've stuck a break point in there, & stuck one in dllmain... doesn't work!! as i said above i don't even get the chance to enter the code because the exe loads & immediately unloads!!

can you get around it by specifying an already running process as the dll client??

The dll is crashing & i'm pretty sure it's because it's reading a dodgy pointer, so i need to step through to the point of the crash to see what's going on.

thanks!!
 
(optional) I have the exe sitting in a state where the next user action will cause the dll to be loaded & used.

I then run the vc++ project which starts up a new instance of the exe, but doesn't hang around for any functions in the dll to be called & unloads the instance of the exe & the vc++ project.

(the same thing always happens, whether i've got previous instances of the exe running or not)

I'm positive the dll is loaded by the exe, but i know it's only loaded on demand.

is there a way around this without sticking message boxes everywhere??

thanks!!

 
breakpoints, put breakpoints apd press f5. If a breakpoint is be reached the application will stop.

Ion Filipski
1c.bmp
 
as i said above, i've stuck breakpoints in both the dll's exported function & it's dllmain. doesn't do anything. i think i may just have to go with messageboxes. :-(
 
quite no differences. I think if the dll is not loaded explicitly with function LoadLibrary inside the .exe than DllMain will not be called.(once again, is my opinion, I did not tested that)

Ion Filipski
1c.bmp
 
>is there a way around this without sticking message boxes everywhere??

Logging to a file? :)

> it's only loaded on demand
+
>unloads the instance of the exe & the vc++ project
= Sounds like the exe quits before your dll is loaded.

>I'm positive the dll is loaded by the exe
Really?
You sure its the DLL you're currently trying to debug and not any old, erroneous, one?
What logic tells the exe to load the dll?
If it uses the environment's PATH then I doubt it loads the dll you are actually trying to debug(I guess that one lies in the /Debug directory of your VC++ project).
Do you have multiple copies if the dll in your machine?



/Per

"It was a work of art, flawless, sublime. A triumph equaled only by its monumental failure."
 
DllMain will be called no matter how the dll is loaded

/Per

"It was a work of art, flawless, sublime. A triumph equaled only by its monumental failure."
 
there's only one copy of the dll built, & i'm pretty sure that it would be loaded explicitly with LoadLibrary because it's path is specified in an ini file for the client exe to load. (unfortunately i don't have the source for the exe) whenever i try to run the project in debug i make sure the dll is renamed so that it won't be loaded instead of my project.

i'm probably gonna have to write to a file as you suggested above.

thanks!!
 
>i make sure the dll is renamed so that it won't be loaded instead of my project

Ie in the INI file you specify that the dll is the one in your .../Debug directory? That IS the dll you want to load.

/Per

"It was a work of art, flawless, sublime. A triumph equaled only by its monumental failure."
 
so i want to make sure the exe eventually loads the debug build of my dll. then do i still run my project (with the breakpoints etc) and wait for the exe to latch on to it??

does the exe run the debug dll or the project?? or both!?!?!?

thanks!!
 
>then do i still run my project (with the breakpoints etc) and wait for the exe to latch on to it??

Bingo!

When you start debugging you may get a "invalid breakpoints, execution will start from the beginning" (or similar) message. Thats because the exe hasn't loaded the dll yet. When it is loaded you can safely set the breakpoints - hmmm...I wonder if thats been your problem from the start? Is there a certain point where you know the dll is loaded and where you can control the exe to perform some action on the dll? This implies that setting BPs in dllmain can be a bit tricky

>does the exe run the debug dll or the project?? or both!?!?!?

The exe loads the dll. I don't know what you mean by loading a project - obviously the exe knows nothing about your project.

/Per

"It was a work of art, flawless, sublime. A triumph equaled only by its monumental failure."
 
ok, this is what i do:

1. build my 'debug' dll & copy it to where it will be loaded by the exe.

2. 'Run' (F5) my project. (the project then loads the exe, which loads it's dlls)

3. hopefully you now have your ide sitting in debug mode ready to pickup calls to your debug dll!?!?

i still don't seem to be getting to stage 3!! my project unloads straight away with a list of dlls that the exe has loaded (which doesn't include mine), in the output window & the following string @ the end:

The program '[584] uniface.exe: Native' has exited with code -1 (0xffffffff).

i'm assuming that my problem is that the exe is loading but is actually having problems & unloading returning an error code!?!? so am gonna have real problems trying to debug it!!

Thanks for all your help with this one!!

 
no, don't copy to location where it will be loaded by the exe :). Your server must start in your case the dll just built in your project at location where C++ have build it:) So, remove any other dll what exe could load but are not in the place where C++ put it.

Ion Filipski
1c.bmp
 
>which doesn't include mine

That's a clue, isn't it?

/Per

"It was a work of art, flawless, sublime. A triumph equaled only by its monumental failure."
 
>my project unloads straight away

I.e. the exe exits straight away. Seems like the exe doesn't feel too well about somehitng.

/Per

"It was a work of art, flawless, sublime. A triumph equaled only by its monumental failure."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top