I have a struct in C#-project and C++-project. I use the struct in C# but it
has to be filled in C++.
I know that arrays work like this:
In C++ code:
struct teststruct {
char str[100];
float myvar[2];
};
CPPPROJECTDLLDE CL int DLLCALL callteststruct( teststruct *data) {
strcpy(data->str, "hello");
data->myvar[0] = 123.45f;
data->myvar[1] = 543.21f;
return 0;
}
In C# code:
using System.Runtime. InteropServices ;
[Serializable()]
[StructLayout(La youtKind.Sequen tial, Pack=1, CharSet=CharSet .Ansi)]
public struct teststruct {
[MarshalAs(Unman agedType.ByValT Str, SizeConst=100)]
public string str;
[MarshalAs(Unman agedType.ByValA rray, SizeConst=2)]
public float[] myvar;
};
[DllImport("CppP roject.dll")]
static public extern unsafe int callteststruct( ref teststruct data);
private void Page_Load(objec t sender, System.EventArg s e)
{
teststruct data = new teststruct();
callteststruct( ref data);
}
Now I need to add a structure array inside the "teststruct ". It should look
something like this in C++:
struct teststruct2 {
int intvalue;
int anotherintvalue
char text[100];
}
struct teststruct {
char str[100];
float myvar[2];
teststruct2 teststruct2arra y[100];
};
But how to do it in C#?
I really would appreciate some help.
Thanks.
Mikko
has to be filled in C++.
I know that arrays work like this:
In C++ code:
struct teststruct {
char str[100];
float myvar[2];
};
CPPPROJECTDLLDE CL int DLLCALL callteststruct( teststruct *data) {
strcpy(data->str, "hello");
data->myvar[0] = 123.45f;
data->myvar[1] = 543.21f;
return 0;
}
In C# code:
using System.Runtime. InteropServices ;
[Serializable()]
[StructLayout(La youtKind.Sequen tial, Pack=1, CharSet=CharSet .Ansi)]
public struct teststruct {
[MarshalAs(Unman agedType.ByValT Str, SizeConst=100)]
public string str;
[MarshalAs(Unman agedType.ByValA rray, SizeConst=2)]
public float[] myvar;
};
[DllImport("CppP roject.dll")]
static public extern unsafe int callteststruct( ref teststruct data);
private void Page_Load(objec t sender, System.EventArg s e)
{
teststruct data = new teststruct();
callteststruct( ref data);
}
Now I need to add a structure array inside the "teststruct ". It should look
something like this in C++:
struct teststruct2 {
int intvalue;
int anotherintvalue
char text[100];
}
struct teststruct {
char str[100];
float myvar[2];
teststruct2 teststruct2arra y[100];
};
But how to do it in C#?
I really would appreciate some help.
Thanks.
Mikko
Comment