how to marshal VARIANT* pArray(which pArray is array of IDynamicProperty objects)? RRS feed

  • Question

  • I have to marshal this interface in my C# code:
    IPropertySource : public
    STDMETHOD(GetProperties)(THIS_ /*[in]*/ IUnknown* pObject, /*[out,
    VARIANT *pPropertyArray) PURE;
    Here is the document of GetProperties():
    The pProperties array contains pointers to IDynamicProperty instances that
    describe additional properties of the object. If the property source object
    does not generate any dynamic properties, pProperties can be VT_EMPTY or an
    empty array.

    I wrapped in C# like this:
    [ComVisible(true )]
    public interface IPropertySource // cannot list any base interfaces here
    [return : MarshalAs(UnmanagedType.SafeArray,SafeArraySubType=VarEnum.VT_UNKNOWN)]
    Object[] GetProperties([In,MarshalAs(UnmanagedType.IUnknown)] Object pObject);
    but when  GetProperties() called by other module,the returned array didn't work.I have searched lots of docs,all about marshal Safearray ,but not doc about pointer to safearray.
    It most likely the pPropertyArray->pparray or pPropertyArray->parray (I'm not sure) pointed the Safearray of  IDynamicProperty,so pPropertyArray maybe created by VT_ARRAY | VT_BSTR.
    How to marshal this interface?
    Thanks for help!
    Thursday, November 26, 2009 2:19 AM

All replies

  • Since the return type is a VARIANT, not a SAFEARRAY, you should make the signature

    Object GetProperties([In,MarshalAs(UnmanagedType.IUnknown)] Object pObject);

    Mattias, C# MVP
    Tuesday, February 23, 2010 4:38 PM