locked
comaddin.Object does not work RRS feed

  • Question

  • I am trying to make two Excel addins talk. the 1st addin can be seen by the 2nd via app.COMAddins collection, and I verified that the addin instance has the right ProgId. however, the Object property yields <undefined value>, therefore, I can not call methods on that addin.

    what can I do to figure out what is wrong?

    Saturday, April 1, 2006 3:01 AM

Answers

  • The way it needs to be done is :

    your first add-in should initialize set the Object property to something. It can be done in IDTExtensibility2.OnConnection method. You will need to cast OnConnection's AddInInstance parameter to Office::COMAddin, then set the Object property.

    Then, when your 2nd add-in accesses COMAddins collection, it would access already initialized Object property.

    Sunday, April 2, 2006 6:35 AM
  • Sorry to disappoint - but that is not true.Think of a scenario when a COM Add-in does not want to expose itself to any external components - then it just does not set AddInInst.Object.

    The AddInInst.Object property can be set to any object the add-in wishes to set it to. But most commontly the code in IDTExtensibility2.OnConnection does just AddInInst.Object = me.

    Hope this helps.

    Monday, April 3, 2006 3:57 AM

All replies

  • The way it needs to be done is :

    your first add-in should initialize set the Object property to something. It can be done in IDTExtensibility2.OnConnection method. You will need to cast OnConnection's AddInInstance parameter to Office::COMAddin, then set the Object property.

    Then, when your 2nd add-in accesses COMAddins collection, it would access already initialized Object property.

    Sunday, April 2, 2006 6:35 AM
  • set the Object property to --What? anything you want?

    I was under the impression that the Object property automatically references the underlying object (meaning the COMAddin). is that not true?
    Sunday, April 2, 2006 6:06 PM
  • Sorry to disappoint - but that is not true.Think of a scenario when a COM Add-in does not want to expose itself to any external components - then it just does not set AddInInst.Object.

    The AddInInst.Object property can be set to any object the add-in wishes to set it to. But most commontly the code in IDTExtensibility2.OnConnection does just AddInInst.Object = me.

    Hope this helps.

    Monday, April 3, 2006 3:57 AM
  • I am able to set .object field but not able to use this thru any external program :( Can you point me to some example which exposes a class using .object and the .object class's function can be called from external code?? I have seen the example XML.Export.dll but thats not exposing any class, the .object property of this addin is always nothing.

    I have even tried changing the .connect = ture, but nothing seems to help. It would be really great if you could help me with some sample addin and a sample external code . A simple hello world type example will do.

    Thanks a ton,

    Vibhore

    Monday, April 3, 2006 3:34 PM
  • You are probably hitting marshalling problems - remember you are going to get a reference to your class through COM, so COM interop rules start applying.

    Registering a class that is defined as below should work.  Make sure you class is marked with ComVisible(true) and regasm'ed.

    public interface IMyInterface
    {
      void MyMehotd();
    }

     [ClassInterface(ClassInterfaceType.None)]
     [ComVisible(true)]
    public class MyClass : IMyInterface
    {
    }

    Monday, April 3, 2006 6:51 PM