From: Mathieu M. <mat...@gm...> - 2008-11-10 10:53:17
|
Hi Antti, On Mon, Nov 10, 2008 at 8:17 AM, Antti Karanta <ant...@na...> wrote: > > On Mon, 10 Nov 2008 00:44:49 +0200, Mathieu Malaterre > <mat...@xx...> wrote: > >> So my question is simply: how do I express I want byte[] instead of >> string here ? > > In the current release I think you have to write your own typemaps as > there is no builtin array support. > > > In the swig version in cvs head there is support for c# arrays and there > I believe e.g. this would work: > > %apply byte OUTPUT[] { char* buffer } ; > > If you don't want to wait for the next swig release (I have no idea when > it's coming out), you can just grab > > http://swig.svn.sourceforge.net/viewvc/swig/trunk/Lib/csharp/arrays_csharp.i > > The documentation should be at > > http://swig.svn.sourceforge.net/viewvc/swig/trunk/Doc/Manual/CSharp.html > > but it seems William has is yet to check it in. Anyhow, there should be > sufficient info in arrays_csharp.i file to get you going. > > > Please note that you can't use the FIXED array typemaps w/ the current > swig release as they require the "terminator" typemap attribute that is > only present in the svn head version. Alright. I tried using my installed swig: SWIG Version 1.3.36. I grabbed the .i file you mentioned. During compilation I am getting: /home/mathieu/Projects/gdcm/trunk/Examples/Csharp/DecompressImage.cs(64,8): error CS1502: The best overloaded method match for `gdcm.Pixmap.GetBuffer(string)' has some invalid arguments /home/mathieu/Projects/gdcm/debug-gcc/bin/gdcm_csharp.dll (Location of the symbol related to previous error) /home/mathieu/Projects/gdcm/trunk/Examples/Csharp/DecompressImage.cs(64,8): error CS1503: Argument 1: Cannot convert type `byte[]' to `string' If I check the generated .cs file, I can still find: public bool GetBuffer(string buffer) { bool ret = gdcmPINVOKE.Pixmap_GetBuffer(swigCPtr, buffer); return ret; } Here is how I used your suggestion: %include "gdcm_arrays_csharp.i" // local copy of arrays_csharp.i from svn %apply byte OUTPUT[] { char* buffer } ; %include "gdcmPixmap.h" and gdcmPixmap.h contains: class GDCM_EXPORT Pixmap : public Object { public: ... bool GetBuffer(char *buffer) const; }; Is there a way to explicitly says I want this method function to have modified typemaps ? Or is there some debug/log info I can look at to understand why your suggestion did not work for me. Thank you very much. -- Mathieu ref: debian testing / gcc 4.3 |