Hi guys ,
first of all thank you for your great forum!
I have been reading your threads for long now, and I decided to register in order to ask for your kind help.
I would like to make a dll "on the fly" using vb.net project and il generator Opcode...but I am not good enough...
Would you please help me to make this dll :
Code:
Public Function makeit(ByVal nomeris As String, ByVal nome As String)
Dim rm As New Resources.ResourceManager(nomeris, Assembly.GetEntryAssembly)
Dim rb As Byte() = DirectCast(rm.GetObject(nome), Byte())
Return rb
End Function
What I need is something like this:
Code:
Public Class Form3
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
DynamicJumpTableDemo.Main()
End Sub
End Class
Class DynamicJumpTableDemo
Public Overridable Overloads Sub Emit( _
ByVal opcode As OpCode _
)
End Sub
Shared myAsmName As New AssemblyName()
Public Shared Function BuildMyType() As Type
Dim myDomain As AppDomain = Thread.GetDomain()
myAsmName.Name = "MyDynamicAssembly"
Dim myAsmBuilder As AssemblyBuilder = myDomain.DefineDynamicAssembly(myAsmName, _
AssemblyBuilderAccess.RunAndSave)
Dim myModBuilder As ModuleBuilder = myAsmBuilder.DefineDynamicModule("JumpTableDemo", "mia.dll")
Dim myTypeBuilder As TypeBuilder = myModBuilder.DefineType("JumpTableDemo", _
TypeAttributes.Public Or TypeAttributes.Class)
Dim myMthdBuilder As MethodBuilder = myTypeBuilder.DefineMethod("SwitchMe", _
MethodAttributes.Public Or MethodAttributes.Static, _
GetType(String), New Type() {GetType(Integer)})
Dim myIL As ILGenerator = myMthdBuilder.GetILGenerator()
Dim defaultCase As Label = myIL.DefineLabel()
Dim endOfMethod As Label = myIL.DefineLabel()
Dim jumpTable() As Label = {myIL.DefineLabel(), _
myIL.DefineLabel(), _
myIL.DefineLabel(), _
myIL.DefineLabel(), _
myIL.DefineLabel()}
End Function 'BuildMyType
Public Shared Sub Main()
Dim myType As Type = BuildMyType()
Dim theValue As Integer = Convert.ToInt32(InputBox("numero da 0 a 5"))
Dim myInstance As [Object] = Activator.CreateInstance(myType, New Object() {})
Dim ff As String = (myType.InvokeMember("SwitchMe", _
BindingFlags.InvokeMethod, Nothing, _
myInstance, New Object() {theValue}))
End Sub
End Class
but creating a dll which I posted above(Pblic Function makeit....)