VSTO Expose Addin Object in Another Solution

时间:2016-04-15 11:14:06

标签: c# vsto

I have created One Add in for Outlook.and i want to Expose AddIn Functionality in Some Other solution in my case i want to access in Windows Application.

I use Below Code Outlook Addin

[ComVisible(true)]
public interface IOutlookUtilities
{
    void DoSomething();
}


public class AddInUtilities: StandardOleMarshalObject,IOutlookUtilities
{
    public void DoSomething()
    {
        System.Windows.Forms.MessageBox.Show("Outlook Add in Called");
    }

}

ThisAddIn Class:

    private AddInUtilities utilities;
    protected override object RequestComAddInAutomationService()
    {
        try
        {
            if (utilities == null)
            {
                utilities = new AddInUtilities();
            }
            return utilities;
        }
        catch (System.Exception ex)
        {
            // Catch your ex here
        }
        return null;
    }

Windows Application :

Outlook.Application outLook = new Outlook.Application();
object addinName = "OutlookAddIn3";
COMAddIn addin = outLook.COMAddIns.Item(ref addinName);
var utilities = (IOutlookUtilities)addin.Object;                                                                                                                                                                                                   
utilities.DoSomething();

I have also check Add in successfully register in Registry.and Addin Name. in Above Code utilities object is always null. can someone help

0 个答案:

没有答案