|
Compiling and Calling Assembler DllIt is possible to write a heavily used method in IL Assembler for efficiency and then call this method from C#. In this sample, the dll and calling code is written in IL Assembler. IL Assembler DllHere is the code that prints a string to the console wrapped in a dll call testildll. To compile this code is the ilasm with the /dll directive: >ilasm testildll.il /dll // testildll.il
// 11.29.04 Jeff Louie
.assembly extern mscorlib {}
.module testildll.dll
.class public auto autochar Class2
{
.method public hidebysig static void Test() cil managed
{
.maxstack 1
ldstr "JAL 11.25.04"
call void [mscorlib]System.Console::WriteLine(string)
ret
}
}
This creates a dll called testildll.dll! Call the Custom IL Assembler CodeHere is the code that calls the dll code, again, in assembler! // TestILCallDll.il
// 11.29.04 Jeff Louie
.assembly extern mscorlib {}
.file testildll.dll
.module extern testildll.dll
.assembly TestILCallDll {.ver 1:0:1:0}
.class public auto autochar Class1
{
.method private static void Main(string[] args) cil managed
{
.entrypoint
.custom instance void [mscorlib]System.STAThreadAttribute::.ctor() =
( 01 00 00 00 )
call void [.module testildll.dll]Class2::Test()
ret
} // end of method Main
}
For some reason I get a name collision if I don't use different names for the classes in the exe and dll. Ouput: JAL 11.25.04 Have fun.
|
Send mail to [email protected]
with questions or comments about this web site. Copyright © 2001, 2002, 2003,
2004, 2005, 2006, 2007, 2008, 2009 ©
|