Correct syntax for a C++ component to return a structure to C# calling application RRS feed

  • Question

  • I'm building a C++ component which ref class members  will be called by a C# application.

    My problem is I want to return a structure of inrofmation, in which one information is a vector of structures.


    public value struct A
       int value;
       String^ text;
    public value struct Result
        int someValue;
        IVector<A>^ resultStructs;

    When Result would be the return of a member function.

    However the compiler rejects this as it seems impossible to put refs in a value struct, as far as I understand.

    What is the correct way to do this?

    Wednesday, June 27, 2012 1:39 PM


All replies

  • I guess your best option is to make Result a ref type.


    Wednesday, June 27, 2012 2:40 PM
  • Thanks. 

    Incidentally I spent the day converting all my input and output parameters structures to sealed public ref classes and adding setters and getters so they can be given as return to the C# calling application, as well as filled by the functions.

    I kept value structs for a few of them when they hold only elementary values, although I feel they'd benefit from going to the ref world, as copying a handle for return should be cheaper than copying a whole structure of values ...

    Too bad debugging with ref classes is so rough in Visual 2012RC.

    Thursday, June 28, 2012 9:43 AM