Proof of concept for communication between COM addins within VSTO context
Microsoft Office Word has a Document_Save event. The calling order of subscribers is indeterminate. When addin X needs access before addin Y to the save event, simply subscribing to the event won't solve the problem as addin Y might be called first. A solution of this problem is to have addin Y subscribe to an event of addin X.
This proof of concept is written in VisualBasic.NET 10.0. For the C# version, check out https://github.com/generateui/ComAddinEvent.
Requirements:
- Visual Studio 2013
- VSTO april 2014 (newest at time of writing)
To debug:
- Open and run HasEvent. Word should start and you should see the add-in load.
- Close Word. The add-in HasEvent is still installed, and will load next time you run Word.
- Open ConsumeEvent
- Reference HasEvent.dll in ConsumeEvent. (References → Add reference → lookup HasEvent.dll, usually in HasEvent/bin/Debug)
- Run ConsumeEvent. Word should start and you should se HasEvent and ConsumeEvent load.
- Open or New a document, then attempt to save it. You should get a messagebox.
Remarks:
- This does not work with .NET 3.5 (runtime version 2.0).
- Tested on VSTO runtime versions
- 10.0.30319 (october 2010)
- 10.0.50701 (april 2014)
- This works regardles of the language HasEvent and ConsumeEvent are written in. Both can be VB.NET, C#, or any combination