Search code examples
c#visual-studiooutlookvstooutlook-addin

Outlook Add In interact with VB Windows Form App


I'm trying to create an outlook add in where I rightclick on a mail and a special popup menu pops out that interacts with a VB Windows Form App that I also created on Visual studio.

Can anyone please guide me on a few methods that allow me to make such interaction possible?

Thanks


Solution

  • Your VSTO add-in can be treated as a regular .net based application. So, you can use standard .net tools to communicate between two separate applications - your VSTO add-in and Windows Forms application.

    If you have an existing WinForms application then I assume you are not using .NET 5 so you can use Windows Communication Foundation (WCF). If you are using .NET 5 or above for WinForms then you cannot use WCF; gRPC is the alternative and it does not work for .Net prior to .Net 5. WCF has been designed as a high-level interface to most options for communications among applications.

    If you do not want a client and server then that would be what is called Peer-to-Peer Networking.

    After choosing the technology to communicate between two applications you can grab the currently selected item by using ribbon callbacks. Typically the onAction callback for button controls has the following signature:

    C#: void OnAction(IRibbonControl control)
    VBA: Sub OnAction(control As IRibbonControl)
    C++: HRESULT OnAction([in] IRibbonControl *pControl)
    Visual Basic: Sub OnAction(control As IRibbonControl)
    

    You can use the IRibbonControl instance passed as a parameter to get the Context property value which represents the active window containing the Ribbon user interface that triggers a callback procedure. After that you can get the Selection object and process the selected item clicked.