编组指向struct中从c ++到c#的数组的指针

时间:2011-03-11 20:47:54

标签: c# arrays marshalling

如何将此表达式从C ++转换为C#?

struct MyStruct    
{  
    uint8_t *rcSource;
    uint8_t *rcMask;  
    uint32_t *clientAuthSchemes;  
}

结构以C ++方式初始化:

MyStruct st;
st.rcSource = (uint8_t*) malloc(width*height);
st.rcMask = (uint8_t*) malloc(width*height);
st.clientAuthSchemes = (uint32_t*) malloc(sizeof(uint32_t)*(size+1));

2 个答案:

答案 0 :(得分:0)

如果这些是一维数组,你可能想要这样的东西:

struct MyStruct    
{  
    public byte[] rcSource;
    public byte[] rcMask;  
    public uint[] clientAuthSchemes;  
}

初​​始化:

MyStruct st;
st.rcSource = new byte[width*height];
st.rcMask   = new byte[width*height];
st.clientAuthSchemes = new uint[size+1];

答案 1 :(得分:-2)

我相信这就是方法:

struct MyStruct
{
   sbyte rcSource, rcMask;
   int clientAuthSchemes;
}

:)