Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / May 2004

Tip: Looking for answers? Try searching our database.

Debugging mixed DLL called from legacy code

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Max Christian - 05 May 2004 02:33 GMT
I'm writing a mixed-mode C++ DLL which is used by an old C++
application that I don't have the source code to.  I'm amazed by the
ease of interoperability, but the one problem I'm having is debugging
the DLL, as the C++ app crashes if loaded into the debugger.

If I could just get the line number on which an exception occurred
that would be enough to fix most bugs.  At the moment I use
exception.ToString() and get a stack trace but it's very hard to find
the bug in a large function without knowing which line.

Anyone have any tips, either on how to get the legacy app to run under
the debugger (so I can step through my DLL when called), or get the
line number an exception occurred on?

Many thanks indeed,

Max Christian
William DePalo [MVP VC++] - 05 May 2004 03:15 GMT
> I'm writing a mixed-mode C++ DLL which is used by an old C++
> application that I don't have the source code to.  I'm amazed by the
[quoted text clipped - 4 lines]
> the debugger (so I can step through my DLL when called), or get the
> line number an exception occurred on?

Well, if you can't run under the debugger can you put a DebugBreak() line at
some point when your DLL gets invoked and step through from there?

Still, I'm not sure I understand what crashes when. The crash occurs only
when you debug?

Did you

1) build the DLL with VS.Net?
2) specify the "legacy" executable in the "command"
   edit box on the Debugging properties page
3) launch the executable by starting the debugger

Is that the sequence that crashes? Does it crash immediately?

Regards,
Will
Max Christian - 05 May 2004 10:39 GMT
> Well, if you can't run under the debugger can you put a DebugBreak() line at
> some point when your DLL gets invoked and step through from there?

Unfortunately that causes the C++ app to crash immediately, which
surprised me as it's obviously my code that's running when
DebugBreak() is called.

> Still, I'm not sure I understand what crashes when. The crash occurs only
> when you debug?

Yes, only when debugging.  I do exactly the three things you've listed
below (using VS.NET 2003), I get a warning about no debug info in EXE,
I click OK to debug anyway, and then I get this msg box:

"The application failed to initalize properly (0xc0000142).  Click on
OK to terminate the application."

As I say, the app works fine when not under the debugger.

M

> Did you
>
> 1) build the DLL with VS.Net?
> 2) specify the "legacy" executable in the "command"
>     edit box on the Debugging properties page
> 3) launch the executable by starting the debugger

(Yes, I did all of those.)
Max Christian - 05 May 2004 10:56 GMT
> Did you
>
> 1) build the DLL with VS.Net?
> 2) specify the "legacy" executable in the "command"
>     edit box on the Debugging properties page
> 3) launch the executable by starting the debugger

I've found an answer to this -- I changed the Debugger Type from Auto
to Managed Only in Configuration Properties|Debugging and now it
works.  (It crashes as before under both the Mixed and Native Only
modes.)

I hope that's useful to a future googler...

M

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.