i'm sorry if question seems repeated many times here spent whole day without finding clear answer.
i'm working under visual studio 2010 , i'm trying load class defined in dll python. saw there's no way without making c++ wrapper (using swig or boost.python). i'm not c++ programmer , couldn't find easy , clear tutorial start with, grateful if give me simple one.
also, class uses singleton pattern restricts instantiation 1 object :
myclass* myclass::getinstance() { if(instance==null) instance = new myclass(); return instance; }
so need know how can deal in python script can create instance of myclass , access methods.
thanks guys.
after finding solution problem, come answer question whom might help.
i used swig make c++ wrapper. defined module interface :
%module myclass %{ #include "myclass.h" %} %include <windows.i> //if you're using __declspec(dllexport) export dll %include "myclass.h"
then compiled directly :
>swig -c++ -python myclass.i
and generates 2 files : myclass.py , myclass_wrap.cxx.
i included myclass_wrap.cxx file project in visual studio , made these changes on project properties :
configuration properties > general > target name : _myclass target extension : .pyd
c/c++ > general > additional include directories : /path/to/python/include
linker > additional library directories : //path/to/python/libs
and compiled project generate _myclass.pyd.
in python script, simple following :
import myclass instance = myclass.myclass.getinstance() #and use myclass methods via instance, ex: instance.somemethod()
that's all. swig work handle reference returned getinstance().
Comments
Post a Comment