From: Steven N. H. <sh...@ad...> - 2007-02-07 20:12:31
|
On Wed, 7 Feb 2007, Thom DeCarlo wrote: > Hi, > I'm not really sure if this is a SWIG question or a Python question. (total > noobie in both) > I'm running WinXP, VS8, SWIG 1.3.31, and Python 2.3 > > > I have a c++ class and function that I'm trying to wrap for python. > > class utNamedSharedMemory > { > public: > utNamedSharedMemory(); > ~utNamedSharedMemory(); > > HRESULT Initialize(std::string name); > ... > } > > SWIG generates a wrapper and I've compiled and linked it into a DLL, > _pyNamedSharedMemory.dll. > > When I load this into python, I get: > >>>> import pyNamedSharedMemory >>>> >>>> nsm = pyNamedSharedMemory.utNamedSharedMemory() >>>> >>>> nsm.Initialize("MY_DATA") > Traceback (most recent call last): > File "<stdin>", line 1, in ? > File "pyNamedSharedMemory.py", line 99, in Initialize > def Initialize(*args): return > _pyNamedSharedMemory.utNamedSharedMemory_Initialize(*args) > TypeError: in method 'utNamedSharedMemory_Initialize', argument 2 of type > 'std::string' >>>> > > Can anyone tell me how this call should be made so I can pass a string to > this function? I believe if you add %include "std_string.i" to your interface description, it will automagically convert native strings to std::string. At least, it does so for Perl wrappers. Question: Can anyone explain how one would extend this sort of magic to a home-grown string library that looks very much like std::string? I cannot even begin to understand the contemporary wrapper macros and have been reduced to defining an inline C++ wrapper around every blasted method that takes our private string type. Steve -- |