C++ gurus in the house?
Author
Discussion

shouldbworking

Original Poster:

4,801 posts

243 months

Wednesday 13th June 2007
quotequote all
Present task is to rewrite an old c++ app that is complete ass. As part of this im trying to get the old app up and running on my machine, however im having a nightmare doing this.

I got hold of the source files and visual studio 2005 files and got that loaded up and happy and after some routine messing about (correcting incorrect paths to referenced dlls etc) it compiles; however, when you hit run it starts and stops immediately. trying to step into it has the same result - never hits a line of code.

Not sure how these apps are supposed to look (c++ is not a language ive worked with before), but the code files dont appear to be linked to forms ie no design view options. there are 2 resource files where the dialogs section contains forms.

odd one. any thoughts as to how to begin approaching it?

Don

28,378 posts

315 months

Wednesday 13th June 2007
quotequote all
So what library are you using? MFC?

You will need to set the compilation type to "Debug" else no debug information gets written into the executable. The compile it. Then put a breakpoint on the first line after the entry point and step into it. Might help.

Why are you re-writing it? Maintenance reasons? Why not just port it to the latest compiler, recompile and away you go - a lot less work.

Don

28,378 posts

315 months

Wednesday 13th June 2007
quotequote all
How MFC works is that for each dialog you create a class derived from CDialog. Embedded in the class definition is an identifier that points to the dialog entry in the Resource file. So if you find files like CMyDialog.cpp and CMyDialog.h they'll be the code you need.

shouldbworking

Original Poster:

4,801 posts

243 months

Wednesday 13th June 2007
quotequote all
Don said:
So what library are you using? MFC?

You will need to set the compilation type to "Debug" else no debug information gets written into the executable. The compile it. Then put a breakpoint on the first line after the entry point and step into it. Might help.

Why are you re-writing it? Maintenance reasons? Why not just port it to the latest compiler, recompile and away you go - a lot less work.
Yep - MFC, and yep its in debug mode. I couldnt find where you set the entry point for the application so I just did step into new instance but that had the same result. I set break on any exceptions and that didnt work.

Im rewriting it because basically its a big pile of pap. Its an app my work bought after a number of reports were written recommending not to buy it. The code is written so poorly a task that ought to take maybe 2-3 hours to complete takes over 24 hours, and its my job to fix it... of course that would be easier if the source code the seller provided actually compiled or worked in the first place! nightmare project - the bad app looks to have been redeveloped from another one itself.

Don

28,378 posts

315 months

Wednesday 13th June 2007
quotequote all
Ahah - its an MFC app. Okey dokey. Do ANY MFC apps run on your machine.

You could create a Hello, World app and test that. The other thing you can do is specify oin the compiler directives if MFC is to be used in a DLL or compiled in. Specify that it should be compiled in and try again.

Sorry - I'm away from the machine with my IDE on it and I can't remember what the specific menus are...

Chances are the executable isn't even loading right...and it will be to do with the infrastructure on your box...maybe...

dilbert

7,741 posts

262 months

Wednesday 13th June 2007
quotequote all
shouldbworking said:
Don said:
So what library are you using? MFC?

You will need to set the compilation type to "Debug" else no debug information gets written into the executable. The compile it. Then put a breakpoint on the first line after the entry point and step into it. Might help.

Why are you re-writing it? Maintenance reasons? Why not just port it to the latest compiler, recompile and away you go - a lot less work.
Yep - MFC, and yep its in debug mode. I couldnt find where you set the entry point for the application so I just did step into new instance but that had the same result. I set break on any exceptions and that didnt work.

Im rewriting it because basically its a big pile of pap. Its an app my work bought after a number of reports were written recommending not to buy it. The code is written so poorly a task that ought to take maybe 2-3 hours to complete takes over 24 hours, and its my job to fix it... of course that would be easier if the source code the seller provided actually compiled or worked in the first place! nightmare project - the bad app looks to have been redeveloped from another one itself.
Loads of stuff happens prior to "main". Checkout that you have specified the appropriate "subsystem" to the linker. Options are "CONSOLE|WINDOWS|NATIVE|WINDOWSCE|POSIX"

Also all of your global classes would be initialised before main so you may have a runtime bug in a constructor for a class instanced globally.

If you're using the c runtime, it should be initialised before "main" is called. If you have the source for "init", you should be able to step through that too.



JonRB

80,226 posts

303 months

Wednesday 13th June 2007
quotequote all
Also bear in mind that if it was written a while back it may only compile without tweakery with VC6.

VC7 (2003) and VC8 (2005) are a lot more strict and standards-compliant.

Edited by JonRB on Wednesday 13th June 17:28

JonRB

80,226 posts

303 months

Wednesday 13th June 2007
quotequote all
BTW, if you want to start debugging an MFC app then look for the one-and-only class in the project that derives from CWinApp and start debugging in the InitInstance() method

Note: you may want to check the return value of InitInstance - if it returns FALSE then the message pump is not started and the application will exit.

Edited by JonRB on Wednesday 13th June 17:24

Don

28,378 posts

315 months

Wednesday 13th June 2007
quotequote all
JonRB said:
Also bear in mind that if it was written a while back it may only compile without tweakery with VC6.

VC7 (2003) and VC8 (2005) are a lot more strict and standards-compliant.

Edited by JonRB on Wednesday 13th June 17:28
Hello, Jon. Thought I might find you in here eventually! hehe

I reckon it could be worth installing an old VC6 somewhere and seeing if that will compile/run it up...

JonRB

80,226 posts

303 months

Wednesday 13th June 2007
quotequote all
Don said:
I reckon it could be worth installing an old VC6 somewhere and seeing if that will compile/run it up...
Indeed - always worth a shot with older apps.

I find that you have to make a conscious effort to migrate from VC6 to newer VC compilers, so as such you should spare yourself that and eliminate it from the list of reasons for failure by initially using VC6. When it's working, then migrate / port.

JonRB

80,226 posts

303 months

Thursday 14th June 2007
quotequote all
Ironically it looks like "shouldbworking" is working as they haven't reported back yet. biggrin

shouldbworking

Original Poster:

4,801 posts

243 months

Saturday 16th June 2007
quotequote all
JonRB said:
Ironically it looks like "shouldbworking" is working as they haven't reported back yet. biggrin
Not a chance :P i was out at hyde park festival thursday and recovering yesterday - just having another look at whats been posted.

The writer of the app presently uses VS 2005 to develop it so I am assuming this means it behaves with any compliance issues and should work with whatever compiler is shipped as part of the visual c++ aspect of vs2005.

Looking at the linker options, this is set to WINDOWS, which as this is a windows app I hope is correct smile

Thanks for the tip on the class deriving from CWinApp, found that now. Putting a breakpoint doesnt change anything - not hitting that.

Sounds to me like the probable explanation so far is the infrastructure on my machine - I will make a hello world and give that a shot. The project properties should in theory be a-ok as ive adapted my project files from the ones the original author is presently using to successfully compile and run the app, just changing paths where appropriate.

I'll be back.. maybe not till monday though smile weekend time

shouldbworking

Original Poster:

4,801 posts

243 months

Saturday 16th June 2007
quotequote all
Hm. a hello world mfc add does work. dagnabbit.