gpt4 book ai didi

c++ - 在结构内部编码结构的安全阵列

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:20:17 24 4
gpt4 key购买 nike

我在 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;
}

最佳答案

你试过吗?

  [StructLayoutAttribute (LayoutKind.Sequential)]
public struct Outer
{
public double data3;
[MarshalAsAttribute (UnmanagedType.SafeArray, SafeArrayUserDefinedSubType=typeof(Inner))]
public Inner [] innerData;
}

关于c++ - 在结构内部编码结构的安全阵列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2233766/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com