call python with python extension in c

放茗 谈 jolley84 at yahoo.com.cn
Fri Nov 24 08:41:22 CET 2006


hello all,  i am a newcomer, and i bring a quesition here: how can i call python app with wxPython/other python extensions in c?
  here is my code here,though not smart,it can explain myself to some extent,in addition,pls forgive me not checking the return value after each calling PyRun_SimpleString,just in the purpose of keeping the code more easier readability:
  #include "python.h" 
#include <iostream> 
using namespace std; 

  int main() 
{ 
  Py_Initialize(); 
if(!Py_IsInitialized()) 
{ 
    cerr << " initialization fails!" << endl; 
    return -1; 
  } 


    PyRun_SimpleString("from wxPython.wx import *"); 
  PyRun_SimpleString("class myApp(wxApp):"); 
  PyRun_SimpleString("        def OnInit(self):"); 
  PyRun_SimpleString("              frame 
=wxFrame(NULL,-1,"hello,world")"); 
  PyRun_SimpleString("              frame.Show(true)"); 
  PyRun_SimpleString("              self.SetTopWindow(frame)"); 
  PyRun_SimpleString("              return true"); 
  PyRun_SimpleString("app = myApp()"); 
  PyRun_SimpleString("app.MainLoop()"); 

    Py_Finalize(); 
   return 0; 
  } 
from the code above,we can see clearly i intend to build up an simple framework with its title "hello,world".but it doesnot work. mainly due to the python extension wxpython, i think.coz if i doesnot write something connected with python extension,such as wxPython.it will run normally, later my work on wxpython include ,first build the wxpython source code into  some pyds and dlls, at this point, i add the pyds and dlls to the vc directory and c:\WINDOWS\system32\.unfortunately,it doesnot work.now my head aches, the whole progress is messed up. i nearly want to say goodbye to my boss.so anyway,help me,ok?
  and i have searched  almost anywhere,nobody i could turn to help,the feedback is little,and i am in despair.
  regards,
  jolley



 		
---------------------------------
 Mp3疯狂搜-新歌热歌高速下   
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20061124/b15bbbe6/attachment.html>


More information about the Python-list mailing list