Oct 29, 2014 10:41 AM
(This post was last modified: Oct 30, 2014 08:39 AM by BerryP.)
Hello,
this is my first sourceshare on HF and my english isnt the best, so dont be so strictly 😭
Lets begin:
What is CodeDom ?: CodeDom
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 code here:
Now add your code, and replace the variables(given by the user) with something like [FTP].
Now 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 🤝
this is my first sourceshare on HF and my english isnt the best, so dont be so strictly 😭
Lets begin:
What is CodeDom ?: CodeDom
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:
PHP Code
<?php
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 class, 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 in order to use the basic .Net Framework. (e.g. Namespaces like System.IO)
Parameters.ReferencedAssemblies.Add("System.Data.dll")
Parameters.ReferencedAssemblies.Add("System.Core.dll")
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 object 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
Messagebox.Show(CompilerError.errorText)
Next
ElseIf cResults.Errors.Count = 0 Then 'No errors
End If
End Sub
End Class
You see, its not that much code.
Now add a document to the resources of the project.
With this code here:
PHP Code
<?php
Imports System.Net
Imports System.IO
Imports System.Collections 'Basic imports (feel free to change them :) )
Module Stub
Sub main()
End Sub
End Module
Now add your code, and replace the variables(given by the user) with something like [FTP].
PHP Code
<?php
'Basic namepsace imports, also set by Visual Studio 2012
Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Drawing
Imports System.Collections
Imports System.Collections.Generic
Imports System.Diagnostics
Imports System.Windows.Forms
Module Stub
Sub main()
My.Computer.Network.DownloadFile([Dlink],[WhereToSave])
End Sub
End Module
Now go to your builder and add something like this:
PHP Code
<?php
Above the code: Imports ProjectName.compiler
PHP Code
<?php
Dim src As String = My.Resources.documentname
src = src.Replace("[Dlink]", "You downloadlink")
src = src.Replace("[WhereToSave]","C:\Programs\Downloaded.whatever")
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 🤝
![[Image: xAhLMBg.png]](https://i.imgur.com/xAhLMBg.png)


