用程序实现Add from file,以使系统初始化的时候能按不同配置加载相应的扩展功能。
二、实现
1、利用反射技术加载并注册dll文件
Dim
asm
As
Assembly
asm = Assembly .LoadFile(filename)
Dim regService As New RegistrationServices
regService.RegisterAssembly(asm, AssemblyRegistrationFlags.SetCodeBase)
asm = Assembly .LoadFile(filename)
Dim regService As New RegistrationServices
regService.RegisterAssembly(asm, AssemblyRegistrationFlags.SetCodeBase)
注:其中filename是该dll文件的路径,该路径可以通过OpenFileDialog获取,也可以通过StreamReader读取配置文件中dll文件的路径信息批量获取。
2、利用AddItem添加dll中的Command到ToolbarControl上
Dim
t
As
Type()
=
asm.GetTypes()
Dim i As Int16
For i = 0 To t.Length - 1
If Not t(i).GetInterface( " ICommand " ) Is Nothing Then
Dim pUid As New UIDClass
pUid.Value = " { " & t(i).GUID.ToString & " } "
AxToolbarControl1.AddItem(pUid)
End If
Dim i As Int16
For i = 0 To t.Length - 1
If Not t(i).GetInterface( " ICommand " ) Is Nothing Then
Dim pUid As New UIDClass
pUid.Value = " { " & t(i).GUID.ToString & " } "
AxToolbarControl1.AddItem(pUid)
End If
三、参考
http://forums.esri.com/Thread.asp?c=159&f=1707&t=176719&mc=2#msgid520646
http://forums.esri.com/Thread.asp?c=159&f=1705&t=165566&mc=7#msgid486539