Start of Execution in a C++ Program

K

KevinSimonson

I'm still working on the Shareaza open source project, but in order to
understand how it works I think I need to find the <main()> function
where execution starts. Or at least I think I do. In C execution
always starts at the <main()> function. Isn't that true for C++ too?

I ask this because I can't find the <main()> function in the Shareaza
source code. I did a recursive search for that function and it didn't
turn up a <main()> function anywhere. Can somebody out there either
confirm that the open source is broken (since it doesn't have a
<main()> function), or point me to where execution does start in a C++
program?

I'd really appreciate any information anyone can give me.

Kevin S
 
J

Juha Nieminen

KevinSimonson said:
I'm still working on the Shareaza open source project, but in order to
understand how it works I think I need to find the <main()> function
where execution starts. Or at least I think I do. In C execution
always starts at the <main()> function. Isn't that true for C++ too?

I ask this because I can't find the <main()> function in the Shareaza
source code. I did a recursive search for that function and it didn't
turn up a <main()> function anywhere. Can somebody out there either
confirm that the open source is broken (since it doesn't have a
<main()> function), or point me to where execution does start in a C++
program?

I'd really appreciate any information anyone can give me.

Not to be overly cynic, but should you be touching an open source
project written in a programming language you have no idea whatsoever?
 
S

Stuart Golodetz

I'm still working on the Shareaza open source project, but in order to
understand how it works I think I need to find the<main()> function
where execution starts. Or at least I think I do. In C execution
always starts at the<main()> function. Isn't that true for C++ too?

I ask this because I can't find the<main()> function in the Shareaza
source code. I did a recursive search for that function and it didn't
turn up a<main()> function anywhere. Can somebody out there either
confirm that the open source is broken (since it doesn't have a
<main()> function), or point me to where execution does start in a C++
program?

I'd really appreciate any information anyone can give me.

Kevin S

If the Shareaza project produces a .dll (just guessing from what you've
been saying elsewhere), it won't have a main function (although it might
have a DllMain function -- my advice is not to worry about that right
now, but see here if you're interested:
http://msdn.microsoft.com/en-us/library/ms682583(VS.85).aspx).

The point being that (as mentioned in my reply to your previous post) a
..dll is a *library* -- you can't run it directly. It just contains
things you can use elsewhere (an executable is the thing that contains a
main function and which you run).

Cheers,
Stu
 
S

Stuart Golodetz

If the Shareaza project produces a .dll (just guessing from what you've
been saying elsewhere), it won't have a main function (although it might
have a DllMain function -- my advice is not to worry about that right
now, but see here if you're interested:
http://msdn.microsoft.com/en-us/library/ms682583(VS.85).aspx).

The point being that (as mentioned in my reply to your previous post) a
..dll is a *library* -- you can't run it directly. It just contains
things you can use elsewhere (an executable is the thing that contains a
main function and which you run).

Cheers,
Stu

Actually, ignore that -- if Shareaza is a GUI app then what Sherm's
saying is more to the point.

Stu
 
K

KevinSimonson

  Not to be overly cynic, but should you be touching an open source
project written in a programming language you have no idea whatsoever?

My job requires me to touch this open source project, and I really
need this job right now, so I don't have much of a choice. And I have
studied C++ before, and programmed in it a little, so it's not
_precisely_ true that I "have no idea whatsoever"; it's just been a
while since I was actively involved with C++.

Kevin S
 
B

BGB / cr88192

Christian Hackl said:
KevinSimonson ha scritto:


It could be hidden inside of a macro.


Step into the code with a debugger and you will inevitably find yourself
in the main function.

except in a Windows GUI app, one may well find themselves in "WinMain()",
which is typically where execution starts in C and C++ in Windows GUI apps
(as opposed to the conventional "main()", which is more used for console
apps, or for most non-Windows OS's).

usually when compiling an app, which is used will determine which sort of
app is intended:
"main()" => "use or summon up a console window to handle stdin/stdout";
"WinMain()" => "don't bother with console, and stdin/stdout/... are no-op".

also the functions look very different, since "main()" will typically give a
pre-parsed command-line (usual "int main(int argc, char *argv[])" setup),
whereas "WinMain()" will give several special handles (needed to do pretty
much anything involving the GUI facilities, like say, creating a window or
adding widgets), as well as forcing one to parse out their own command-line
(it is passed as a single "LPSTR" string).

hence, something like:
"int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR
lpCmdLine, int nCmdShow)".


or such...
 
G

Geoff

I'm still working on the Shareaza open source project, but in order to
understand how it works I think I need to find the <main()> function
where execution starts. Or at least I think I do. In C execution
always starts at the <main()> function. Isn't that true for C++ too?

I ask this because I can't find the <main()> function in the Shareaza
source code. I did a recursive search for that function and it didn't
turn up a <main()> function anywhere. Can somebody out there either
confirm that the open source is broken (since it doesn't have a
<main()> function), or point me to where execution does start in a C++
program?

I'd really appreciate any information anyone can give me.

Kevin S

CMainWnd
 
G

Geoff

I'm still working on the Shareaza open source project, but in order to
understand how it works I think I need to find the <main()> function
where execution starts. Or at least I think I do. In C execution
always starts at the <main()> function. Isn't that true for C++ too?

I ask this because I can't find the <main()> function in the Shareaza
source code. I did a recursive search for that function and it didn't
turn up a <main()> function anywhere. Can somebody out there either
confirm that the open source is broken (since it doesn't have a
<main()> function), or point me to where execution does start in a C++
program?

I'd really appreciate any information anyone can give me.

Kevin S

Shareaza is a complex Windows program. It has some 30 projects in the
solution and incorporates Boost libraries. I can see why you might
have a hard time finding the starting point.

The main function changes names in Windows programs depending on the
nature of the project (Console, Win32, MFC, .NET) and the mode of the
compiler (C vs C++).

In Shareaza's case the main function is CMainWnd::CMainWnd() in
WndMain.cpp in the Shareaza project.
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top