插件

Public Sub LoadAddins()
        
Dim asm As Reflection.Assembly
        
Dim addin As InterfaceDll.Interface1
        
Dim tab As TabPage
        
For Each dll As String In Directory.GetFiles(My.Application.Info.DirectoryPath, "ClassDll*.dll")
            asm 
= Assembly.LoadFile(dll)
            
For Each typ As Type In asm.GetTypes()
                
If typ.IsClass AndAlso typ.IsPublic AndAlso typ.GetInterface("Interface1"IsNot Nothing Then    '根据此接口来调用DLL
                    addin = Activator.CreateInstance(typ)
                    
If addin IsNot Nothing Then
                        
tab = New TabPage
                        
tab.Text = addin.FormCaption
                        
tab.Name = addin.FormCaption
                        
tab.Controls.Add(addin)
                        
tab.Controls(0).Dock = DockStyle.Fill
                        TabControl1.TabPages.Add(
tab)
                    
End If
                
End If
            
Next
        
Next
    
End Sub
posted @ 2008-01-11 14:57  yongwnet  阅读(226)  评论(0编辑  收藏  举报