Csharp calling C++ Managed code using Byte array reference

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Trev

    #1

    Csharp calling C++ Managed code using Byte array reference

    I can call C++ methods using byte arrays as values but I wish to call a C++
    method using a reference to an empty byte array that is then initiaised to a
    set size by the c++ method and populated within the c++ mthod before
    returning back to the c# code.

    E.g.

    c# call

    byte[] data;
    cpp_method.getD ata(ref data);

    c++ method signature

    int getData (System::Byte __gc * __gc * byteArray __gc[])

    However this is not allowed.

    Can anybody help me in how I need to call a C++ managed method passing a
    reference to a byte array that is going to be initialised in the c++ layer.

    Thanks

  • Willy Denoyette [MVP]

    #2
    Re: Csharp calling C++ Managed code using Byte array reference

    Try this:

    // CLS compliant function taking a REF array
    void GetArray( System::Byte (*bArray) __gc[])
    {
    *bArray = new System::Byte[123];
    }

    Willy.

    "Trev" <Trev@discussio ns.microsoft.co m> wrote in message
    news:FFB03AC3-3535-46F6-816F-9EFF77ADD15E@mi crosoft.com...[color=blue]
    >I can call C++ methods using byte arrays as values but I wish to call a C++
    > method using a reference to an empty byte array that is then initiaised to
    > a
    > set size by the c++ method and populated within the c++ mthod before
    > returning back to the c# code.
    >
    > E.g.
    >
    > c# call
    >
    > byte[] data;
    > cpp_method.getD ata(ref data);
    >
    > c++ method signature
    >
    > int getData (System::Byte __gc * __gc * byteArray __gc[])
    >
    > However this is not allowed.
    >
    > Can anybody help me in how I need to call a C++ managed method passing a
    > reference to a byte array that is going to be initialised in the c++
    > layer.
    >
    > Thanks
    >[/color]


    Comment

    Working...