I am trying to interface some C/C++ code from C# via a dll. I am not a fluent C/C++ programmer but use C# all the time. I am attempting to deal with these C/C++ types at the moment:
#ifndef struct_emxArray_char_T_1024
#define struct_emxArray_char_T_1024
struct emxArray_char_T_1024
{
char_T data[1024];
int32_T size[1];
};
#ifndef typedef_e_struct_T
#define typedef_e_struct_T
typedef struct
{
emxArray_char_T_1024 value1;
real_T value2;
uint32_T value3;
boolean_T value4;
} e_struct_T;
They were created by a third party tool. My unsuccessful C/C++ attempt to initialize value1 is as follows:
static char_T test[5] = { 'h', 'e', 'l', 'l', 'o'};
emxArray_char_T_1024 x;
x.data = test;
x.size = 5;
e_struct_T Parameters;
Parameters.value1 = x;
Parameters.value2 = 50;
Parameters.value3 = 3;
Parameters.value4 = FALSE;
I would like to ultimately expose a C# interface which takes the values:
PerformCPlusPlusComputation(string value1, double value2, int value3, bool value)
which initializes e_struct_T in C/C++. Any feedback would be very much appreciated. Thanks!
The lines
contains two errors: The first is that you can’t assign one array to another, not even if they were the same size. Use e.g.
std::copyto copy from one to the other.The other error is that the
sizemember is an array as well, and you can’t assign a single value to an array. You have to assign tox.size[0].Correct lines could look like this: