Click here to Skip to main content
12,357,929 members (71,633 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VB7.x VB9.0 C# VB VB.NET
My question is that how can a VB.NET PROGRAM create exe's ?
Suppose in my program i have a button with caption "save as EXE" and when i click that
it saves the form as an executable.
I need this for my programming language????
Any code for that????
You know what's a programming language? Right?
You that it compiles the code into an exe.
I have implemented a programming language using VB.NET and it can create windows forms. But I dont know how to create excecutables of those forms.
Any code or a source for that????
I know how to make a exe file in C#.NET of a module :
Here's the code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using System.Reflection.Emit;
namespace Asharp_Compiler
{
    class Program
    {
        static AssemblyName an;
        static AssemblyBuilder ab;
        static ModuleBuilder mb;
        static TypeBuilder tb;
        static _AppDomain ad;
        static MethodBuilder meb;
        static ILGenerator il;
        static void Main(string[] args)
        {
            ad = AppDomain.CurrentDomain;
            an = new AssemblyName("lol");
            ab = ad.DefineDynamicAssembly(an, AssemblyBuilderAccess.Save);
            mb = ab.DefineDynamicModule("Lol", "idk.exe");
            tb = mb.DefineType("lolType", TypeAttributes.Public);
            meb = tb.DefineMethod("main", MethodAttributes.Public | MethodAttributes.Static);
            il = meb.GetILGenerator();
            an.Name = "MyApp";
            ab.SetEntryPoint(meb);
            StreamReader sr = new StreamReader(args[0]);
            string Code = sr.ReadToEnd();
 
            foreach (string cmd in Code.Split('\n'))
            {
                if (cmd.StartsWith("print "))
                {
                    il.Emit(OpCodes.Ldstr, cmd.Substring(6));
                    il.Emit(OpCodes.Call, typeof(System.Console).GetMethod("Write", new System.Type[] { typeof(string)}));
 
                }
                if (cmd.StartsWith("println"))
                {
                    il.Emit(OpCodes.Ldstr, cmd.Substring(8));
                    il.Emit(OpCodes.Call, typeof(System.Console).GetMethod("WriteLine", new System.Type[] { typeof(string) }));
 
                }
            }
            il.Emit(OpCodes.Ret);
            tb.CreateType();
            ab.Save(Path.GetFileNameWithoutExtension(args[0]) + ".exe");
        }
    }
}
Can i do the same with vb cause i don't know C# well
Posted 15-Dec-12 1:17am
sid2x1.1K
Edited 16-Dec-12 4:44am
v3
Comments
Nelek 15-Dec-12 8:25am
   
Create an "exe" from where, with what? You are already creating an "exe" or a "dll" or whatever you set in the project when you compile your code.

What do you want to generate? What is that "exe" supposed to do? Please use the "improve question" widget and add some more information, since it is not really clear what you mean.

Possible... it is possible (i.e: winzip auto-selfextracting tool) but if it really makes sense or how difficult will be... it depends on many many factors
Richard MacCutchan 15-Dec-12 8:29am
   
This is not a simple issue. You need to learn and understand the format of both object and executable files, how to convert source program to object code and how to link object modules into executables. I would suggest you try some Google searching for utilities and libraries that will help in the process.
Richard MacCutchan 16-Dec-12 7:10am
   
You have edited your question, but you have not added any significant detail. I have explained above the things that you need to research so I suggest you make a start as there is a lot to learn.
Richard MacCutchan 16-Dec-12 12:59pm
   
You can convert that into VB.NET, the .NET parts will be the same.

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Hi,

You can use on-the-fly compiling:
Compiling .NET code on-the-fly[^]
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160621.1 | Last Updated 16 Dec 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100