我在C ++中有以下代码,我需要能够从C#调用:
struct Inner
{
double data1;
double data2;
};
struct Outer
{
double data3;
SAFEARRAY innerData;
};
int WINAPI ProcessData (Outer& outer )
{
...
}
我尝试了以下但是它没有用我做错了什么?
[StructLayoutAttribute(LayoutKind.Sequential)]
public struct Inner
{
public double data1;
public double data2;
}
[StructLayoutAttribute(LayoutKind.Sequential)]
public struct Outer
{
public double data3;
[MarshalAsAttribute(UnmanagedType.Safearray,ArraySubType = UnmanagedType.Struct)]
public Inner[] innerData;
}
答案 0 :(得分:1)
你试过这个吗?
[StructLayoutAttribute (LayoutKind.Sequential)]
public struct Outer
{
public double data3;
[MarshalAsAttribute (UnmanagedType.SafeArray, SafeArrayUserDefinedSubType=typeof(Inner))]
public Inner [] innerData;
}
答案 1 :(得分:0)
看起来好像属性声明不正确,因为它拒绝编译......
[StructLayoutAttribute(LayoutKind.Sequential)] public struct Outer { public double data3; [MarshalAsAttribute(UnmanagedType.SafeArray, SafeArraySubType=VarEnum.VT_SAFEARRAY)] public Inner[] innerData; }
希望这有帮助, 最好的祝福, 汤姆。