(I'd search the archives, but the sf.net search function isn't working
now.)
First off, I see that I can include stl.i to get translation of
std::string to String. However, in case a developer reads this, I'd like
to point out that this is not mentioned in the manual until chapter 25,
SWIG and Ocaml. It belongs in "SWIG Basics" too, IMO. Speaking of the
manual, I'm surprised that there's no command-line argument reference in
there. (but you can use the command line "swig -help" to get a
mini-reference.)
Unfortunately, the C# version of stl.i (actually std_string.i) doesn't
work for me because I'm using std::basic_string<wchar_t>, not
std::string itself (std::string is a typedef of
std::basic_string<char>). I was thinking I might make a copy of
std_string.i hack it to use wide strings instead. Does this sound like
the best approach? I'm more than a little worried I won't be able to do
it correctly because I'm a newbie. BTW, I don't actually use
basic_string in my code; I have a derived class called more_string which
adds extra functionality (no extra data). I could use a typedef to fool
SWIG, if only it could handle basic_string (which it can't).
typedef std::basic_string<wchar_t> tstring;
Next problem: SWIG is translating all my pointers to C# classes named
SWIGTYPE_p_*. I know they exist for type checking, but I would much
prefer to save at least two heap allocations by simply using IntPtr in
such cases. Can I do this globally? Or, if nothing else, can I get void*
to be translated as IntPtr (rather than SWIGTYPE_p_void)?
How do I get SWIG to translate HWND as IntPtr? (I'm wrapping a C++
control which needs to be passed the window handle of a parent window in
which it should create itself. In C# this is represented by
System.Windows.Forms.Control.Handle, which is an IntPtr.)
I'm having a little problem with RECT: SWIG has put it verbatim in the
C# file:
// C++
virtual void Create(HWND parent, RECT& rc);
// C#
public virtual void Create(SWIGTYPE_p_HWND parent, RECT rc) { ... }
That's actually a Good Thing on the face of it: I don't want SWIG to
wrap the structure, nor treat it like a pointer; it should be passed
through directly. RECT doesn't exist on the C# side, but that's okay:
I'll be happy to supply the structure definition myself, but I might
like it to have a different name in C# (maybe Rect).=20
Unfortunately, the wrapper doesn't pass RECT, instead it passes void*
and treats it like RECT*:
// C#
[DllImport("Navi", EntryPoint=3D"CSharp_MapControl_Create__SWIG_1")]
public static extern void MapControl_Create__SWIG_1(HandleRef jarg1,
HandleRef jarg2, HandleRef jarg3);
// C++
SWIGEXPORT void SWIGSTDCALL CSharp_MapControl_Create__SWIG_1(void *
jarg1, void * jarg2, void * jarg3)
{
...
arg3 =3D (RECT *)jarg3;
...
}
So I have two questions: how can I get RECT passed directly as a
structure, and how do I rename it on the C# side?
|