From: Lyle Johnson Date: 2004-08-22T01:19:52+09:00 Subject: Re: calling a swig generated function On Sat, 21 Aug 2004 06:47:08 +0900, Michael Hale wrote: > 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] OK, good! > 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); Yes, I couldn't tell from your previous example (in the original post) what kind of return value, if any, NSCalculateGap() was declared to have -- so I guess a void return type. If you only want the wrapped version of NSCalculateGap() to return a single value (the gap) and not that two-element array, you might be able to do something like this: %extend { unsigned long NSCalculateGap(int iMode, int iSpeed, unsigned long ulPacketLength, double dValue, int iHub, int iSlot, int iPort) { int iResult; unsigned long ulGap; iResult = NSCalculateGap(iMode, iSpeed, ulPacketLength, dValue, &ulGap, iHub, iSlot, iPort); return ulGap; } } In other words, we're introducing a helper function in the middle that calls the "real" NSCalculateGap() function and ignores its integer return value. If that integer return value shouldn't be ignored -- say, because it is an error code or something -- you might want to check it first and raise an exception, or whatever makes sense for your application. Hope this helps, Lyle