CRT Initialization in clr[pure Assemblies

The CRT has been extended so that it can also be used from managed code. This is essential for extending existing applications with managed code. For mixed-code as well as native applications, the CRT provides many more features and services than many programmers think of. Here are some of them as follows:

• The CRT implements the heap (malloc/free).

• The CRT implements the C++ free store (new/delete). This is usually done in terms of the heap.

• The CRT supports throwing and catching C++ exceptions.

• The CRT ensures initialization of global variables by calling the appropriate constructors when code is loaded.

• The CRT ensures uninitialization of global variables by calling the appropriate destructors when code is unloaded.

• The CRT implements the actual native entry point.

• For an EXE file, the entry point parses the command line and calls main passing the command-line arguments.

The CRT has been extended to support all these features in scenarios in which managed and unmanaged code is executed. In /clr[:pure] assemblies, the CRT is initialized differently than it is in native applications and DLLs. If you use ILDASM to inspect a typical Hello World application compiled with /clr, you will see that the assembly contains a lot of variables, types, and functions that do not come from your source file. Figure 12-1 shows an ILDASM window for a mixed-code assembly. All this extra stuff exists only to initialize and uninitialize the CRT and to perform managed startup.

f Hello World 3. e*c IL DASM

Fie View Help


* W <CppImplementationDetails> + • <0"tlmplementatbnDetails>

* »stri k E JEXCEPT ION.PO INTERS i Ef „enative_star(Lp3tate

* .igcroot<System::Striri3

? A0x490-109CM. ?J ock $ i n i ti al izer $ @ AtEx i B_ock(3 < CrtI mp le mentatit i- ?AOx49040904._exiUi5t_size : slatic assembly uint32 atDJDCOO! ?A0x4 9040904. _cnexitbegin : static assembly method void *()* t ?AQx49Q40904,_anexitend : static assembly method void *()* at ?A0x7d798523,[email protected][email protected]<Crtlmpl ?A0x7d79352 3. ?Inltla [email protected]@<C ^ [email protected])CurrentDon [email protected](Domain( & ? A0x7d798523. ? In i ti a [email protected](ai<( [email protected]@<( & ?A0x7d798523.?Uninitializediiriitializer$pCutTenitDomain(ai<Cri:Irr,

.assembly HelloWarld3

Figure 12-1. Managed startup logic

Was this article helpful?

0 0

Post a comment