I have the following C# code with a structure definition (CInput), obj definition and init, and a call to a C++ (native) DLL function (that has also been written by me).
//C# code
public struct CInput
{
[MarshalAsAttribute(UnmanagedType.R8)]
public double Time;
[MarshalAs(UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_R8)]
public double[] Database;
/* other similar fields*/
}
CInput Inputs = new CInput();
/* init of Inputs fields*/
int bfr = Example(ref Inputs); // Example being the C++ DLL call
Messagebox.Show(bfr.ToString());
第二个参数瓦解有错误,我不知道什么地方。 然后:
//C++ code
struct CInput {
double Time;
double Database[3650];
/*etc*/
}
int Example(CInput& ObjIn) {
return ObjIn.Database[0]; // just an example
}
如果我不小心,在数据库中只注明“SafeArray”,我就会在阅读/书写记忆中出现错误,很可能是腐败的。
if "Database" was marshaled as ByValArray everything is fine, the values show up correctly. Unfortunately I get an internal size exception because I have many arrays of that size, therefore I have to go for pointers - but anything with "SizeArray" will bring the following results (with the code just posted):
(C++):
Database[0] = **0**
Database[1..etc] = values of the next parameters in the struct marshaled with ByValArray.
我认为,我应该提到,我需要从C#到C++的同样结构,我不想看任何问题。 So Array in a Struct >>> Array in a Struct.
<>ANY>/strong> 这方面的见解将具有巨大价值。 我一直在寻找时间,我还没有解决办法。
很多人预先表示感谢。