Pointer to a structure that has a fixed array of another structure

I am trying to write C # bindings for a native DLL. DLL structures are defined as

typedef struct Foo {
    Bar bars[32];
} Foo;

and

typedef struct Bar {
    uint32_t data;
} Bar;

and functions

void Baz(Foo* foo);

Ideally, I would like to define C # structures as

public unsafe struct Foo {
    public unsafe fixed Bar bars[32]
}

and

public struct Bar {
    public uint data;
}

and function as

public unsafe void BazDelegate(Foo* foo);

This will allow me to use pointers to manage structures. However, this is not allowed since fixed arrays can only be used for primitive types, so I cannot have a fixed array of the second type. The API requires that the first type be passed through a pointer to a specific function.

, , - , Bar[] . , " . ref.

[DllImport]. Marshal.GetDelegateForFunctionPointer. [MarshalAs(UnmanagedType.ByValArray)], ref Foo Foo*?

, Marshal.GetDelegateForFunctionPointer P/Invoke? , [DllImport]? , ref?

+4

Source: https://habr.com/ru/post/1650360/


All Articles