Public Class Form1
Public Sub New()
''加载DLL到exe的事件
AddHandler AppDomain.CurrentDomain.AssemblyResolve, New ResolveEventHandler(AddressOf CurrentDomain_AssemblyResolve)
InitializeComponent()
End Sub
''' <summary>
''' 把DLL加载到EXE中
''' </summary>
''' <param name="sender"></param>
''' <param name="args"></param>
''' <returns></returns>
Private Function CurrentDomain_AssemblyResolve(sender As Object, args As ResolveEventArgs) As System.Reflection.Assembly
Dim dllName As String = If(args.Name.Contains(","), args.Name.Substring(0, args.Name.IndexOf(","c)), args.Name.Replace(".dll", ""))
dllName = dllName.Replace(".", "_")
If dllName.EndsWith("_resources") Then
Return Nothing
End If
Dim rm As New System.Resources.ResourceManager([GetType].Namespace & ".Resources", System.Reflection.Assembly.GetExecutingAssembly())
Dim bytes As Byte() = DirectCast(rm.GetObject(dllName), Byte())
Return System.Reflection.Assembly.Load(bytes)
End Function
'以下为项目正式的代码
End Class