First we will write client and from client send string to ArgIn.dll which will show our string in message box. Copy following, paste it in notepad and save as client.il
.assembly extern mscorlib{} .assembly extern ArgIn{} .assembly go{} .method public static void GO2() cil managed //any name starting with letter is ok { .entrypoint //must .maxstack 1 //you can safely comment out .maxstack 1 or set it on 2 but if
//it is insufficient results in run-time error .locals ([0] class [ArgIn]ArgIn.Class1 q) //.locals [init] ( <localsSignature> )
// Defines a set of local variables for this method. ldstr "Hello from client" //72 <T> ldstr string push a string object for the literal string newobj instance void [ArgIn]ArgIn.Class1::.ctor(string) //73 <T> newobj ctor allocate an uninitialized object and call ctor stloc.0 //0A stloc.0 Pop value from stack into local variable 0.
//pop will also do here (we won't use it again) ret //return is a must }
Do not compile yet, first we must compile library. Following is what we are going to compile to ArgIn.dll :
.assembly extern mscorlib {} .assembly extern System.Windows.Forms { .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) .ver 1:0:2411:0 } .assembly ArgIn {} .namespace ArgIn { .class public auto ansi beforefieldinit Class1 extends [mscorlib]System.Object { .method public hidebysig specialname rtspecialname instance void .ctor(string msg) cil managed { //.maxstack 8 ldarg.0 call instance void [mscorlib]System.Object::.ctor() ldarg.1 ldstr "From dll" call valuetype [System.Windows.Forms]System.Windows.Forms.DialogResult
[System.Windows.Forms]System.Windows.Forms.MessageBox::Show(string,string) pop ret } } }
Save this as ArgIn.il. To compile we will type on command line "ilasm
ArgIn /dll"
.
Reference .assembly extern System.Windows.Forms
deserves additional
explanation. This is value on my machine, if it does not work on yours copy and
paste in notepad following:
using System; using System.Windows.Forms; class try1 { public static void Main() { MessageBox.Show ("Test", "Test app"); } }
save it as test.cs and compile from command line typing "csc test.cs". Send test.exe to ildasm and check what is in MANIFEST (double click on it). If it is necessary copy values and apply it in your code.
Now is a time to compile client application. ArgIn.dll must be in the same folder .From command line execute "ilasm client.il" and run client.exe. You will see message box with message "Hello from client" and title "From dll". I hope that you will find that IL assembler is very friendly and write some code on your own.
At the end I wish to thank Microsoft for making .NET platform available to public, my company Objectronics for providing me with their copy of .NET Framework Beta 2 and finally to my dear friend Dmitri Vibornov for idea and his help on coding and preparing this article.
If you have any question or suggestion I can be reached at [email protected] if time allows I will come back to you.
Comments