·首页 ·asp ·.net ·php ·JSP ·CGI ·数据库 ·网页设计 ·网管专栏 ·XML ·工具软件 ·办公软件 ·操作系统 ·程序设计 ·LINUX 
  当前位置: 普克>>计算机教程>>.net>>Windows开发>>Create Exe On Fly
flash视频教学

photoshop专题

asp.net专题

office专题

Create Exe On Fly


Windows开发 发表时间:2006-4-8 字体:  返回
Creating Exe on the Fly
Submitted ByUser LevelDate of Submission
Kunal ChedaBeginner06/29/2001

This is probably the most wonderful this I have explored in .net. What happens here is a user can actually make the EXE file on the fly. System.Runtime.Emit Namespace provides necessay class to do this.
After compiling this file and running it on the Console a new file is generated in your folder called TestAsm.exe. This Exe file print's a message "Hello World" on the Console.

Source Code:

RuntimeEmit.cs  
using System;
using System.Runtime;
using System.Runtime.Emit;
Class RuntimeEmit
{
public static void Main(String [] args)
{
         AppDomain ad = AppDomain.CurrentDomain;
         AssemblyName am = new AssemblyName();
         am.Name = "TestAsm";
        AssemblyBuilder ab = ad.DefineDynamicAssembly(am,AssemblyBuilderAccess.Save);
        ModuleBuilder mb = ab.DefineDynamicModule("testmod","TestAsm.exe");
        TypeBuilder tb = mb.DefineType("mytype",TypeAttributes.Public);  
        MethodBuilder metb = tb.DefineMethod("hi",MethodAttributes.Public | MethodAttributes.Static,null,null);
        mb.SetEntryPoint(metb);
        ILGenerator il = metb.GetILGenerator();
        il.EmitWriteLine("Hello World");
        il.Emit(OpCodes.Ret);  
        tb.CreateType();
        ab.Save("TestAsm.exe");
}
}

Save this file as RuntimeEmit.cs  and Compile C:/>csc RuntimeEmit.cs and run this file C:\>RuntimeEmit  
to run the Exe file generated  C:\>TestAsm


上一篇:Rotation Sample
下一篇:关于序列化--这篇完整些,但是是for beta1的

普克创业投资网刊载此文不代表同意其说法或描述,仅为提供更多信息。
在百度中搜索Create Exe On Fly的相关内容]   [在狗狗中搜索Create Exe On Fly的相关内容]
Copyright @ 2006 PUPK.COM 普克创业投资网 版权所有
 建议使用1024*768以达到最好的浏览效果