M
Markus Stoeger
Hello,
I have an unmanaged C++ class that contains a member function similar to this
one:
void MyUnmanagedClass::get_data(unsigned char **data, int *count) {
*count = 100;
*data = new unsigned char[100];
// ... put some data into data
}
How does the managed C++ wrapper function have to look like so that I can
call it like that from C#:
MyManagedClass x = new MyManagedClass();
byte[] data;
x.get_data(out data);
What I came up with so far is:
using namespace System;
void MyManagedClass::get_data(Byte (&data)[]) {
int count;
unsigned char *tmp;
unmanaged_class->get_data(&tmp, &count);
data = new Byte[count];
for (int i = 0; i < count; i++)
data = tmp;
delete tmp;
}
.... but that requires a x.get_data(ref data); in C#, what I want is
an "out" data because I'd like to prevent the error C# gives me if I don't
initialize the ref data to null.
I'm not sure if I've even followed the right track. Whats the right way to do
that?
thanks,
Max
I have an unmanaged C++ class that contains a member function similar to this
one:
void MyUnmanagedClass::get_data(unsigned char **data, int *count) {
*count = 100;
*data = new unsigned char[100];
// ... put some data into data
}
How does the managed C++ wrapper function have to look like so that I can
call it like that from C#:
MyManagedClass x = new MyManagedClass();
byte[] data;
x.get_data(out data);
What I came up with so far is:
using namespace System;
void MyManagedClass::get_data(Byte (&data)[]) {
int count;
unsigned char *tmp;
unmanaged_class->get_data(&tmp, &count);
data = new Byte[count];
for (int i = 0; i < count; i++)
data = tmp;
delete tmp;
}
.... but that requires a x.get_data(ref data); in C#, what I want is
an "out" data because I'd like to prevent the error C# gives me if I don't
initialize the ref data to null.
I'm not sure if I've even followed the right track. Whats the right way to do
that?
thanks,
Max