Problem with PyRun_SimpleFile and MFC Application
Susanne
susi2000 at web.de
Tue Nov 25 15:32:46 EST 2003
Hello!
In have embedded python into my MFC application.
It works fine using the PyRun_SimpleString method, giving it a string with
some simple commands.
When i am using PyRun_SimpleFile instead, my application crashes.
I have also created a console application. There i also call PyRun_SimpleFile.
The console application executes the given script.
My code looks like the following:
**********************************
MFC-Application:
**********************************
>Py_SetProgramName("testclient");
>/* Initialize the Python interpreter. Required. */
>Py_Initialize();
>initCORBA();
>curMode = DEBUG_MODE;
>//**** is running!!!!*****
>//CString command = "import CORBA; CORBA.SetTPData();";
>//PyRun_SimpleString(command);
>//CORBA is my python module, SetTPData a method of this modul
>//in SetTPData i open an AfxMessageBox, so thats why i know that
>//it works
>//path of my file
>char * filename2 = "C:\\cvsroot\\OCI-TestClient\\projects\\main\\tao\\test.py";
>FILE *fp =fopen(filename2,"r");
int result;
>if(fp !=NULL)
>{
> //does not work :-(
> result = PyRun_SimpleFile(fp,filename2);
> fclose(fp);
>}
>Py_Finalize();
****************************************
Now the code of the console application:
****************************************
>/* Pass argv[0] to the Python interpreter */
>Py_SetProgramName(argv[0]);
>/* Initialize the Python interpreter. Required. */
>Py_Initialize();
>//create instance of my class
>PythonExtension * pythi = new PythonExtension();
>//init my module (not the same module like in MFC app)
>pythi->initspam();
>char * filename2 = "C:\\cvsroot\\OCI-TestClient\\projects\\main\\tao\\test.py";
>FILE *fp =fopen(filename2,"r");
>int result;
>//works fine, only says, that there is no modul called CORBA
>//see below
>result = PyRun_SimpleFile(fp,filename2);
>printf("Result: %d",result);
**********************
My python script file:
**********************
>import CORBA;
>CORBA.SetTPData();
>//...
************************
So, does anyone of you have an idea, what i am doing wrong in my mfc app?
Susanne
More information about the Python-list
mailing list