I’ve committed to trying to really sit down and learn how to use SWIG to do things “the correct way”, and I’m having lots of trouble. First, let me ask a specific question then I’ll elaborate on the general troubles I’m having and perhaps someone could point me in the right direction.

 

I’m sure this is a very common question (I’ve seen it asked a lot, but thanks to poor sourceforge mailing list search/browsing and google pointing to dead pages, I can’t find an answer!).

 

I need to wrap the following type of function:

 

typedef void *HANDLE;

void MyFunc(HANDLE *pOutput);

 

The cheezy way (and what I’ve done in the past) is to typecast HANDLE as an unsigned long (32-bit forever!) and move on my way. However, by doing that I completely miss out on all the type checking I would have gotten by treating HANDLE as a unique SWIGTYPE.

 

So, what’s the “correct” way to return a SWIGTYPE pointer via an argument? I saw someone’s solution that involved rewriting typemaps and allocating memory, but this seems utterly overkill for what should be the most common output task.

 

----

In general though, although the SWIG docs are robust for low level SWIG typemaps and everything, they hardly cover most of the MEAT of SWIG which lies in the libraries and proper use of them. And, no, “look at the files” is no more acceptable here than “look at the disassembly” is for documenting software – it’s to complicated and there are far too many levels of preprocessor foo to have to wade through. The examples that come with SWIG seem to cover cases I don’t care about, they don’t cover the every-day little things I run into every single time I try to expose even the simplest function. Where do I go to find information on the libraries and how to use them?

 

Thanks muchly!

-Allen