????? ????? Office 2000 ????? ???????? COM ?? Visual Basic

?????? ????????? ?????? ?????????
???? ???????: 238228 - ??? ???????? ???? ????? ????? ??? ???????.
????? ???? | ?? ????

?? ??? ??????

??????

Microsoft Office 2000 ???? ???? ??????? ?? ???? ???? ????????? ????? ??????? ?????? ??????? ???????? ????? ??????? ?? ??????? Office. ???? ??? ??????? ???????? ????? COM ????????. ???? ???? ??? ??????? ????? ????? COM ??????? ???????? ???????? Visual Basic.

??????? ????

??????? ???????? COM ?? inprocess COM ???? (DLL ActiveX) ???? ???? ?????? ??????? IDTExensibility2 ??? ?? ???? ?? ??????? ???????? ???? ??? ????? Microsoft (Msaddndr.dll). ???? ????? COM ???????? ??? ?? ??? ??????? ? ??? ?? ???? ?????? ?? ?? ?????? ??? ????? ??.

OnConnection

??? ????? OnConnection ???? ??? ?????? ??????? ???????? COM. ??????? ???????? ???? ?????? ?? ??? ??? ??????? ?????? ???????? ??????? ?? ?? ???? ??????? ????????. ??? ?? ????? OnConnection ?????, ??????? ???????? ?? ???? ???? ??????. ??? ?? ????? ??? ??????? ?????? ?????? ????????? ?????? ?? ???? ??????? ???????? ?? ????? ??????.

???? OnConnection ???????? ?????? ???????:
  • ??????? - ???? ??? ???? ??????? ??????.
  • ConnectMode ???? ???? ????? ??????? ???????? ????.
    • ext_cm_AfterStartup - ????? ?? ????? ???????? ??????? ?? ???? ?????? ??????? ???????? COM.
    • ext_cm_CommandLine - ??????? ?? ??? ???????. (?? ??? ????? ?????? ????? COM ???????? ???????? Office.)
    • ext_cm_External - ????? ?????? ????? ????? ???? ??????? ????????. (?? ??? ????? ?????? ????? COM ???????? ???????? Office.)
    • ext_cm_Startup - ????? ?? ??? ?????? ??? ??? ????? ???????. (??? ?????? ??? ?????? ?????? ????? ?? ???????.)
  • AddInInst ???? ??? ???? COMAddIn ???? ???? ??? ??? ??????? ???????? ?? "?????? ????? COM ????????" ??????? ??????.
  • ???? - ???? ??????? ??? ???? ???? ???? ???????? ???????? ??????? ?? ??? ????????.

OnDisconnection

??? ????? OnDisconnection ????? ??? ??? ??????? ???????? COM ? ??? ????? ????? ?? ???????. ??????? ???????? ??? ????? ????? ????? ?? ??????? ?? ??? ????? ?? ??????? ??? ??????? ??? ??????? ??? ??????? ??????.

???? OnDisconnection ??????? ???????:
  • RemoveMode ???? ???? ????? ??????? ???????? ?? ??? ?????.
    • ext_dm_HostShutdown - ??? ??????? ??? ????? ??????? ??????.
    • ext_dm_UserClosed - ??? ??????? ?? ??? ???????? ??????? "??" ???? ???? ???????.
  • ???? - ???? ??????? ??? ???? ???? ???? ???????? ???????? ??????? ?? ??? ????????.

OnAddInsUpdate

??? ????? OnAddInsUpdate ??? ????? ?????? ??????? ????? COM ????????. ????? ???? ???? ????? ???????? COM ??? ????? ?? ????? ?? ??????? ?????? ??? ??? ?????.

OnStartupComplete ? OnBeginShutdown

??? ??????? ?????? OnStartupComplete ? OnBeginShutdown ??? ??? ??????? ?????? ?? ??? ????? ???? ??? ??? ???? ????? ???????? ??? ??????? ????? ????? ?? ????? ????? ???? ?? ???????. ??? ??????? OnStartupComplete ??? ??? ????? ?????? ?? ????? ????? ??? ??????? ??????? OnBeginShutdown ??? ??? ????? ?????? ?? ??? ??????? ?? ??? ?????? ????? ????? ???????.

??? ????? ???????? ??????? ?????? ??? ???? ???? ??? ????? ??? ???????, ??? ???? ??????? ??????? ?????? ??????? ????? ???? ????? ?????? ?? OnConnection ? OnDisconnection.

????? ??????? ???????? ?? COM

???????? ??? ????? COM ?????? ????? ???????? COM ????? ????? ???? ?? ?? ????? Office ???? ??? ?????. ????? ???? ?? ????? ???? ??????? ???????? ???? ????? ????? ???? ???????? ProgID ????? ?? ??? ??? ????? ??? ?????? ??????:
HKEY_CURRENT_USER\Software\Microsoft\Office\<OfficeApp>\Addins\<ProgID>
??????? ???????? ???? ?? ???? ????? ?? ??? ?????? ??????? ?? ??? ??? ????? ???? ????. ???????? ??? ???? ??????? ???????? ??? ????? ???? ??????? ??????? ???????? ???? DWORD ???? "LoadBehavior." ???? ??? ?????? ??????? ???????? ??? ?????? ?? ??? ??????? ?????? ? ?????? ????? ?? ?????? ?? ????? ???????:
  • 0 = ??? ??????? - ??? ??????.
  • 1 = ???? - ?? ??????.
  • 2 = bootload - ??????? ??? ??????? ??? ???????.
  • 8 = demandLoad - ????? ??? ??? ???? ?? ??? ????????.
  • 16 = ConnectFirstTime - ??????? ??? ????? ??? (??? ??? ??????? ??????).
?????? ????????? ??????? ?? 0x03 (???? | Bootload).

??? ????? ????? ??????? ???????? ???? ???? ?????? IDTExtensibility2 DWORD ?????? ???? "CommandLineSafe" ???????? ??? ?? ??? ??? ????? ???????? ???? ?? ????? ????? ??????. ???? 0x00 ???? False ? 0x01 True.

????? ????? ???????? COM

????? ????? COM ??????? ???????? ????? ????? ?????? ???????? ?????:

????? ????? ???????? COM ???????? ???? Com ????????

??? ??? ???? Microsoft Office 2000 ?????? "??" Microsoft Office XP ?????? "?" Visual Basic 6.0 ???? ????? ?????? ??????? ???????? COM ??????? ???? in.vbp ????? COM. ???? ??? ??????? ?? ?????? ?????? ODETools\V9\Samples\OPG\Samples\CH11\VB_COM_AddIn ??? ????? ??????? ????? ?? Office 2000 ??????. ??? ??????? ?? ??? ?????? ??? ?????? Visual Basic 6.0 Template\Projects ??? ???? Studio\VB98\Template\Projects C:\Program Files\Microsoft ?????. ??? ????? ???? ??? ??? ?????? ???? ??? ?? ???? ?????? ?? ???? ?????? "????? Visual Basic 6.0 ????". ???? 11 ????? ?? ???? ????????? Visual Basic 2000 Microsoft Office ?????? ??? ???? ?? ????????? ??? ??? ?????? ?????? ????? COM ????????.

????? ????? ???????? COM ???????? ???? ??????? ?? Visual Basic 6

??? ??? ???? ????? 6.0 Microsoft Visual Basic ??? ???? ???? ??????? ????? ???? ?? ????? ?????? IDTExtensibility2 ?????? ? ????? ??????? ??? ??????? ???????? ?????? ???? ??????? ?????? In. ????? VB6 ???? ??????? ??????? ?????? ??? ????? ?????? ?? Microsoft Excel 2000 ?? 2002:
  1. ??? ????? Microsoft Visual Basic 6.0 ???? Addin ???? ???????. ???? ??? ????? ??? ???? ??? ??????? (?????) ?????? (frmAddin).
  2. ??? ???? "??????" ??????? ?? ??? Microsoft Excel ?? ??????? ???????? ???????.
  3. ?? ??????? ???????? ???? ??????? ?????? ??? ??? ???????.
  4. ????? frmAddin ?? ???????.
  5. ?? ???? Project ???? ??? ?????? ?????? ??? ?????? ??????? ?? ??? ????? ??? ????????? ????????.
  6. ?? ?????? ???? ????????? ???????? ?? ???? ????????? ???????? ??????. ???? ??? ???????? ???????? ??????? ???????? VB ???? ?? ????? Office ????????.
  7. ?? ?????? ????????? ???????? ??????? ??? ??????:
       Option Explicit
    
       Dim oXL As Object
       Dim WithEvents MyButton As Office.CommandBarButton
    
       Private Sub AddinInstance_OnConnection(ByVal Application As Object, _
        ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, _
        ByVal AddInInst As Object, custom() As Variant)
          On Error Resume Next
          MsgBox "My Addin started in " & Application.Name
       
          Set oXL = Application
       
          Set MyButton = oXL.CommandBars("Standard").Controls.Add(1)
             With MyButton
                .Caption = "My Custom Button"
                .Style = msoButtonCaption
    
              ' The following items are optional, but recommended. 
              ' The Tag property lets you quickly find the control 
              ' and helps MSO keep track of it when there is more than
              ' one application window visible. The property is required
              ' by some Office applications and should be provided.
    
                .Tag = "My Custom Button"
     
              ' The OnAction property is optional but recommended. 
              ' It should be set to the ProgID of the add-in, such that if
              ' the add-in is not loaded when a user presses the button,
              ' MSO loads the add-in automatically and then raises
              ' the Click event for the add-in to handle. 
    
                .OnAction = "!<" & AddInInst.ProgId & ">"
    
                .Visible = True
             End With
       
       End Sub
    
       Private Sub AddinInstance_OnDisconnection(ByVal RemoveMode As _
          AddInDesignerObjects.ext_DisconnectMode, custom() As Variant)
          On Error Resume Next
          MsgBox "My Addin was disconnected by " & _
             IIf(RemoveMode = ext_dm_HostShutdown, _
             "Excel shutdown.", "end user.")
          
          MyButton.Delete
          Set MyButton = Nothing
          Set oXL = Nothing
        End Sub
    
       Private Sub MyButton_Click(ByVal Ctrl As Office.CommandBarButton, _
         CancelDefault As Boolean)
          MsgBox "Our CommandBar button was pressed!"
       End Sub
  8. ??? ??????? ?????? MyAddin.dll. ???? ????? ?????? ??????? ???????? ????? ???.
  9. ??? Microsoft Excel ???? ???? ???? ????? ??? ??????? ???????? ??? ????? ?? ????? ???????. ??? ???? ??????? ??????? ??? ????? ?? ???? ???? ??????? ???????? ?????? ??? ????? ??????? ??? ????? ?? ????.

????? ????? ???????? COM ???????? implements

????? ?? ???? ?? ???????, ????? ????? ??????? ???????? COM ???????? Microsoft Visual Basic 5.0 ? ?????? ???????? Implements ?????? ????? IDTExtensibility2 ??????. downside ??? ??? ??? ??????? ?? ???????. ??? ?? Microsoft Visual Basic ???? ????? ????? ?????? ?????? ??? ????? ??????? ???????? ?? Office, ??? ?????? ???? ???? ????? (?? ?????? ?????? ????? ???? ?? ??????? ?????? ??? REG).

??? ???? ???? ??????? Implements ?? ???? ??????? ????? ????? ?? ??????? ?????? ? ???? ??? ?????? ???? COM ????? ???? ????? ?? ??????? Office ?????? (????? ?? ????? ???? ????? ????? ??? ????? ??? ???? ????? ??).

???? ??? ??????? ?????? ?????? ????? - ?? ??????? Implements:
  1. ???? Visual Basic ?? ????? ????? ???? DLL ActiveX. ??? ??????? MyCOMAddin ???? ??????? ????? ???????.
  2. ?? ???? ?????? ????? (Project | ?????) ? ????? ???? ??? ????? ????? Microsoft ??????? ???????? ???? "?" ????? ?????? Microsoft Office 9.0 (?? 10.0 ?? Office XP). ??? ?? ????? ?? ?????? ??? "????" ??????? ???????? ?? ????? ????? ??? ????????? ????? ?? Msaddndr.dll ?? Msaddndr.tlb ????? ??????? ?? ?????? "Files\Designer Files\Common C:\Program".
  3. ?? ???? ????????? ???????? ?? ??????? ?????? ?? ???:
       Option Explicit
       Implements IDTExtensibility2
    
       Dim oHostApp As Object
       Dim WithEvents MyButton As Office.CommandBarButton
    
      Private Sub IDTExtensibility2_OnConnection(ByVal Application As Object, _
         ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, _
    
         ByVal AddInInst As Object, custom() As Variant)
      
          On Error Resume Next
        ' Set a reference to the host application...
          Set oHostApp = Application
       
        ' If you aren't in startup, then manually call OnStartupComplete...
          If (ConnectMode <> ext_cm_Startup) Then _
             Call IDTExtensibility2_OnStartupComplete(custom)
          
       End Sub
    
       Private Sub IDTExtensibility2_OnStartupComplete(custom() As Variant)
          Dim oCommandBars As Office.CommandBars
          Dim oStandardBar As Office.CommandBar
       
          On Error Resume Next
        ' Set up a custom button on the "Standard" commandbar...
          Set oCommandBars = oHostApp.CommandBars
          If oCommandBars Is Nothing Then
           ' Outlook has the CommandBars collection on the Explorer object
             Set oCommandBars = oHostApp.ActiveExplorer.CommandBars
          End If
       
          Set oStandardBar = oCommandBars.Item("Standard")
          If oStandardBar Is Nothing Then
           ' Access names it's main toolbar Database
    
             Set oStandardBar = oCommandBars.Item("Database")
          End If
       
        ' In case the button was not deleted, use the exiting one...
          Set MyButton = oStandardBar.Controls.Item("My Custom Button")
             If MyButton Is Nothing Then
    
                Set MyButton = oStandardBar.Controls.Add(1)
                With MyButton
                   .Caption = "My Custom Button"
                   .Style = msoButtonCaption
     
              ' The following items are optional, but recommended. 
              ' The Tag property lets you quickly find the control 
              ' and helps MSO keep track of it when there is more than
              ' one application window visible. The property is required
              ' by some Office applications and should be provided.
    
                .Tag = "My Custom Button"
     
              ' The OnAction property is optional but recommended. 
              ' It should be set to the ProgID of the add-in, such that if
              ' the add-in is not loaded when a user presses the button,
              ' MSO loads the add-in automatically and then raises
              ' the Click event for the add-in to handle. 
    
                   .OnAction = "!<MyCOMAddin.Connect>"
    
                   .Visible = True
                End With
             End If
     
        ' Display a simple message to know which application you started in...
          MsgBox "Started in " & oHostApp.Name & "."
    
          Set oStandardBar = Nothing
          Set oCommandBars = Nothing
       End Sub
    
       Private Sub IDTExtensibility2_OnDisconnection(ByVal RemoveMode As _
         AddInDesignerObjects.ext_DisconnectMode, custom() As Variant)
    
          On Error Resume Next
          If RemoveMode <> ext_dm_HostShutdown Then _
             Call IDTExtensibility2_OnBeginShutdown(custom)
          
          Set oHostApp = Nothing
    
       End Sub
    
       Private Sub IDTExtensibility2_OnBeginShutdown(custom() As Variant)
          On Error Resume Next
        ' Notify the user you are shutting down, and delete the button...
          MsgBox "Our custom Add-In is unloading."
          MyButton.Delete
          Set MyButton = Nothing
       End Sub
    
       Private Sub MyButton_Click(ByVal Ctrl As Office.CommandBarButton,    CancelDefault As Boolean)
          MsgBox "Our CommandBar button was pressed!"
       End Sub
    
       Private Sub IDTExtensibility2_OnAddInsUpdate(custom() As Variant)
          'You do nothing if this is called, but you need to
          'add a comment so Visual Basic properly implements the function...
       End Sub
  4. ??? ??????? ?????? MyCOMAddin.dll. ??? ???? ??? ??? ???? ??????? ???????? ??? ?? ????? ?? ????? Office ???? ???? ?? ????? ??. ?? ?????? ???????? ???? ????? ?????? ???? ?????? ???? ??? ????? DLL. ?????? ??? ??? ??????? ??? ??????? ???? ????? ?????? ?? IDE Visual Basic.
  5. ????? ???? ????? ????? ??? ???????. ?? ???????? ???????? ?????? ?????? ??????? 1 ?????? ?? ???:
       Option Explicit
    
       Private Declare Function RegCreateKeyEx Lib "advapi32.dll" _
       Alias "RegCreateKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, _
       ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions As _
       Long, ByVal samDesired As Long, ByVal lpSecurityAttributes As Long, _
       phkResult As Long, lpdwDisposition As Long) As Long
       
       Private Declare Function RegSetValueEx Lib "advapi32.dll" _
       Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As _
       String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, _
       ByVal cbData As Long) As Long
       
       Private Declare Function RegDeleteKey Lib "advapi32.dll" _
       Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) _
       As Long
       
       Private Declare Function RegCloseKey Lib "advapi32.dll" _
       (ByVal hKey As Long) As Long
    
       Private Const HKEY_CURRENT_USER = &H80000001
       Private Const KEY_ALL_ACCESS = &H1F0037
       Private Const REG_CREATED_NEW_KEY = &H1
       Private Const REG_SZ = 1
       Private Const REG_DWORD = 4
    
       'These are the settings for your Add-in...
       Private Const PROGID As String = "MyCOMAddin.Connect"
       Private Const DESCRIPTION As String = "My VB5/6 COM Add-In Sample"
       Private Const LOADBEHAVIOR As Long = 3
       Private Const SAFEFORCOMMANDLINE As Long = 0
    
    
       Public Sub RegisterAll()
          RegisterOfficeAddin "Access"
          RegisterOfficeAddin "Excel"
          RegisterOfficeAddin "FrontPage"
          RegisterOfficeAddin "Outlook"
          RegisterOfficeAddin "PowerPoint"
          RegisterOfficeAddin "Word"
       End Sub
    
       Public Sub UnregisterAll()
          UnRegisterOfficeAddin "Access"
          UnRegisterOfficeAddin "Excel"
          UnRegisterOfficeAddin "FrontPage"
          UnRegisterOfficeAddin "Outlook"
          UnRegisterOfficeAddin "PowerPoint"
          UnRegisterOfficeAddin "Word"
       End Sub
    
       Public Sub RegisterOfficeAddin(sTargetApp As String)
          Dim sRegKey As String
          Dim nRet As Long, dwTmp As Long
          Dim hKey As Long
       
          sRegKey = "Software\Microsoft\Office\" & sTargetApp _
             & "\Addins\" & PROGID
       
          nRet = RegCreateKeyEx(HKEY_CURRENT_USER, sRegKey, 0, _
             vbNullString, 0, KEY_ALL_ACCESS, 0, hKey, dwTmp)
          
          If nRet = 0 Then
             If dwTmp = REG_CREATED_NEW_KEY Then
                Call RegSetValueEx(hKey, "FriendlyName", 0, _
                   REG_SZ, ByVal PROGID, Len(PROGID))
                Call RegSetValueEx(hKey, "Description", 0, _
                   REG_SZ, ByVal DESCRIPTION, Len(DESCRIPTION))
                Call RegSetValueEx(hKey, "LoadBehavior", 0, _
                   REG_DWORD, LOADBEHAVIOR, 4)
                Call RegSetValueEx(hKey, "CommandLineSafe", 0, _
                   REG_DWORD, SAFEFORCOMMANDLINE, 4)
             End If
             Call RegCloseKey(hKey)
          End If
       
       End Sub
    
       Public Sub UnRegisterOfficeAddin(sTargetApp As String)
          Dim sRegKey As String
          sRegKey = "Software\Microsoft\Office\" & sTargetApp _
             & "\Addins\" & PROGID
       
           Call RegDeleteKey(HKEY_CURRENT_USER, sRegKey)
       
       End Sub
  6. ?? ???? ???? (??? | ?????? ??????) ? ???? RegisterAll ??? ?? ???? ENTER. ????? ??? ??????? ??????? ???????? ?? ???? ??????? Office ???????? (Access ? Excel ? FrontPage ? Outlook ? PowerPoint ? Word).
  7. ??? ?? ?? ??????? Office ??? ???. ???? ???? ????? ??? ??? ??????? "?" ????? ??????? "?" ?? ???? ????? ??? ???? ??????? ???????.
  8. ??? ??? ???? ?? ????? ????? ??????? ???????? ???? UnregisterAll ?? ?????? ?????? Visual Basic ??? ?? ???? ENTER.

?????

"Microsoft Office 2000 Visual Basic ????????? ????? ????" ? 11 ?????. ??????? ???????? ????? ? ??????? ? ??????.

?????? ??? ???? ?? ????????? ??? ????? ????? COM ???????? ???? ??? ????? ???????? ??????? ?????? ?? "????? ??????? ?? Microsoft:
230689?????: Comaddin.exe Office 2000 ????? COM ???????? ???????? ?? Visual C++
190253?? ???? ????? VB6 ?? VB5
?????? ??? ???? ?? ????????? ??? ????? ?????? ???????? ??? ??? ??????? Microsoft Internet Explorer? ?? ?????? ???? Microsoft ?????? ??? ?????:
http://msdn.microsoft.com/ie/
?????? ??? ????? ???? ????? ??? Office Word ?? ????? ???????? COM Visual Basic ???????? ??????? ??????? ?? ??? ??????? ?? ???????? ????? ??????, ???? ??????? ?? ???? ??? ?? ?????. ????? ?? ?????????? ???? ??? ??? ??????? ?????? ?????? ?? "????? ??????? ?? Microsoft:
313948Word ???? ???? ??? ????? ??????? ???? COM (CommandBarControl)

???????

???? ???????: 238228 - ????? ??? ??????: 05/????/1428 - ??????: 6.2
????? ???
  • Microsoft Excel 2000 Standard Edition
  • Microsoft Office XP Developer Edition
  • Microsoft Office 2000 Developer Edition
  • Microsoft Access 2002 Standard Edition
  • Microsoft Access 2000 Standard Edition
  • Microsoft Excel 2002 Standard Edition
  • Microsoft FrontPage 2002 Standard Edition
  • Microsoft FrontPage 2000 Standard Edition
  • Microsoft Outlook 2002 Standard Edition
  • Microsoft Outlook 2000
  • Microsoft PowerPoint 2002 Standard Edition
  • Microsoft PowerPoint 2000 Standard Edition
  • Microsoft Word 2002 Standard Edition
  • Microsoft Word 2000 Standard Edition
  • Microsoft Visual Basic 5.0 Professional Edition
  • Microsoft Visual Basic 6.0 Professional Edition
  • Microsoft Visual Basic 5.0 Enterprise Edition
  • Microsoft Visual Basic Enterprise Edition for Windows 6.0
????? ??????: 
kbmt kbautomation kbhowto KB238228 KbMtar
????? ????
???: ??? ????? ??? ?????? ???????? ?????? ????? ???? ????? ?????????? ????? ?? ????????? ?????? ????. ???? ???? ?????????? ???? ?? ???????? ???????? ?????? ????????? ????? ????????? ???????? ????? ???????? ?????? ?? ?????? ??? ?? ???????? ???????? ?? ????? ??????? ?????? ??? ??????? ?????? ??. ?????? ?? ???? ??? ??????? ???????? ????? ?? ???? ????? ?????? ??? ????? ??? ????? ??????? ?? ????? ?? ?????? ??? ??? ??????? ??????? ?? ????? ????? ????? ????? ?????. ?? ????? ???? ?????????? ??????? ??? ????? ?? ??????? ?? ????? ?????? ?? ??? ????? ?? ????? ??????? ?? ???????? ?? ??? ???????. ???? ???? ?????????? ???????? ??? ????? ?????? ??????? ??????
???? ??? ????? ??????? ?????? ??????????238228

????? ???????

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com