views:

226

answers:

0

I have asked a similar question somewhere else, but I still cannot find a good answer (see http://stackoverflow.com/questions/2479764/swig-c-to-c-pointer-to-pointer-marshalling ). First answer did comment on typemap, but actual error message (yes, it is a memory issue, but it is because P/Invoke is not marshalling properly)

I'm currently trying to solve a few marshalling problems, which I don't believe to be unique to my API.

So, typical situation. I have a massive API in C++ and we want to create C# bindings, so we turn to SWIG. Everything works fine, except the following cases:

Example generic objects (classes are examples, so no need to comment of actual design)

class Foo
{
   double x, y, z;
};

class FooUserClass
{
public:
   // Other code here
   // ....
   //
   void FillInArray(int iNum, Foo** ioFooArray);
   void FillInArray(FooClass* ioFooArray[3]);
   void GetAllCoordPts( int iPts[][3] );
   double * GetCoords();
};
  1. Function takes arrays of objects:

    void FillInArray(int iNum, Foo** ioFooArray);

  2. Function takes an fixed-size array of objects: (similar to above)

    void FillInArray(Foo* ioFooArray[3]);

  3. Function takes a multi-dimensional array (either of primitives or custom types):

    void GetAllCoordPts( int iPts[][3] );

  4. Function returns a pointer (heap-allocated) (apparently %newobject would've helped there):

    double * GetCoords();

So, any help on how to %typemap those calls would be greatly appreciated.