locked
pass byte array to between csharp and c++

    Question

  • Below is my c++ class, a wrapper to send buffer

    void TestSocket::Send(BYTE *mybuf)
    {
        ...

        localBuffer = mybuf;

       DoSend(localBuffer);

      ...

    }

    In csharp code as follows.

        byte[] content = new byte[1024];
        mySocket.Send(content );

    But it canot work. what's my wrong?

    Help needed.

    Thursday, February 16, 2012 10:16 AM

Answers

  • Hi,

    Your error is caused by incorrect method signature.

    Please re-define Send method in TestSocket class as follows.

    void TestSocket::Send(array<unsigned char>^ buff)

    Then you can define byte array in C# and pass it to C++ WinRT.

    For unsigned char in C++, equivalent data type in C# is byte. The underlying WinRT data type is Byte.

    Please refer to Windows Runtime base data types to learn data type mapping.


    Best wishes,


    Robin [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, February 16, 2012 12:36 PM
    Moderator

All replies

  • Hi,

    Your error is caused by incorrect method signature.

    Please re-define Send method in TestSocket class as follows.

    void TestSocket::Send(array<unsigned char>^ buff)

    Then you can define byte array in C# and pass it to C++ WinRT.

    For unsigned char in C++, equivalent data type in C# is byte. The underlying WinRT data type is Byte.

    Please refer to Windows Runtime base data types to learn data type mapping.


    Best wishes,


    Robin [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, February 16, 2012 12:36 PM
    Moderator
  • hi

      it canot work.error:too few arguments for class template "std::array"

    Wednesday, April 18, 2012 11:17 AM