returning safearray of idispatch pointers as variant

Latest post 06-20-2008 9:55 AM by Gary. 4 replies.
  • 06-19-2008 8:18 AM

    • rahulr
    • Top 100 Contributor
    • Joined on 06-05-2008
    • Posts 2

    returning safearray of idispatch pointers as variant

    Hi,

    I have a function

    STDMETHODIMP CTestComponent::func3(VARIANT* objects)

    in my host which is supposed to return an array of IDispatch pointers as a SAFEARRAY

    In the proxy the function becomes

    void func3(out object dllcomps);

    I can return an array of BSTR values but not IDispatch* , get a ArgumentException

    Should that be possible?

    regards

    rahul

  • 06-19-2008 9:02 AM In reply to

    • Gary
    • Top 10 Contributor
    • Joined on 07-13-2006
    • Posts 320

    Re: returning safearray of idispatch pointers as variant

    Are you using ProxyGen for VSTA 1.0?
  • 06-19-2008 1:09 PM In reply to

    • Gary
    • Top 10 Contributor
    • Joined on 07-13-2006
    • Posts 320

    Re: returning safearray of idispatch pointers as variant

    As documented in Thomas Quinn's blog arrays are passed as value by default.  In your particular case, IDispatch* is a reference type.  Proxygen will not pass IDispatch* parameters because it violates the transitive closure of types; that is, types that cross from host to add-in and vice versa must be well-defined.  This provides security for the host application.

    It is possible to work around this issue with a custom contract or a simplified approach to the proxy layer.  But if you can pass an array of values, that is the simplest solution.

     

  • 06-20-2008 9:48 AM In reply to

    • rahulr
    • Top 100 Contributor
    • Joined on 06-05-2008
    • Posts 2

    Re: returning safearray of idispatch pointers as variant

    Thanks, Gary.

    However, I am able to return a single IDispatch* successfully.

    STDMETHODIMP CTestComponent::func2(IDispatch** pD)  which maps as  public object func2()

    Is that difference expected as well? ( array of idispatch is failing but single idispatch succeeds)

    If what u say is true -- "types that cross from host to add-in and vice versa must be well-defined..." then whether the data is in an array or not, should it matter?

    I may be totally wrong here, please correct me if so..

    regards

    rahul

  • 06-20-2008 9:55 AM In reply to

    • Gary
    • Top 10 Contributor
    • Joined on 07-13-2006
    • Posts 320

    Re: returning safearray of idispatch pointers as variant

    Which version of ProxyGen are you using for func2(IDispatch** pD)?

    I will have to confirm, but I'm pretty sure that Array elements are only passed by value with both ProxyGen v1 and v2

Page 1 of 1 (5 items) | RSS
Copyright Summit Software Company, 2008. All rights reserved.