Application Startup

To understand how a C++ application is started and executed, it is necessary to inspect different kinds of entry points. The first entry point that is executed is the PE entry point. This entry point is invoked by the operating system's loader for DLLs and EXE files. The OS loader finds the address of this entry point in the PE header of the EXE file. The PE entry point is a function with the following signature:

int _stdcall PEEntryPoint();

Depending on the kind of application, different functions are used. For a managed EXE file, the linker uses an entry point provided by the CLR. When the linker produces a native application, this entry point is provided by the CRT. Table 12-1 shows the different PE entry points that are chosen in different scenarios.

Table 12-1. PE Entry Points

Condition

Entry Point

Library Containing Entry Point

Only native inputs, main defined

mainCRTStartup

msvcrt[d].lib

Only native inputs, wmain defined

wmainCRTStartup

msvcrt[d].lib

Only native inputs, WinMain(,,,)defined

_WinMainCRTStartup

msvcrt[d].lib

Only native inputs, wWinMain(,,,)defined

_wWinMainCRTStartup

msvcrt[d].lib

Only native inputs, linker switch /ENTRY used

Native function specified via /ENTRY

At least one input compiled with /clr[:*]

CorExeMain

mscoree.lib (mscoree.dll)

As you can see in Table 12-1, a function named _CorExeMain is always used when there is at least one managed input to the linker. As discussed in Chapter 1, a .NET assembly is created in this case. _CorExeMain is implemented in mscoree.dll, a DLL that acts as the starting point for the CLR. Several other .NET languages, including C# and VB .NET, also use _CorExeMain as the entry point of a managed application. _CorExeMain performs several steps as follows:

• It prepares the EXE assembly to execute managed code. For /clr or /clr:pure assemblies, this implies the initialization of the CRT.

• It executes the assembly's entry point.

Was this article helpful?

0 0

Post a comment