SuperNeo Posted July 19, 2004 Posted July 19, 2004 Hello everybody. I use VB.net. I have a problem about how to creat exe file from my application on runtime. That is: I have a program A, I want A can dynamic creat a program B on runtime. B have been custom by some parameter that user input to A. How can I do this? Who can teach me? Thanks!!! Quote
Administrators PlausiblyDamp Posted July 19, 2004 Administrators Posted July 19, 2004 If you want to create code on the fly then you need to be looking at the classes under System.Reflection.Emit - these are the ones that allow you to construct assemblies dynamically. What kind of program would A be generating? What are the parameters that determine how this works? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Joe Mamma Posted July 19, 2004 Posted July 19, 2004 Hello everybody. I use VB.net. I have a problem about how to creat exe file from my application on runtime. That is: I have a program A, I want A can dynamic creat a program B on runtime. B have been custom by some parameter that user input to A. How can I do this? Who can teach me? Thanks!!! there are a couple of ways to skin this cat: 1. Generate the code as a text file and compile from program A. (probably the easiest) 2. use System.Reflection.Emit classes to dynamically generate IDL (more robust but more complex) There are some great examples in the help file. look up AssemblyBuilder class. Is the dynamic assembly an actual exe or do you just want to dynamically extend the currently running application? Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
SuperNeo Posted July 22, 2004 Author Posted July 22, 2004 there are a couple of ways to skin this cat: 1. Generate the code as a text file and compile from program A. (probably the easiest) 2. use System.Reflection.Emit classes to dynamically generate IDL (more robust but more complex) There are some great examples in the help file. look up AssemblyBuilder class. Is the dynamic assembly an actual exe or do you just want to dynamically extend the currently running application? Thank you for yourhelp. I wanna dynamic assembly an actual exe. But I cannot understand your first way. How to Generate the code as a text file and compile from program A? My VB.net and english are all very poor. Can you explain your first way more detail? Quote
predseda Posted July 22, 2004 Posted July 22, 2004 Thank you for yourhelp. I wanna dynamic assembly an actual exe. But I cannot understand your first way. How to Generate the code as a text file and compile from program A? My VB.net and english are all very poor. Can you explain your first way more detail? 1. Study English 2. Study VB.NET If your home language is Czech or Slovak you can ask me in this languages if you need help & you are not english speaking, but study english - 99,9% of all programming resources are in english. Quote
Arch4ngel Posted July 22, 2004 Posted July 22, 2004 Some study incoming Well... You'll be having a hard time buddy. I admit... I'm french canadian (From Quebec) and I speak english as nearly good as my french (well... our french isn't that good :p). But you'll really have to learn english to understand and produce good english text (speaking isn't necessary ... well ... for now). VB.NET has many many many (did I said many ?) many tutorial on the web right now. Look into google for "VB.NET tutorial" and you'll be having a great time. Dynamic assembly and code compilation on the fly is - maybe - a little to advance for you right now... I might be wrong... but all you'll have is all the code without really understanding everything that happen behind all that. 2 solution are given to you. -Learn VB.NET a little bit more and come back -Continue in this thread and try to make the impossible possible. :) Thank you for your patience. Quote "If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown "Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me "A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend. C# TO VB TRANSLATOR
SuperNeo Posted July 26, 2004 Author Posted July 26, 2004 I find a example at: http://www.c-sharpcorner.com/1/ExeOnFlyKunal.asp But this example write in C# I have rewrite example in VB.net, But get a error. My code is below: Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Main() End Sub Public Shared Sub Main() Dim AppD As AppDomain AppD = AppDomain.CurrentDomain Dim AssemblyN As New AssemblyName AssemblyN.Name = "TestAsm" Dim AssemblyB As AssemblyBuilder AssemblyB = AppD.DefineDynamicAssembly(AssemblyN, AssemblyBuilderAccess.Save) Dim ModuleB As ModuleBuilder ModuleB = AssemblyB.DefineDynamicModule("testmod", "TestAsm.exe") Dim TypeB As TypeBuilder TypeB = ModuleB.DefineType("mytype", TypeAttributes.Public) Dim MethodB As MethodBuilder MethodB = TypeB.DefineMethod("hi", MethodAttributes.Public Or MethodAttributes.Static, GetType(String), New Type() {GetType(String)}) AssemblyB.SetEntryPoint(MethodB) Dim ILG As ILGenerator ILG = MethodB.GetILGenerator() ILG.EmitWriteLine("Hello World") ILG.Emit(OpCodes.Ret) TypeB.CreateType() AssemblyB.Save("TestAsm.exe") End Sub End Class How to I can fix my code? Quote
Joe Mamma Posted July 26, 2004 Posted July 26, 2004 I could be wrong as I have only taken a cursory look. . . the entry point code you referenced in the link: MethodBuilder metb = tb.DefineMethod("hi", MethodAttributes.Public |MethodAttributes.Static, null,null); has a signature: Public Shared Sub hi() your translation: MethodB = TypeB.DefineMethod("hi", MethodAttributes.Public Or MethodAttributes.Static, GetType(String), New Type() {GetType(String)}) has a signature ( aString is implied): Public Shared Function hi(AString as string) as string shouldn't your translation be: MethodB = TypeB.DefineMethod("hi", MethodAttributes.Public Or MethodAttributes.Static, Nothing, Nothing) Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.