Public Function DllRegister(ByVal strFileName As String) As Boolean
Return (ApiInvoke(strFileName, "InitApplicationStartPath", GetType(DllSelfRegister)) = 0)
End Function
Private Function ApiInvoke(ByVal LibFilePath As String, ByVal MethodName As String, ByVal DelegateFunctionType As System.Type) As Object
Dim MethodPointer As Integer, ModuleHandle As Integer
Dim ret As Object
ret = Runtime.InteropServices.Marshal.GetDelegateForFunctionPointer(MethodPointer, DelegateFunctionType).DynamicInvoke()//报错:值不能为空。 参数名: ptr
FreeLibrary(ModuleHandle)
Return ret
End Function
Private Sub 广电ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 广电ToolStripMenuItem.Click
DllRegister("Debug_冰箱/MainControl5.12.dll")
End Sub
Private Sub 洗衣机ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 洗衣机ToolStripMenuItem.Click
DllRegister("Debug_空调/MainControl5.12.dll")
End Sub
Dim asm As System.Reflection.Assembly = System.Reflection.Assembly.LoadFile("E:/实验室项目/毕业项目/毕业设计_冰冷可靠性测试系统/0.冰冷可靠性测试系统/TestSystem - 全面版本--冰箱/Test/bin/Debug/Debug_冰箱/MainControl5.12.dll")
Dim classtemp As Type = asm.GetType("MainControl5._12.MainUserControl")//b为nothing
Dim obj As Object = asm.CreateInstance(classtemp.FullName)
obj.InitApplicationStartPath(Application.StartupPath + "\Debug_冰箱\")
Dim asm As System.Reflection.Assembly = System.Reflection.Assembly.LoadFile("E:/实验室项目/毕业项目/毕业设计_冰冷可靠性测试系统/0.冰冷可靠性测试系统/TestSystem - 全面版本--冰箱/Test/bin/Debug/Debug_冰箱/MainControl5.12.dll")
Dim classtemp As Type = asm.GetType("MainControl5._12.MainUserControl")//b为nothing
Dim obj As Object = asm.CreateInstance(classtemp.FullName)
obj.InitApplicationStartPath(Application.StartupPath + "\Debug_冰箱\")
Dim asm As System.Reflection.Assembly = System.Reflection.Assembly.LoadFile("E:/实验室项目/毕业项目/毕业设计_冰冷可靠性测试系统/0.冰冷可靠性测试系统/TestSystem - 全面版本--冰箱/Test/bin/Debug/Debug_冰箱/MainControl5.12.dll")
Dim classtemp As Type = asm.GetType("MainControl5._12.MainUserControl")//b为nothing
Dim obj As Object = asm.CreateInstance(classtemp.FullName)
obj.InitApplicationStartPath(Application.StartupPath + "\Debug_冰箱\")
Dim asm As System.Reflection.Assembly = System.Reflection.Assembly.LoadFile("DLL的绝对路径")
Dim classtemp1 As Type = asm.GetType("MainControl5._12.MainUserControl")//命名空间.类名
Dim obj1 As Object = asm.CreateInstance(classtemp1.FullName)//创建实例
obj1.Dock = DockStyle.Fill
obj1.InitApplicationStartPath(Application.StartupPath)//调用方法
缺点就是不能马上卸载已加载的dll
#18
贴出我暂时可行的动态加载DLL的代码。
Dim asm As System.Reflection.Assembly = System.Reflection.Assembly.LoadFile("DLL的绝对路径")
Dim classtemp1 As Type = asm.GetType("MainControl5._12.MainUserControl")//命名空间.类名
Dim obj1 As Object = asm.CreateInstance(classtemp1.FullName)//创建实例
obj1.Dock = DockStyle.Fill
obj1.InitApplicationStartPath(Application.StartupPath)//调用方法
缺点就是不能马上卸载已加载的dll
我以前做ERP时,系统也是动态加载。每个单据有更新时,将原来的FORM/DLL先CLOSE,再设置一次 BILL=NOTHING 。在不关闭系统下再加载新版本没有任何问题。至于你说的连续加载,我有点想不是明白。因为,每反射一次,实际上你得到的是一个实例。本质和 DIM O AS NEW OBJECT 是一样。你可以NEW无数个实例。
#19
贴出我暂时可行的动态加载DLL的代码。
Dim asm As System.Reflection.Assembly = System.Reflection.Assembly.LoadFile("DLL的绝对路径")
Dim classtemp1 As Type = asm.GetType("MainControl5._12.MainUserControl")//命名空间.类名
Dim obj1 As Object = asm.CreateInstance(classtemp1.FullName)//创建实例
obj1.Dock = DockStyle.Fill
obj1.InitApplicationStartPath(Application.StartupPath)//调用方法
Dim asm As System.Reflection.Assembly = System.Reflection.Assembly.LoadFile("DLL的绝对路径")
Dim classtemp1 As Type = asm.GetType("MainControl5._12.MainUserControl")//命名空间.类名
Dim obj1 As Object = asm.CreateInstance(classtemp1.FullName)//创建实例
obj1.Dock = DockStyle.Fill
obj1.InitApplicationStartPath(Application.StartupPath)//调用方法
Dim asm As System.Reflection.Assembly = System.Reflection.Assembly.LoadFile("E:/实验室项目/毕业项目/毕业设计_冰冷可靠性测试系统/0.冰冷可靠性测试系统/TestSystem - 全面版本--冰箱/Test/bin/Debug/Debug_冰箱/MainControl5.12.dll")
Dim classtemp As Type = asm.GetType("MainControl5._12.MainUserControl")//b为nothing
Dim obj As Object = asm.CreateInstance(classtemp.FullName)
obj.InitApplicationStartPath(Application.StartupPath + "\Debug_冰箱\")
Dim asm As System.Reflection.Assembly = System.Reflection.Assembly.LoadFile("E:/实验室项目/毕业项目/毕业设计_冰冷可靠性测试系统/0.冰冷可靠性测试系统/TestSystem - 全面版本--冰箱/Test/bin/Debug/Debug_冰箱/MainControl5.12.dll")
Dim classtemp As Type = asm.GetType("MainControl5._12.MainUserControl")//b为nothing
Dim obj As Object = asm.CreateInstance(classtemp.FullName)
obj.InitApplicationStartPath(Application.StartupPath + "\Debug_冰箱\")
Dim asm As System.Reflection.Assembly = System.Reflection.Assembly.LoadFile("E:/实验室项目/毕业项目/毕业设计_冰冷可靠性测试系统/0.冰冷可靠性测试系统/TestSystem - 全面版本--冰箱/Test/bin/Debug/Debug_冰箱/MainControl5.12.dll")
Dim classtemp As Type = asm.GetType("MainControl5._12.MainUserControl")//b为nothing
Dim obj As Object = asm.CreateInstance(classtemp.FullName)
obj.InitApplicationStartPath(Application.StartupPath + "\Debug_冰箱\")
Dim asm As System.Reflection.Assembly = System.Reflection.Assembly.LoadFile("DLL的绝对路径")
Dim classtemp1 As Type = asm.GetType("MainControl5._12.MainUserControl")//命名空间.类名
Dim obj1 As Object = asm.CreateInstance(classtemp1.FullName)//创建实例
obj1.Dock = DockStyle.Fill
obj1.InitApplicationStartPath(Application.StartupPath)//调用方法
缺点就是不能马上卸载已加载的dll
#18
贴出我暂时可行的动态加载DLL的代码。
Dim asm As System.Reflection.Assembly = System.Reflection.Assembly.LoadFile("DLL的绝对路径")
Dim classtemp1 As Type = asm.GetType("MainControl5._12.MainUserControl")//命名空间.类名
Dim obj1 As Object = asm.CreateInstance(classtemp1.FullName)//创建实例
obj1.Dock = DockStyle.Fill
obj1.InitApplicationStartPath(Application.StartupPath)//调用方法
缺点就是不能马上卸载已加载的dll
我以前做ERP时,系统也是动态加载。每个单据有更新时,将原来的FORM/DLL先CLOSE,再设置一次 BILL=NOTHING 。在不关闭系统下再加载新版本没有任何问题。至于你说的连续加载,我有点想不是明白。因为,每反射一次,实际上你得到的是一个实例。本质和 DIM O AS NEW OBJECT 是一样。你可以NEW无数个实例。
#19
贴出我暂时可行的动态加载DLL的代码。
Dim asm As System.Reflection.Assembly = System.Reflection.Assembly.LoadFile("DLL的绝对路径")
Dim classtemp1 As Type = asm.GetType("MainControl5._12.MainUserControl")//命名空间.类名
Dim obj1 As Object = asm.CreateInstance(classtemp1.FullName)//创建实例
obj1.Dock = DockStyle.Fill
obj1.InitApplicationStartPath(Application.StartupPath)//调用方法
Dim asm As System.Reflection.Assembly = System.Reflection.Assembly.LoadFile("DLL的绝对路径")
Dim classtemp1 As Type = asm.GetType("MainControl5._12.MainUserControl")//命名空间.类名
Dim obj1 As Object = asm.CreateInstance(classtemp1.FullName)//创建实例
obj1.Dock = DockStyle.Fill
obj1.InitApplicationStartPath(Application.StartupPath)//调用方法