954,498 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Regarding crtStartup

Hello!

I have a sample application. I just put a breakpoint at the beginning of main(). The callstack pointed to a function called mainCRTStartup() and before that, the kernel32.dll was present(grayed out). Can anyone please tell me what these functions are, and who invokes them?

Thanks in advance!

myk45
Posting Whiz
319 posts since Sep 2010
Reputation Points: 57
Solved Threads: 40
 

The C++ runtime eventually has to call your main(), but there's stuff that needs to be done both before and after. Judging by the name, you're using a Microsoft compiler. If you have the CRT sources then look for crt0.c, it's a small source file that does the runtime initialization.

deceptikon
Indubitably
Administrator
632 posts since Jan 2012
Reputation Points: 119
Solved Threads: 105
 

So, if i get this correct, the kernel invokes the MSVCRT(i'm using a MS compiler) which in-turn invokes the main(). Am i correct?

myk45
Posting Whiz
319 posts since Sep 2010
Reputation Points: 57
Solved Threads: 40
 

It's probably safer to say that there's hidden initialization and termination code in your program's executable. While it's correct to say that main() is the starting point for a program, it's not necessarily the first starting point. When your executable is loaded into memory, the starting address is probably at mainCRTStartup() instead of main().

deceptikon
Indubitably
Administrator
632 posts since Jan 2012
Reputation Points: 119
Solved Threads: 105
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You