Loading DLL files from inside .exe?

Kragex Jul 16, 2012

  1. Kragex

    Kragex Newbie BANNED
    5/47

    Joined:
    Jul 14, 2012
    Messages:
    372
    Likes Received:
    45
    Trophy Points:
    0
    Gender:
    Male
    Location:
    Northampton
    Console:
    Xbox
    I've never been the greatest coder but back during college I made a few proxies and such, I've recently started again but I can't remember how or if it's possible to have the DLL files load from inside the program. Making it just a single .exe that's easy to distribute?
     
  2. KillerVidz

    KillerVidz Rocky BANNED
    0/47

    Joined:
    Feb 20, 2012
    Messages:
    3,312
    Likes Received:
    1,280
    Trophy Points:
    0
    Gender:
    Male
    Location:
    XPG-UK
    Console:
    Xbox One
    Download SmartAssembliy And Merge Package io in with it ;) ( thats if ur making save editors )
     
  3. Ji

    JizzaBeez The One and Only
    0/47

    Joined:
    Nov 15, 2009
    Messages:
    384
    Likes Received:
    136
    Trophy Points:
    0
    Gender:
    Male
    Location:
    Cerebral Cortex.
    Console:
    Xbox
    You can use System.Reflection to load an Assembly (from file path, Resources, etc.) and then get the loaded Assembly's Classes, Methods, etc.

    Here is an example for using System.Reflection in Visual Basic:
    Code:
    Imports System.Reflection
    
    Namespace ReflectionDemo
    
    	'//Reflecting on Methods
    	' GetMethodsDemo
    	Namespace Reflection1
    		Class GetMethodsDemo
    			Private Shared Sub Main()
    				' Get name of type
    				Dim t As Type = GetType(Char)
    				GetMethod(t)
    				GetMethods(t)
    				Console.ReadLine()
    			End Sub
    
    			' Display method names of type.
    			Public Shared Sub GetMethods(ByVal t As Type)
    				Console.WriteLine("***** Methods *****")
    				Dim mi As MethodInfo() = t.GetMethods()
    				For Each m As MethodInfo In mi
    					Console.WriteLine("->{0}", m.Name)
    				Next
    				Console.WriteLine("")
    			End Sub
    
    			' Display method name of type.
    			Public Shared Sub GetMethod(ByVal t As Type)
    				Console.WriteLine("***** Method *****")
    				'This searches for name is case-sensitive.
    				'The search includes public static and public instance methods.
    				Dim mi As MethodInfo = t.GetMethod("IsMoving")
    				Console.WriteLine("->{0}", mi.Name)
    				Console.WriteLine("")
    			End Sub
    		End Class
    	End Namespace
    
    
    	'//Reflecting on Fields and Properties
    	' GetFieldsPropertiesDemo
    	Namespace Reflection2
    		Class GetFieldsPropertiesDemo
    			Private Shared Sub Main()
    				' Get name of type
    				Dim t As Type = GetType(Char)
    				GetFields(t)
    				GetProperties(t)
    				Console.ReadLine()
    			End Sub
    
    			' Display field names of type.
    			Public Shared Sub GetFields(ByVal t As Type)
    				Console.WriteLine("***** Fields *****")
    				Dim fi As FieldInfo() = t.GetFields()
    				For Each field As FieldInfo In fi
    					Console.WriteLine("->{0}", field.Name)
    				Next
    				Console.WriteLine("")
    			End Sub
    
    			' Display property names of type.
    			Public Shared Sub GetProperties(ByVal t As Type)
    				Console.WriteLine("***** Properties *****")
    				Dim pi As PropertyInfo() = t.GetProperties()
    				For Each prop As PropertyInfo In pi
    					Console.WriteLine("->{0}", prop.Name)
    				Next
    				Console.WriteLine("")
    			End Sub
    		End Class
    	End Namespace
    
    
    	'//Reflecting on Implemented Interfaces
    	' GetInterfacesDemo
    	Namespace Reflection3
    		Class GetInterfacesDemo
    			Private Shared Sub Main()
    				' Get name of type
    				Dim t As Type = GetType(Char)
    				GetInterfaces(t)
    				Console.ReadLine()
    			End Sub
    
    			' Display implemented interfaces.
    			Public Shared Sub GetInterfaces(ByVal t As Type)
    				Console.WriteLine("***** Interfaces *****")
    				Dim ifaces As Type() = t.GetInterfaces()
    				For Each i As Type In ifaces
    					Console.WriteLine("->{0}", i.Name)
    				Next
    			End Sub
    		End Class
    	End Namespace
    
    
    	'//Reflecting on Method Parameters and Return Values
    	'  GetParameterInfoDemo
    	Namespace Reflection4
    		Class GetParameterInfoDemo
    			Private Shared Sub Main()
    				' Get name of type
    				Dim t As Type = GetType(Char)
    				GetParametersInfo(t)
    				Console.ReadLine()
    			End Sub
    
    			'Display Method return Type and parameters list
    			Public Shared Sub GetParametersInfo(ByVal t As Type)
    				Console.WriteLine("***** GetParametersInfo *****")
    				Dim mi As MethodInfo() = t.GetMethods()
    				For Each m As MethodInfo In mi
    					' Get return value.
    					Dim retVal As String = m.ReturnType.FullName
    					Dim paramInfo As New StringBuilder()
    					paramInfo.Append("(")
    					' Get params.
    					For Each pi As ParameterInfo In m.GetParameters()
    						paramInfo.Append(String.Format("{0} {1} ", pi.ParameterType, pi.Name))
    					Next
    					paramInfo.Append(")")
    					' Now display the basic method sig.
    					Console.WriteLine("->{0} {1} {2}", retVal, m.Name, paramInfo)
    				Next
    				Console.WriteLine("")
    			End Sub
    		End Class
    	End Namespace
    
    
    	'//Reflecting on Constructor
    	' GetConstractorInfoDemo
    	Namespace Reflection5
    		Class GetConstructorsInfoDemo
    			Private Shared Sub Main()
    				' Get name of type
    				Dim t As Type = GetType(Char)
    				GetConstructorsInfo(t)
    
    				Console.ReadLine()
    			End Sub
    
    			' Display method names of type.
    			Public Shared Sub GetConstructorsInfo(ByVal t As Type)
    				Console.WriteLine("***** ConstructorsInfo *****")
    				Dim ci As ConstructorInfo() = t.GetConstructors()
    				For Each c As ConstructorInfo In ci
    					Console.WriteLine(c.ToString())
    				Next
    				Console.WriteLine("")
    			End Sub
    		End Class
    	End Namespace
    
    
    	'Dynamically Loading an Assembly
    	' AssemblyDemo
    	Namespace Reflection6
    		Class AssemblyDemo
    			Private Shared Sub Main()
    				Dim objAssembly As Assembly
    
    				' You must supply a valid fully qualified assembly name here.
    				objAssembly = Assembly.Load("mscorlib,2.0.0.0,Neutral,b77a5c561934e089")
    
    				' Loads an assembly using its file name  
    				'objAssembly = Assembly.LoadFrom(
    				'	@"C:\Windows\Microsoft.NET\Framework\v1.1.4322\caspol.exe");
    
    				'this loads currnly running process assembly
    				' objAssembly = Assembly.GetExecutingAssembly();
    
    				Dim Types As Type() = objAssembly.GetTypes()
    
    				' Display all the types contained in the specified assembly.
    				For Each objType As Type In Types
    					Console.WriteLine(objType.Name.ToString())
    				Next
    
    				'fetching custom attributes within an assembly
    				Dim arrayAttributes As Attribute() = Attribute.GetCustomAttributes(objAssembly)
    
    				' assembly1 is an Assembly object
    				For Each attrib As Attribute In arrayAttributes
    					Console.WriteLine(attrib.TypeId)
    				Next
    
    				Console.ReadLine()
    			End Sub
    		End Class
    	End Namespace
    
    
    	'Late Binding
    	' LateBindingDemo
    	Namespace Reflection7
    		Class LateBindingDemo
    			Private Shared Sub Main()
    				Dim objAssembly As Assembly
    				' Loads an assembly  
    				objAssembly = Assembly.GetExecutingAssembly()
    
    				'get the class type information in which late bindig applied
    				Dim classType As Type = objAssembly.[GetType]("Reflection.Car")
    
    				'create the instance of class using System.Activator class
    				Dim obj As Object = Activator.CreateInstance(classType)
    
    				'get the method information
    				Dim mi As MethodInfo = classType.GetMethod("IsMoving")
    
    				'Late Binding using Invoke method without parameters
    				Dim isCarMoving As Boolean
    				isCarMoving = CBool(mi.Invoke(obj, Nothing))
    				If isCarMoving Then
    					Console.WriteLine("Car Moving Status is : Moving")
    				Else
    					Console.WriteLine("Car Moving Status is : Not Moving")
    				End If
    
    				'Late Binding with parameters
    				Dim parameters As Object() = New Object(2) {}
    				parameters(0) = 32456
    				'parameter 1 startMiles
    				parameters(1) = 32810
    				'parameter 2 end Miles
    				parameters(2) = 10.6
    				'parameter 3 gallons
    				mi = classType.GetMethod("calculateMPG")
    				Dim MilesPerGallon As Double
    				MilesPerGallon = CDbl(mi.Invoke(obj, parameters))
    				Console.WriteLine("Miles per gallon is : " & MilesPerGallon)
    
    				Console.ReadLine()
    			End Sub
    		End Class
    	End Namespace
    
    End Namespace
    
     
  4. Kragex

    Kragex Newbie BANNED
    0/47

    Joined:
    Jul 14, 2012
    Messages:
    372
    Likes Received:
    45
    Trophy Points:
    0
    Gender:
    Male
    Location:
    Northampton
    Console:
    Xbox
    Both seem ideal, thank you. :)
     
  5. chrisboyz18

    chrisboyz18 Newbie
    5/47

    Joined:
    Jun 10, 2011
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    5
    Console:
    Xbox
    http://www.enigmapro...om/en/home.html
    • The unique technology which allows combining the files used by your application into a single module without loss of efficiency. This function supports all kinds of files, including dll, ocx, mp3, avi, etc.
     

Share This Page

Close