问题
I am implementing COM Add-In for Outlook. I use IDTExtensibility2. I am not sure whether this is the best way of doing COM Add-Ins but I cannot change that.
This interface defines five methods: OnConnection, OnStartupComplete, OnAddInsUpdate, OnBeginShutdown, OnDisconnection.
I need to perform the following operations:
- Load configuration data from file
- Load registry data
- Start new session
- Create *.pst file
- Subscribe to Explorer events
- Connect to Internet Server to get some data
- Create menu items in the main menu
- Create a toolbar
- Add/Remove several things in Outllok (on *.pst files level)
Please advise, what I am supposed to do when?
- What I need to perform in OnConnection method?
- What is allowed only when OnStartupComplete invokes?
- What resources I need to free dispose during OnBeginShutdown / OnDisconnection?
回答1:
Note that 1,2 and 6 are not Outlook-addin-specific tasks.
3 is not needed: As an addin you don't create a session - you get connected with an existing one (by implementing the OnConnection
method).
For 4 and 9 I recommend using RDO: http://dimastr.com/redemption/ (can also be used for 3 if you really need another session)
For 5,7 and 8 I recommend using ADX: http://www.add-in-express.com/add-in-net/
(you won't actually have to worry about IDTExtensibility2
at all anymore if you do this)
OnConnection
is where you grab your reference to the Application
interface from which you can derive everything else.
OnStartupComplete
is where you can put all your initialization code.
OnDisconnection
is where you should release all remaining OOM references you may have accumulated during the session, i.e everything that was derived from the initial Application
reference that you received via OnConnection
.
来源:https://stackoverflow.com/questions/387277/how-it-is-correctly-to-implement-idtextensibility2-interface-for-office-com-add