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
The bytes() function returns a bytes object. It can convert objects into bytes objects, or create empty bytes object of the specified size. The difference between bytes() and bytearray() is that bytes() returns an object that cannot be modified, and bytearray() returns an object that can be modified.
In C, a byte array is considered an object, by C's definition of object: 3.15. 1 object. region of data storage in the execution environment, the contents of which can represent values. 2 NOTE When referenced, an object may be interpreted as having a particular type; see 6.3.
you can use the linq method: MyBytes. Reverse() as well as the Array. Reverse() method.
What is a Bytearray? A byte array is simply a collection of bytes. The bytearray() method returns a bytearray object, which is an array of the specified bytes. The bytearray class is a mutable array of numbers ranging from 0 to 256.
This is the way you declare a byte array in C++/CLI:
array<System::Byte>^
Google is your friend...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With