开发者

Marshalling pointer to an array in struct from c++ to c#

开发者 https://www.devze.com 2023-02-16 03:14 出处:网络
How do I convert this expression from C++ to C#? struct MyStruct { uint8_t *rcSource; uint8_t *rcMask; uint32_t *clientAuthSchemes;

How do I convert this expression from C++ to C#?

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

The structure is initialised in C++ this way:

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));


If those are 1-dimensional arrays, you probably want something like this:

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

Initialization:

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


I believe this is the way:

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

:)

0

精彩评论

暂无评论...
验证码 换一张
取 消