EDN Code Exchange

Updated Sep 29, 2010
Add Component
frmAddComponent.frm

' Copyright 1995-2004 ESRI

' All rights reserved under the copyright laws of the United States.

' You may freely redistribute and use this sample code, with or without modification.

' Disclaimer: THE SAMPLE CODE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 
' WARRANTIES, INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
' FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ESRI OR 
' CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 
' OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
' SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
' INTERRUPTION) SUSTAINED BY YOU OR A THIRD PARTY, HOWEVER CAUSED AND ON ANY 
' THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ARISING IN ANY 
' WAY OUT OF THE USE OF THIS SAMPLE CODE, EVEN IF ADVISED OF THE POSSIBILITY OF 
' SUCH DAMAGE.

' For additional information contact: Environmental Systems Research Institute, Inc.

' Attn: Contracts Dept.

' 380 New York Street

' Redlands, California, U.S.A. 92373 

' Email: contracts@esri.com

Option Explicit

' Declare UDT
Private Type RegisterInfo
  CatName(5) As String
  CatID(5) As String
  IName(5) As String
  IID(5) As String
End Type

' Declare variable
Private m_pCompCatMgr As IComponentCategoryManager 'for adding or removing Component
Private m_CatID As New UID  'for category UID
Private m_IID As New UID  'for objectType UID

Private m_strPath As String
Private m_Bool As Boolean

Const m_Filter = "DLL Files (*.dll)|*.dll"
Private m_Msg As String

Sub RegCom(pbool As Boolean, pMsg As String)
  CommonDialog1.ShowOpen
  m_strPath = CommonDialog1.FileName
  
  If Not m_strPath = vbNullString Then
    ' Add the components in the dll (m_strPath) to the selected category (m_CatID)
    m_pCompCatMgr.Setup m_strPath, m_IID, m_CatID, m_Bool
    MsgBox pMsg
  End If
End Sub

Private Sub cmdAdd_Click()
  m_Bool = True
  m_Msg = "Please start ArcMap or ArcCatalog to see if the components have been added.  " _
  & "If not, you might have selected the wrong category. Try it again."
  RegCom m_Bool, m_Msg 'add component
End Sub

Private Sub cmdClose_Click()
  Unload Me
End Sub

Private Sub cmdRemove_Click()
  m_Bool = False
  m_Msg = "Please start ArcMap or ArcCatalog to see if the components have been removed.  " _
  & "If not, you might have selected the wrong category. Try it again."
  RegCom m_Bool, m_Msg 'remove component
End Sub

Private Sub Form_Load()
  Dim pRegisterInfo As RegisterInfo
  
  ' Intialize pHeadCol, the header for the listview
  Dim pHeadCol(3) As String
  pHeadCol(0) = "Category Name"
  pHeadCol(1) = "Category GUID"
  pHeadCol(2) = "Interface Name"
  pHeadCol(3) = "Interface GUID"
  
  ' Set listview view property
  lvwListView.View = lvwReport
  
  ' Add column Header
  Dim Col As ColumnHeader ' Declare variable.
  Dim Index As Integer
  For Index = LBound(pHeadCol) To UBound(pHeadCol)
    Set Col = lvwListView.ColumnHeaders.Add
    Col.Text = pHeadCol(Index)
    Col.Width = lvwListView.Width / 4
  Next
    
  ' Add ESRI Mx Commands info
  pRegisterInfo.CatName(0) = "ESRI Mx Commands"
  pRegisterInfo.CatID(0) = "{B56A7C42-83D4-11d2-A2E9-080009B6F22B}"
  pRegisterInfo.IName(0) = "ICommand"
  pRegisterInfo.IID(0) = "{36B06538-4437-11D1-B970-080009EE4E51}"
  
  ' Add ESRI Mx CommandBars info
  pRegisterInfo.CatName(1) = "ESRI Mx CommandBars"
  pRegisterInfo.CatID(1) = "{B56A7C4A-83D4-11d2-A2E9-080009B6F22B}"
  pRegisterInfo.IName(1) = "IToolbarDef"
  pRegisterInfo.IID(1) = "{61B318F0-CDA0-11D1-B9A8-080009EE4E51}"
  
  ' Add ESRI Mx Extensions info
  pRegisterInfo.CatName(2) = "ESRI Mx  Extensions"
  pRegisterInfo.CatID(2) = "{B56A7C45-83D4-11d2-A2E9-080009B6F22B}"
  pRegisterInfo.IName(2) = "IExtension"
  pRegisterInfo.IID(2) = "{7F657EC9-DBF1-11D2-9F2F-00C04F6BC69E}"
  
  ' Add ESRI GX Commands info
  pRegisterInfo.CatName(3) = "ESRI GX Commands"
  pRegisterInfo.CatID(3) = "{5F08CBCA-E91F-11d1-AEE8-080009EC734B}"
  pRegisterInfo.IName(3) = "ICommand"
  pRegisterInfo.IID(3) = "{36B06538-4437-11D1-B970-080009EE4E51}"
  
  ' Add ESRI GX CommandBars info
  pRegisterInfo.CatName(4) = "ESRI GX CommandBars"
  pRegisterInfo.CatID(4) = "{56C205F9-E53A-11d1-9496-080009EEBECB}"
  pRegisterInfo.IName(4) = "IToolbarDef"
  pRegisterInfo.IID(4) = "{61B318F0-CDA0-11D1-B9A8-080009EE4E51}"
 
  ' Add ESRI GX Extensions info
  pRegisterInfo.CatName(5) = "ESRI GX Extensions"
  pRegisterInfo.CatID(5) = "{4531C69D-DC07-11d2-9F2F-00C04F6BC69E}"
  pRegisterInfo.IName(5) = "IExtension"
  pRegisterInfo.IID(5) = "{7F657EC9-DBF1-11D2-9F2F-00C04F6BC69E}"
  
  ' Add registerInfo as subitems in lvwListView
  Dim itmX As ListItem
  For Index = LBound(pRegisterInfo.CatName) To UBound(pRegisterInfo.CatName)
    Set itmX = lvwListView.ListItems.Add(, , pRegisterInfo.CatName(Index))
    itmX.SubItems(1) = pRegisterInfo.CatID(Index)
    itmX.SubItems(2) = pRegisterInfo.IName(Index)
    itmX.SubItems(3) = pRegisterInfo.IID(Index)
  Next Index
  
  ' Intialize m_pCompCatMgr
  Set m_pCompCatMgr = New ComponentCategoryManager
  
  ' Set filters for CommonDialog
  CommonDialog1.Filter = m_Filter
End Sub

Private Sub lvwListView_ItemClick(ByVal Item As MSComctlLib.ListItem)
  m_CatID = Item.ListSubItems(1).Text
  m_IID = Item.ListSubItems(3).Text
End Sub