views:

228

answers:

1

I know only very little about C++/CLI, but I have a simple problem that needs a solution. I have a C++/CLI class method that takes a byte-array as a parameter. The array is of a pre-determined length, and can be allocated in C# beforehand. The array is supposed to be filled with data by the C++/CLI method.

How do I declare the method and then call it from C#?

I tried something like having the following in my C++/CLI class:

public ref class C
{
public:
    void FillBytes(array<BYTE^>^ bytes);
};

And then, in C#:

o = new C();
var bytes = new byte[3];
o.FillBytes(bytes);

But that didn't work at all :).

+5  A: 

Have you tried using byte instead of a BOOL reference?

void FillBytes(array<System::Byte>^ bytes);
                                ↑
                           //   no ^ here
dtb
Oops, I just typed in some simplified version of my actual code and made a typo. But the problem still remains. I get "Argument '1': cannot convert from 'byte[]' to 'System.ValueType[]'", when trying to compile the above code.
jco
There's still a superfluous `^` in your code.
dtb