I have a C library, with a pack() function. The SWIG file looks like this:

// packer.i
typedef struct {
  int width; // input
  int height; // input
  frame_t view; // output
  frame_t dest; // output
} image_t;

CSHARP_ARRAYS(image_t, image_t)
%apply image_t INOUT[] { image_t *images }

int pack(image_t *images, int nb_images, parameters_t params);

Which generates a function with this signature:

// packer_cs.cs
public static int pack(image_t[] images, int nb_images, parameters_t arg2)

And I call it like this:

// Program.cs
var files = Directory.GetFiles("./images");
var images = new image_t[files.Length];
for (var f = 0; f < files.Length; f++)
using (var imgInfo = Image.FromFile(files[f]))
var imgStruct = new image_t()
width = imgInfo.Width,
height = imgInfo.Height,
dest = new frame_t(),
view = new frame_t()
images[f] = imgStruct;
var result = packer_cs.pack(images, images.Length, new parameters_t());

I have found a way to debug into the C code. If I add a breakpoint at the top of the pack() C method, I can see that the parameters "nb_images" and "params" have the right values, but in the "images" array, the widths and heights have very weird values ; they even can be 0 or negative, even though none are if I inspect/watch my variables in the C#.

So, the base problem is: why isn't the wrapper passing the correct values to the C ?

Thanks !