
Application Entry Points | 91
Program
Structure
This is the Title of the Book, eMatter Edition
Copyright © 2006 O’Reilly & Associates, Inc. All rights reserved.
IL_0000: ldstr "This is a console application."
IL_0005: call void [mscorlib]System.Console::WriteLine(string)
IL_000a: ret
} // end of method StartsHere::Main
The Visual Basic compiler and the .NET Common Language Runtime, it would
seem, have transformed this simple code module into a self-executing class.
Using Main in Windows Forms Applications
All forms displayed in Windows Forms applications must be instantiated before
use. Visual Basic allows you to specify a Form as the startup object of an applica-
tion (instead of a standard Class- or Module-based Main routine), and you don’t
have to add the routine yourself. So is it really there? Yes, the framework adds a
shared Main routine to your class. What does it do? A quick look at the IL gives
the answer. (Lines in this presentation have been wrapped for readability.)
.method public hidebysig static void Main( ) cil managed
{
.entrypoint
.custom instance void
[mscorlib]System.STAThreadAttribute::.ctor( ) = ( 01 00 00 00 )
// Code size 16 (0x10)
.maxstack 8
IL_0000: call class WindowsApplication1.My.MyProject/
MyForms WindowsApplication1.My.MyProject::get_Forms( )
IL_0005: callvirt instance class WindowsApplication1.Form1
WindowsApplication1.My.MyProject/MyForms::get_Form1( )
IL_000a: ...