0

I am exposing this C++/CLI property to COM and COM can only accept a reference type property for complex types (it won't accept a pointer property). What is the best way to expose a class' private member to be used with a reference property? I tried the following (and both don't work because I am missing a pointer to reference or vice versa conversion somewhere):

private:
    Object _myProp;
public:
property Object %MyProp { 
    virtual Object %get() 
    {
        return _myProp;
    }
    virtual void set(Object %value) 
    {
        _myProp = value;  // this line doesn't work
    }
};

And I tried this:

private:
    Object ^_myProp;
public:
property Object %MyProp { 
    virtual Object %get() 
    {
        return _myProp;   // this line doesn't work
    }
    virtual void set(Object %value) 
    {
        _myProp = %value;
    }
};

What am I doing wrong here (given that I have to use a reference property)?

Adam
  • 3,872
  • 6
  • 36
  • 66
  • Hard to guess what you mean by "reference property". Replace % by ^, Object is already a reference type. – Hans Passant Nov 28 '12 at 20:26
  • Hans, that doesn't work with COM. http://stackoverflow.com/questions/12976506/c-sharp-property-exposed-to-vba-com-run-time-error-424-object-required. It has to be a reference property, a pointer one doesn't work. – Adam Nov 28 '12 at 20:54
  • That doesn't work on a property. This problem is described here: http://stackoverflow.com/a/9924325/17034 – Hans Passant Nov 28 '12 at 21:03
  • In C# I wasn't able to make it work and I did spend few days on this particular issue. In C++/CLI it works and I was able to SET the property, however, my question here is how to enable both setting and getting from a reference property. – Adam Nov 28 '12 at 23:09

1 Answers1

0

I was trying to use "^" to return _myProp, I discovered that I should be using "*"

private:
    Object ^_myProp;
public:
property Object %MyProp { 
    virtual Object %get() 
    {
        return *_myProp;   // this line NOW works
    }
    virtual void set(Object %value) 
    {
        _myProp = %value;
    }
};
Adam
  • 3,872
  • 6
  • 36
  • 66