Spark
Spark

Reputation: 672

How to return a byte[] to C# in C++ CLR

I'm using C++ CLR to wrap a native C++ dll. So that the C++ CLR dll can be accessed by a C# project.

The problem is that when I want to return a byte[] to C#, and write such code in CLR:

static System::Byte[]^ GetTestByteBuffer()
{
    System::Byte[]^ byte = gcnew System::Byte[128];
    return byte;
}

but it cannot pass compilation. Anyone can help me?

compilation error:

error C3409: empty attribute block is not allowed 
error C3409: empty attribute block is not allowed error C2146: syntax error "^": 
error C2334: unexpected token(s) preceding '{'; skipping apparent function

Upvotes: 14

Views: 15256

Answers (1)

Jeff
Jeff

Reputation: 1734

This is the way you declare a byte array in C++/CLI:

array<System::Byte>^

Google is your friend...

Upvotes: 32

Related Questions