From: codeoedoc <cod...@gm...> - 2013-03-02 18:47:53
|
Hi Richard, I haven't used MFC wrapping. In linux, to wrap an unknown type, one can do something like: %apply int { int32_t }; Hope it helps. Xin On Fri, Mar 1, 2013 at 5:52 AM, Richard Burcher <ric...@gm...>wrote: > Hi folks, apologies if this is duplicated on the list. > > Set up: > windows xp pro os > Windows vc++ 2008 > python 2.7 > swig 2.0.9 > > Working on wrapping a number of C++ classes into a Python wrapper but am > encountering issues with MFC CString. Can successfully generate swig > wrapper > & compile the Python module & shared library within Visual Studios 2008. > The > module can be imported into Python 2.7, an object instance created but the > issue arises when passing a string file path to a member function; Python > reports: TypeError: in method 'CEnSimObject_SetFullFileName', argument 2 > of > type 'CString' > > I've reviewed the swig wrapper section & somewhat understand that the issue > is the creation of a CString pointer from the the passed in Python string. > Reviewing this message board & web in general, many point to creating an > MFC > CString class wrapper & that std_string.i is a template for use. I have > looked over these but am not sure how/where to implement this. I have tried > using the %typemap mentioned in the swig documentation but again, not > entirely sure how you define a conversion type. > > How do you let swig know about MFC & CString? > > Please note that I am quite new to C++ & only looking for some > hints/pointers. > > Cheers, > > Richard > > > swig wrapper file: > ------------------------- > %module swig_pyEnsim > > %{ > > #pragma once > > #ifndef _WIN32 > #define _WIN32 1 > #endif > > #include "stdafx.h" > #define AFX_EXT_CLASS > > #include "D:\Projects\Kenue\EnSimCore\EnSimObject.h" > #include "D:\Projects\Kenue\EnSimCore\EnSimDrawableObject.h" > #include "D:\Projects\Kenue\EnSimCore\TableObject.h" > %} > > %include "stdafx.h" > %define AFX_EXT_CLASS > %enddef > > %include "D:\Projects\Kenue\EnSimCore\EnSimObject.h" > %include "D:\Projects\Kenue\EnSimCore\EnSimDrawableObject.h" > %include "D:\Projects\Kenue\EnSimCore\TableObject.h" > > --------- > python function: > > def SetFullFileName(self, *args): return > _swig_pyEnsim.CEnSimObject_SetFullFileName(self, *args) > > --------- > section of swig generated wrapper: > > SWIGINTERN PyObject *_wrap_CEnSimObject_SetFullFileName(PyObject > *SWIGUNUSEDPARM(self), PyObject *args) { > PyObject *resultobj = 0; > CEnSimObject *arg1 = (CEnSimObject *) 0 ; > CString arg2 ; > void *argp1 = 0 ; > int res1 = 0 ; > void *argp2 ; > int res2 = 0 ; > PyObject * obj0 = 0 ; > PyObject * obj1 = 0 ; > BOOL result; > > if (!PyArg_ParseTuple(args,(char > *)"OO:CEnSimObject_SetFullFileName",&obj0,&obj1)) SWIG_fail; > res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_CEnSimObject, 0 | 0 ); > if (!SWIG_IsOK(res1)) { > SWIG_exception_fail(SWIG_ArgError(res1), "in method '" > "CEnSimObject_SetFullFileName" "', argument " "1"" of type '" "CEnSimObject > *""'"); > } > arg1 = reinterpret_cast< CEnSimObject * >(argp1); > { > res2 = SWIG_ConvertPtr(obj1, &argp2, SWIGTYPE_p_CString, 0 | 0); > if (!SWIG_IsOK(res2)) { > SWIG_exception_fail(SWIG_ArgError(res2), "in method '" > "CEnSimObject_SetFullFileName" "', argument " "2"" of type '" > "CString""'"); > } > if (!argp2) { > SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in > method '" "CEnSimObject_SetFullFileName" "', argument " "2"" of type '" > "CString""'"); > } else { > CString * temp = reinterpret_cast< CString * >(argp2); > arg2 = *temp; > if (SWIG_IsNewObj(res2)) delete temp; > } > } > result = (arg1)->SetFullFileName(arg2); > resultobj = SWIG_NewPointerObj((new BOOL(static_cast< const BOOL& > >(result))), SWIGTYPE_p_BOOL, SWIG_POINTER_OWN | 0 ); > return resultobj; > fail: > return NULL; > } > > -- > Cheers, > > Richard > > ------ > Please note: > I only check email a few times during business hours. > > Richard Burcher > 613-799-4240 > > LinkedIn: http://linkd.in/richardburcher > Twitter: @richardburcher > Blog: http://geotechrichard.com/ > > > ------------------------------------------------------------------------------ > Everyone hates slow websites. So do we. > Make your web apps faster with AppDynamics > Download AppDynamics Lite for free today: > http://p.sf.net/sfu/appdyn_d2d_feb > _______________________________________________ > Swig-user mailing list > Swi...@li... > https://lists.sourceforge.net/lists/listinfo/swig-user > > |