C#: marshalling a struct that contains arrays

前端 未结 3 1859
伪装坚强ぢ
伪装坚强ぢ 2021-01-02 21:25

I am doing some C# interop work. I have the following struct:

#pragma pack(push,1)
typedef struct
{
    unsigned __int64 Handle;
    LinkType_t Type;
    Lin         


        
3条回答
  •  梦毁少年i
    2021-01-02 21:36

    whenever I initialize the struct the Name, DeviceInfo, and Reserved fields are all set to null

    This is correct, and your definition looks OK to me (BTW, you don't need [MarshalAs] on the primitive fields, the default behaviour is to do what you specified there). Because your array fields are null, the marshaler won't do anything about them when marshaling your struct to unmanaged memory, but it's going to create the strings and arrays when unmarshaling.

提交回复
热议问题