main function not found

W

wongjoekmeu

Hello All,
From a book where I have learned C++ it says that each application must
have at least one
function which is the main() function. Now I have the source code of a
C++ program from someone else. But whatever I am doing to search for
the main function, I can not find it. There is a very short description
of the program in a Readme file where it says that the main program is
located in a class "MytoolApp". I've had a look in this class which
seems to be derived from the "CWinApp" class. What is a "CWinApp" class
? I could not find any function called main() in this "MytoolApp"
class. Can anyone explain this to me ?
Many thanks in advance.
Robert
 
S

Shezan Baig

Hello All, must
have at least one
function which is the main() function. Now I have the source code of a
C++ program from someone else. But whatever I am doing to search for
the main function, I can not find it. There is a very short description
of the program in a Readme file where it says that the main program is
located in a class "MytoolApp". I've had a look in this class which
seems to be derived from the "CWinApp" class. What is a "CWinApp" class
? I could not find any function called main() in this "MytoolApp"
class. Can anyone explain this to me ?
Many thanks in advance.
Robert

This is an MFC application, there is no 'main'. There is
'InitInstance', but no 'main'. Try google for "cwinapp mfc" and you
should find some information.

Hope this helps,
-shez-
 
H

Hariprasad Govardhanam

Check out below.

Hello All, must
have at least one
function which is the main() function.
Correct.

Now I have the source code of a
C++ program from someone else. But whatever I am doing to search for
the main function, I can not find it. There is a very short description
of the program in a Readme file where it says that the main program is
located in a class "MytoolApp". I've had a look in this class which
seems to be derived from the "CWinApp" class. What is a "CWinApp" class
? I could not find any function called main() in this "MytoolApp"
class. Can anyone explain this to me ?

Inorder to implement complete OOPS in C++, we can declare and implement
a class, which when initialized as global object, calls the constructor
of that particular class. This does n't need a main function. This
method is utilized in MFC(Microsoft Foundation Classes). So,
constructor of MyToolApp is the start of the program. But, MFC class
CWinApp calls the InitInstance() method in that particular class, so
InitInstance is the main method of the program.
 
J

Jack Klein

Hello All,
have at least one
function which is the main() function. Now I have the source code of a
C++ program from someone else. But whatever I am doing to search for
the main function, I can not find it. There is a very short description
of the program in a Readme file where it says that the main program is
located in a class "MytoolApp". I've had a look in this class which
seems to be derived from the "CWinApp" class. What is a "CWinApp" class
? I could not find any function called main() in this "MytoolApp"
class. Can anyone explain this to me ?
Many thanks in advance.
Robert

The MFC (Microsoft Foundation Classes) which are by the way off-topic
here, bury the main() function internally.
 
A

Alf P. Steinbach

* (e-mail address removed):
have at least one function which is the main() function. Now I have the
source code of a C++ program from someone else. But whatever I am doing
to search for the main function, I can not find it. There is a very short
description of the program in a Readme file where it says that the main
program is located in a class "MytoolApp". I've had a look in this class
which seems to be derived from the "CWinApp" class. What is a "CWinApp" class
? I could not find any function called main() in this "MytoolApp" class.
Can anyone explain this to me ?

There are two ways a C++ program can apparently or actually be without a
'main' function, and both probably apply in your case.

First, that you're using an application framework that has a 'main'
function that in turn calls a function (e.g. a member function) in
your code. If you don't have the application framework source code
you'll not see 'main' anywhere. Even though it might be there.

Second, the standard differentiates between _hosted_ and _freestanding_
implementations of the language. Freestanding is meant for e.g. embedded
systems programming, where it's impractical to provide all the features
of the standard library, or even a 'main' function. For purposes of formalism
most Windows C++ implementations must be regarded as freestanding, because
they allow and to a certain practical extent require other startup functions
than 'main', e.g. 'wmain', 'WinMain' and 'wWinMain' (a Microsoft convention);
and these names might be hidden in macros, e.g. 'tmain' (a macro).

What you have seems to be an MFC Windows GUI application, as Jack Klein
pointed out, and if so then both apply: first, you're using an application
framework that provides the startup function, and second, the C++
implementation is a freestanding one where most probably the startup function
is not 'main' but (non-standard, implementation-defined) 'WinMain'.

Hope this helps,

- Alf
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,201
Messages
2,571,048
Members
47,651
Latest member
VeraPiw932

Latest Threads

Top