Programming implementation of internal COM plugins under office2000 (one)

zhaozj2021-02-08  216

Programming implementation of internal COM plug-ins in Office2000

Translation: Xu Jingzhou

Download sample source code (http://www.vchelp.net/itbookreview/view_paper.asp?paper_id=596)

Introduction

You may see the new custom toolbar buttons or menu bars added to other software added in the toolbar or menu strip resources of Word2000, Access2000, Excel2000, PowerPoint2000, etc. in Office2000. When you click on them, There is a different response. Below, let us also implement these functions, it needs to be explained, here we don't have to implement it, but use the ATL (active template library) in VC6 to develop office2000 internal COM with this effect. Plugin. In Office2000, whether it is Word2000, Access2000, Excel120000, PowerPoint2000 or Outlook2000, etc., their COM plug-in programming methods and steps are extremely similar (in addition to the registry "and importing the corresponding type of library).

Basic knowledge

COM add a lower internal Office2000 _IDTExtensibility2 must implement a distributed interfaces, interfaces are defined in the distribution _IDTExtensibility2 MSADDin Designer type library (MSADDNDR.dll / MSADDNDR.tlb) usually located at / Program Files / Common Files / Designer under. _IdTextensibility2 must implement the following five interfaces (generally need to write onConnection and ONDISCONNECTION), as follows:

1. ONCONNECTION: Load the plug-in to the memory (can be automatically loaded when the program is started by automation).

2. OnDisconnection: Processs when the plugin is loaded from the memory.

3. Onaddinsupdate: The COM plug-in is handled.

4. OnStartUpComplete: Processing when the plugin is just loaded when the application starts.

5. Onbeginshutdown: The plugin is complete when the plugin is complete when the application is turned off.

Registration plugin

Only when registering the internal COM plug-in that the appropriate application is registered correctly, it can be loaded by its application. You need to create the following key values ​​in the registry:

HKEY_CURRENT_USER / SOFTWARE / Microsoft / Office / / Addins /

Where theofficeApp represents the corresponding program name, such as: Word, Outlook, etc., ProgID indicates the string representation of the unique identifier of the internal COM plug-in, such as: Outlook2000Addin.Addin, etc.

The following four key values ​​are mainly created under the PROGID key value:

1. FriendlyName: String Type, the name of the plugin, will be seen in the COM Load dialog box of the corresponding program.

2. Description: String Type, Description Information of Plugin.

3. Loadbehavior: DWORD type, determine the plugin will be loaded in any form. When its value is 0x03, it is automatically loaded for the application (usually using this value), and when its value is 0x08, the load is controlled to activate the load.

4. CommandLinesAfe: DWORD type, command line mode, can be set to 0x01 (true) or 0x00 (fake).

The full description of other key values ​​can be found in the latest MSDN. Implementation

Below, we will use the internal COM plug-in to create an Outlook2000 as an example, to show you how to create a whole process of creating an Office2000 internal plug-in. The renderings are as follows:

Figure one

Open VC6.0, select the ATL COM AppWizard in the new project, enter OutLaddin in the right project name, click Next, accept the default option Dynamic Link Library (DLL) constant, you can select the following Allow Merging of proxy-stub code (Allow Merge Agent / Place) check box option, click Finish button to complete the project creation.

Next, select the menu INSERT-> New ATL OBJEC term, select the corresponding Objects corresponding to the right of Objects corresponding to the appropriate Objects in the pop-up, click Next, enter OutlookAddin in the pop-up dialog box, if needed You can also select the Support ISUPPORTERRORINFO checkbox option in Attributes (Properties Page), and point OK completes the insertion ATL object.

Then by importing the type library, the right click on the coutLookAddin class in the ClassView in the COTLOOKADDIN class in ClassView, and select the Implement Interface item in the pop-up. Click Add Typelib in the Pop-up Implementation Interface dialog box. In the pop-up Browse Type Libraries dialog box, scroll down the Microsoft Add-in Designer (1.0) sub-item, point OK button. Select the _idtextensibility2 interface in the pop-up list dialog, point the OK button to complete the import. The system will automatically generate the five required number of interfaces mentioned above.

Then register the compiled plugin, in FileView-> Resource Files, open the OutlookAddin.rgs registration file, in the bottom of the file, add the following new internal plug-in registration code:

// Add Outlook2k internal plugin registration key value

HKCU

{

Software

{

Microsoft

{

Office

{

Outlook

{

Addins

{

'Outladdin.OutlookAddin'

{

Val FriendlyName = S 'Outlook2000 Plugin'

Val description = s 'uses ATL development Outlook2000 plug-in'

Val loadbehavior = d '00000003'

Val CommandLinesAfe = D '00000000'

}

}

}

}

}

}

}

Compile this project, if the registration is correct, you can see its corresponding name in the plug-in dialog box in Outlook. Load or uninstall the COM plugin in Office2000, generally followed by:

1. If you have added the COM Add Item command to the Tools menu, jump to step 6.

2. Click the Custom command in the Tools menu and click the Commands tab.

3. In the Category box, select Tools.

4. Drag the "COM Add Item" from the Command box to the Tools menu. When the "Tool" menu displays the menu command, point the mouse pointer to the hope "COM Add Item" command appears on the menu, then release the mouse button.

5. Click the "Close" button. 6. Click the COM Add Item command in the Tools menu and do one of the following:

l To add a add-on, select the check box next to the load item name in the "Used Add Item" list. If the required add-on is not in the "User Add Item" list, click the Add button to find the add-on you want to add, and then click the "OK" button.

l To uninstall the add-on from memory, you want to keep your name in the list, clear the check box next to the load item name.

To delete the add-in list from the list, remove it from the list of load items registered from the registry file, select the name of the add-on, and then click the "Delete" button.

转载请注明原文地址:https://www.9cbs.com/read-2168.html

New Post(0)