locked
Is there a way to communicate between Word Document Addin & Word COM Addin in VSTO? RRS feed

  • Question

  • I have Word Document Addin in VSTO 2005, but I need to add some items to MS Word menu. I'm going to use Word COM Addin to add menu items, but it's going to be separate app. I'm not sure how can I notify Word Document Addin when state changed in COM Addin. What is the best way to do that? Does Word provide any functionality to solve this problem?
    Wednesday, December 20, 2006 2:08 AM

Answers

  • <<By the way, I'm going to implement Ribbon support for Word 2007 for my project later. Do you know if I'll be able to do the same trick (Create Ribbon in COM Addin and then subscribe on OnClick event from Document project)?>>

    No, that won't work because the Ribbon is based on an XML model that uses a callback system. In the XML element for a Ribbon control there's an onAction attribute containing the name of the (public void) procedure associated with the control.

    For this scenario it would probably make more sense to put the "working code" in a separate DLL, in the GAC, that both project assemblies refer to. If you do that, I think you can subscribe to events it fires from both projects.

    Hmmm... Another possibility would be to leave the CommandBars in the original project, but make them all invisible and disabled. The callback procedure could then enable the associated button, call the button's Execute method, which should trigger the event. Complicated, but probably do-able.

    Friday, December 29, 2006 8:27 AM

All replies

  • It's not clear what you mean by "Word Document Addin". Do you mean a document-level VSTO project?

    It's also not clear what you mean by "state changed in the COM Addin", so it's not really possible to try to answer your question. You need to provide more information.

    Tuesday, December 26, 2006 6:15 PM
  • Sorry, that I wasn't clear.

    >>It's not clear what you mean by "Word Document Addin". Do you mean a document-level VSTO project?

    If you have VSTO 2005 SE, you can see it on New Project Dialog under "Visual C#" > Office  and it called  "Word Document" project.

     

     

    >>It's also not clear what you mean by "state changed in the COM Addin",

    >>so it's not really possible to try to answer your question. You need to provide more information.

    Bassically, I just want to communicate between those 2 addins. So for example if in COM Addin for Word I create menu, then when you click on any buttons in this menu I want to notify "Word Document" about this event.

    Wednesday, December 27, 2006 11:04 PM
  • Hmmm. Unless you use Remoting, there's no way the two DLLs can communicate with one another - each runs in its own AppDomain. If you search "Remoting" in this forum you should turn up a discussion or two with information on how this can be done.

    That said, if all you want to do is to react to a commandbar button being executed, you should be able to add an "OnClick" event handler for the button, even if  it wasn't created by the code attached to the Document project. This assumes, of course, that the COM Add-in has loaded its toolbar before you try to make the connection. You can check the Connect property of  COMAddin object and set it to True if it's not yet loaded.

    Thursday, December 28, 2006 8:21 AM
  •  Cindy Meister wrote:

    Hmmm. Unless you use Remoting, there's no way the two DLLs can communicate with one another - each runs in its own AppDomain. If you search "Remoting" in this forum you should turn up a discussion or two with information on how this can be done.

    Yes, I thought about Remoting, but I hoped that there can be easier way to communicate since they're both under Word proccess.

     Cindy Meister wrote:

    That said, if all you want to do is to react to a commandbar button being executed, you should be able to add an "OnClick" event handler for the button, even if  it wasn't created by the code attached to the Document project. This assumes, of course, that the COM Add-in has loaded its toolbar before you try to make the connection. You can check the Connect property of  COMAddin object and set it to True if it's not yet loaded.

    Wow. It sounds like great idea. I'll try to do that and let you know how it works. By the way, I'm going to implement Ribbon support for Word 2007 for my project later. Do you know if I'll be able to do the same trick (Create Ribbon in COM Addin and then subscribe on OnClick event from Document project)?

    Thanks a lot for your help

    Thursday, December 28, 2006 9:29 AM
  • <<By the way, I'm going to implement Ribbon support for Word 2007 for my project later. Do you know if I'll be able to do the same trick (Create Ribbon in COM Addin and then subscribe on OnClick event from Document project)?>>

    No, that won't work because the Ribbon is based on an XML model that uses a callback system. In the XML element for a Ribbon control there's an onAction attribute containing the name of the (public void) procedure associated with the control.

    For this scenario it would probably make more sense to put the "working code" in a separate DLL, in the GAC, that both project assemblies refer to. If you do that, I think you can subscribe to events it fires from both projects.

    Hmmm... Another possibility would be to leave the CommandBars in the original project, but make them all invisible and disabled. The callback procedure could then enable the associated button, call the button's Execute method, which should trigger the event. Complicated, but probably do-able.

    Friday, December 29, 2006 8:27 AM