So I finally found someone who could help me :

So now I can actually pass a managed array as parameter for the method:

// packer.i
typedef struct {
  int width;
  int height;
  frame_t view;
  frame_t dest;
} 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);


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


But I still have a protected memory access problem. Actually, in the the image_t structure, the frame_t view and frame_t dest are output properties, but I'm guessing the wrapper uses them as read-only.

How can I tell SWIG that the unmanaged DLL can modify the two frame_t members of the image_t structure ?

Thanks !

2014-06-30 14:48 GMT+02:00 ThomasB <>:
I'm using SWIG 3 to generate a C# wrapper around a C library called "packer".

My packer.h looks like this (simplified) :

typedef struct {
        int width;
        int height;
        frame_t view;
        frame_t dest;
} image_t;
int pack(image_t *images, int nb_images, parameters_t params);

I have tried with a "naïve" packer.i file:

%module packer_cs
%include "carrays.i"
    #include "packer.h"
%array_class(image_t, image_t_array);
%include "packer.h"

It generates a C# method like this:

  public static int pack(image_t images, int nb_images, parameters_t arg2) {
    int ret = packer_csPINVOKE.pack(image_t.getCPtr(images), nb_images,
    if (packer_csPINVOKE.SWIGPendingException.Pending) throw
    return ret;

That I use like this (C#):

// images is a List<image_t>
var images_array = new image_t_array(images.Count);
for (var i = 0; i < images.Count; i++)
        images_array.setitem(i, images[i]);
var result = packer_cs.pack(images_array.cast(), images.Count, param);

Two questions:

* The last line throws an AccessViolationException (trying to read or write
from/to protected memory). Any idea why, or how I can debug it?

* This looks unnatural to me (and the library wrapper might be used by,
let's say, not-top-notch developers). I would rather pass a C# array of
image_t to my method. I've tried adding %apply image_t INPUT[] { image_t
*images } to my packer.i file, but now SWIG tells me : "Warning 453: Can't
apply (image_t INPUT[]). No typemaps are defined." I have a very hard time
finding proper documentation for this thing. Any help ?

Thank you!

View this message in context:
Sent from the swig-user mailing list archive at

Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
Swig-user mailing list