1 2 3 4 5 6 7 8 9 10 | #include <string> class Excute { public: Excute(){} int getIoReuslt(std::string ioStr); int getSignal(); }; #endif |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | int Excute::getIoReuslt(std::string ioStr) { //do something here return 1; } int Excute::getSignal() { int i = rand()%2; return i; } BOOST_PYTHON_MODULE(pythonDll) { using namespace boost::python; class_<Excute>("Excute", init<>()) .def("getIoResult", &Excute::getIoReuslt) .def("getSignal", &Excute::getSignal) ; } |
1 2 3 4 5 | from pythonDll import*h=Excute()h.excute("abc")print h.getSignal()... |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | int main(int argc, char* argv[]) { Py_Initialize(); FILE * fp = fopen("$PATH/test.py", "r"); if (fp == NULL) { return 1; } PyRun_SimpleString("execfile($PATH/test.py')"); Py_Finalize(); system("Pause"); return 0; } |