I’ve just joined the site, and this is my first posting here.
I could really do with some help calling an unmanaged DLL function from my C# application. I've been searching around, and have found various similar questions, but nothing which quite fits what I need.

The function I need to call is:

```
int DevConfig(struct A *a, int b, unsigned int c, BOOL *d);

```

Where A is defined as:

```
struct A
{
    double f[4];    
    unsigned int df[4];
    unsigned int dfn[4];
    double *dc[4];
    float dg[4];
    float g;
    UCHAR gs;
};

```

I’m getting a bit stuck and confused as to how to handle this in the C#. I think I need to do something like this, but I know it’s not quite right:

```
[StructLayout(LayoutKind.Sequential)]
public struct A
{
    public double[] f = new double[4];
    public uint[] df = new uint[4];
    public uint[] dfn = new uint[4];
    public double[,] dc = new uint[4,256];
    public float[] dg = new float[4];
    public float g;
    public byte gs;
}

[DllImport("DevControl.dll")]
static extern int DevConfig (ref A a, int b, uint c, bool[] d);

```

I think this is the correct approach, but I’m confused about the array of pointers to doubles (double \*dc[4]), and also the pointer to an array of Boolean (BOOL \*d).
Please could someone help me get this right?

**Edit with more info:**
In the case of this function, data flows from the C# to the DLL. That is, the C# allocates the memory.
I was thinking of specifing dc as follows, unless it's easier to do it another way:

```
double[,] dc = new double[4, 256];

```

The size of this array is always 4 x 256. Somehow I need to marshal this into the IntPtr[] field of the struct?

And for the bool array:

```
bool[] d = new bool[8];

```

The length of this array may vary, it is not necessarily always 8 (but the DLL knows how long it is via one of the other parameters passed in).