From: Michael Hale Date: 2004-08-21T06:47:08+09:00 Subject: Re: calling a swig generated function Thank you for the suggestion. I was able to get my code to work with the following in my smartlib.i file: %apply unsigned long *OUTPUT { unsigned long *pulGap }; Now I call the function like this: NSCalculateGap(iMode, iSpeed, ulPacketLength, dValue, hub, slot, port) And get back an array with the first element being the original return value and the second being the value of the pulGap pointer. Like this: [0,1273] BTW here is the method definition from my header file: int DLL_EXPORT NSCalculateGap(int iMode, int iSpeed, unsigned long ulPacketLength, double dValue, unsigned long *pulGap, int iHub, int iSlot, int iPort); On Aug 19, 2004, at 9:09 AM, Lyle Johnson wrote: > On Thu, 19 Aug 2004 09:58:32 +0900, Michael Hale > wrote: > >> I have a library that I wrapped with SWIG. One of the SWIG generated >> functions looks like this: > > > > I'm guessing that the fifth argument is declared as a pointer to an > unsigned long, correct? The problem is that SWIG doesn't know which > one of the many interpretations of that to use. In this case, it > appears that the NSCalculateGap() function uses that unsigned long > pointer argument to return a value (i.e. for output), but as far as > SWIG knows you could be passing in a single unsigned long value, or > even an array of unsigned longs, as input. > >> How should I call this function from ruby? > > You're going to need to use a typemap of some kind to let SWIG know > that, in this case, that unsigned long pointer argument is actually an > output value. Depending on how you've written your SWIG interface > file, you'll want to do something like this: > > // Include declarations for output typemaps from the SWIG library > %include typemaps.i > > // Apply SWIG's OUTPUT typemap for unsigned long values to the > "ulGap" argument > %apply unsigned long *OUTPUT { unsigned long ulGap; } > > // Here's what I would guess the actual function declaration looks > like... > void NSCalculateGap(int iMode, int iSpeed, unsigned long > ulPacketLength, double dValue, unsigned long *ulGap, int iHub, int > iSlot, int iPort); > > Now, when you call this function from Ruby you will only pass in the > seven input arguments, and catch the output value as the method > result, e.g. > > ulGap = Smartlib::NSCalculateGap(iMode, iSpeed, ulPacketLength, > dValue, hub, slot, port) > > For more information, see the "Argument Handling" chapter of the SWIG > manual: > > http://www.swig.org/Doc1.3/Arguments.html > > Hope this helps, > > Lyle > > > "OS X: because it was easier to make UNIX user-friendly than to fix Windows"