none
How to marshal a struct containing array of unknown size from managed to native RRS feed

  • Question

  • Hello,

    I am c++ person, and new to managed concepts. 

    I want to use System::Web::Script::Serialization:Javascriptserialiser class in C++ application. So need to marshal data from managed struct returned by serialiser into native struct.


    //managed class JSON class
    [Serializable]
    public value class B

    {

    public:
    System::Int32 i;

    array<System::Int32>^ data;

    }

    [Serializable]
    public value class B1

    {

    public:
    B b;

    }

    //The Structs I defined looks like this
    //Native
    struct A

    {

    int i;

    int data[]; //i donno size till runtime 

    }

    struct A1

    {

    A a;

    }

    Now I want to marshal struct B1 to A1 ( I think way of doing this is StructureToPtr()) and finally get A and access data. 
    Since I don't know size of array data till runtime,I am confused how should I declare my struct A?
     Even though I declare it like this and allocate memory runtime


    struct A

    {

    int i;

    int*data; 

    }

    Do I have to iteratively copy the data from B's data? or can I use StructureToptr() instead?

    Can Anyone help me how exactly should I marshal this?



    Thanks in advance!!


    Friday, July 5, 2013 12:16 PM