Codedom - Make your own advanced builder 09-22-2013, 01:22 PM
#1
Hello,
this is my first tutorial on HC and my english isnt the best, so dont be so strictly
.
Lets begin:
What is CodeDom ?: CodedDom
We will use CodeDom to compile our stub code stored in a string, the big advantage is that you can edit the code easily.
I assume that you know, what Classes, Subs, Functions and so on are.
Builder:
First of all you will need the compiler.vb class:
You see, its not that much code.
Now add a document to the resources of the project.
With this text here:
Know add your code, and replace the variables(given by the user) with something like [FTP].
Know go to your Builder and add something like this:
With this method you can easily add not just variables, complete functions, subs can be added with this.
Use this code wherever you want.
Peace :Cool:
this is my first tutorial on HC and my english isnt the best, so dont be so strictly
.Lets begin:
What is CodeDom ?: CodedDom
We will use CodeDom to compile our stub code stored in a string, the big advantage is that you can edit the code easily.
I assume that you know, what Classes, Subs, Functions and so on are.
Builder:
First of all you will need the compiler.vb class:
Code:
Imports System.CodeDom.Compiler
Public Class compiler
Public Shared Sub Compile(ByVal Output As String, ByVal cSource As String)
Dim Compiler As ICodeCompiler = New VBCodeProvider().CreateCompiler 'Creating compiler
Dim Parameters As New CompilerParameters 'A type of variable, holding things like: path to save, imports and more
Dim cResults As CompilerResults 'Used for checking if everything is fine
Parameters.GenerateExecutable = True 'We want to make an EXE-File
Parameters.OutputAssembly = Output 'Declare where to save the file
Parameters.ReferencedAssemblies.Add("System.dll") 'We need that if we want to import something like: System.IO
Parameters.ReferencedAssemblies.Add("System.Data.dll")
Parameters.ReferencedAssemblies.Add("System.Windows.Forms.dll") 'Adding basic references, you have to do this because you cant do it in the code. (Things like "System.IO" can be added in the code :) ).
Parameters.CompilerOptions = "/optimize+ /platform:X86 /debug- /target:winexe" 'Basic parameters: read more here: http://msdn.microsoft.com/en-us/library/w95cx9k1.aspx
cResults = Compiler.CompileAssemblyFromSource(Parameters, cSource) 'Compile the code with the Parameters Variable and the source given in compiler.Compile(pathtofile,My.Resources.Stub)
If cResults.Errors.Count > 0 Then 'Checking for errors
For Each CompilerError In cResults.Errors 'Looping through all of them, use CompilerError.errorText to get the error
msgbox(CompilerError.errorText)
Next
ElseIf cResults.Errors.Count = 0 Then 'No errors
End If
End Sub
End ClassYou see, its not that much code.
Now add a document to the resources of the project.
With this text here:
Code:
Imports System.Net
Imports System.IO
Imports System.Collections 'Basic imports (feel free to change them :) )
Module Stub
Sub main()
End Sub
End ModuleKnow add your code, and replace the variables(given by the user) with something like [FTP].
Code:
Imports System.Net
Imports System.IO
Imports System.Collections 'Basic imports (feel free to change them :) )
Module Stub
Sub main()
My.Computer.Network.DownloadFile([Dlink],[WhereToSave])
End Sub
End ModuleKnow go to your Builder and add something like this:
Code:
Above the code: Imports ProjectName.compilerCode:
Dim src As String = My.Resources.documentname
src = src.Replace("[Dlink]", Downloadlink.Text)
src = src.Replace("[WhereToSave]",save.text)
compiler.Compile(pathtosaveEXE, src)With this method you can easily add not just variables, complete functions, subs can be added with this.
Use this code wherever you want.
Peace :Cool:


![[+]](https://sinister.li/images/modern/collapse_collapsed.png)


![[Image: 2xgfjby9.png]](http://s1.directupload.net/images/131103/2xgfjby9.png)