Link to home
Start Free TrialLog in
Avatar of pFaz69
pFaz69

asked on

CWinApp theApp; what's for?

i've frequently asked to myself why Visual C++ 6.0 Wizard for console applications includes always the statement:
//------------------------------------
// The one and only application object
CWinApp theApp;
//------------------------------------

It's to let to users the chance to call 'AfxGetApp()->.....', or there's a wiser reason?
Avatar of nil_dib
nil_dib

its the instance/object of your "main" application class (which is derived from CWinApp). no object, no running program.

nil_dib
Avatar of pFaz69

ASKER

My console program runs without problems without the code row above) if i don't use funcs like AfxGetApp()); so why Visual C++ Wizard includes always this row?
your console program has a main() function (!) which is called at the execution of the application.
The entry to your MFC application is the creation of an object from your "main" app class (runs as a thread(derived from CWinApp derived from CWinThread)).

nil_dib
A CWinApp is necessary because you're using MFC (or, at least, you've asked the console Wizard for MFC support).

It's there to maintain state information for the application and help MFC initialize.

If your application works fine without it, it's because you're not using MFC--or not using enough of MFC--to run into a problem.

..B ekiM
Avatar of pFaz69

ASKER

i'd like to know something more about that. My program is composed by a main() func (!) and five classes: three of them inherites from CWinThread and two from CAsyncSocket: it works pretty well without the 'CWinApp theApp' statement. So: i don't think i'm using little MFC. Maybe the job of 'CWinApp theApp' statement is performed by some other initializations; but witch is exactly this job?
ASKER CERTIFIED SOLUTION
Avatar of abk102299
abk102299

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 pFaz69

ASKER

thank you, abk for your research.