473,386 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Problem with PyRun_SimpleFile and MFC Application

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
Jul 18 '05 #1
8 2439
"Susanne" <su******@web.de> wrote...
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:
[...]

So, does anyone of you have an idea, what i am doing wrong in my mfc app?


Somebody in a relevant newsgroup probably does. comp.lang.c++ is
NOT one of them. Perhaps along with the Python one that you used,
an MFC newsgroup can help. comp.os.ms-windows.programmer.tools.mfc
and microsoft.public.vc.mfc are the two that spring to mind.

Victor
Jul 18 '05 #2
"Susanne" <su******@web.de> schrieb im Newsbeitrag
news:18**************************@posting.google.c om...
| 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.
|

<Code snipped> >//works fine, only says, that there is no modul called
CORBA

|
| So, does anyone of you have an idea, what i am doing wrong in my mfc app?
PyRun_SimpleFile() reportedly (and I can second that) when certain compiler
flags are different from the pythonxx(_d).dll. Try setting your Project
Settings -> C/C++, Code Generation -> "Use runtime library" - to "(Debug)
Multithreaded DLL"

(Don't know if or how this affects any of your MFC stuff though)

Hope this helps,

Vincent Wehren

|
| Susanne
Jul 18 '05 #3
vincent wehren wrote:
"Susanne" <su******@web.de> schrieb im Newsbeitrag
news:18**************************@posting.google.c om...
| 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.
|

<Code snipped> >//works fine, only says, that there is no modul called
CORBA

|
| So, does anyone of you have an idea, what i am doing wrong in my mfc app?
PyRun_SimpleFile() reportedly (and I can second that) when certain compiler
flags are different from the pythonxx(_d).dll. Try setting your Project
Settings -> C/C++, Code Generation -> "Use runtime library" - to "(Debug)
Multithreaded DLL"

(Don't know if or how this affects any of your MFC stuff though)


Yes, this will be the OPs issue. However, you don't always use the
debug CRT - the important thing is to use the *same* CRT as Python
itself. So a release build of your app/extension *must* be the
non-debug in a DLL, and a debug build must use the debug in a DLL.

Mark.

Jul 18 '05 #4
"Mark Hammond" <mh******@skippinet.com.au> wrote...
vincent wehren wrote:
"Susanne" <su******@web.de> schrieb im Newsbeitrag
news:18**************************@posting.google.c om...
| Hello!

[...]
PyRun_SimpleFile() reportedly (and I can second that) when certain compiler flags are different from the pythonxx(_d).dll. [...]

(Don't know if or how this affects any of your MFC stuff though)


Yes, this will be the OPs issue. However, you don't always use the
debug CRT - the important thing is [...]


This is all OT in comp.lang.c++. Please trim your cross-posting.
[follow-ups set to Python group only]

Victor
Jul 18 '05 #5
Hello together,

after reading your comments, i looked, which configuration
im using in my console app. Its a release app.
Than i tried to run it as a debug app and now the
programm crashes like my mfc app.

So the hint with the debug dll was good.

But how can i get this dll?
I don't have the python source code and i also
can't find it in the internet.
So there is no way to create it by myself.

Can anyone of you help me again??

Thanks
Susanne
Jul 18 '05 #6
su******@web.de (Susanne) writes:
[...]
But how can i get this dll?
I don't have the python source code and i also
can't find it in the internet.

[...]

http://www.python.org/
You have to compile the debug DLL yourself, IIRC.
John
Jul 18 '05 #7
"Susanne" <su******@web.de> schrieb im Newsbeitrag
news:18**************************@posting.google.c om...
| Hello together,
|
| after reading your comments, i looked, which configuration
| im using in my console app. Its a release app.
| Than i tried to run it as a debug app and now the
| programm crashes like my mfc app.
|
| So the hint with the debug dll was good.
|
| But how can i get this dll?
| I don't have the python source code and i also
| can't find it in the internet.
| So there is no way to create it by myself.
|
| Can anyone of you help me again??
|
| Thanks
| Susanne

Download the Python source (e.g.
http://www.python.org/ftp/python/2.3.2/Python-2.3.2.tgz or the version you
want to use) and untar it to disk. You will end up with a directory
"Python-2.3.2".

In this directory you will find a directory called "PCBuild" with the
relevant MSVC workspaces already nicely lined up. Look at the pythoncore and
build it in debug mode (python23_d.dll).

If you want to do extensions at some time, make sure you compile a
python_d.exe for debugging purposes too.

Regards
Vincent Wehren

(PS: ~snipped cross-post to comp.lang.c++ to avoid angry neighbors....)




Jul 18 '05 #8
Hello,
i changed Python 2.3 to Python 2.1.

The ftp of python.org contains a *.zip file in the 2.1 directory
which contains python21_d.lib etc.
I downloaded the file, and unpacked it in my python21 directory.

http://www.python.org/ftp/python/2.1...-2.1-Debug.zip

Now PyRun_SimpleFile works !!

Thanks!!!!!

Bye
Susanne
Jul 18 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Susanne | last post by:
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...
12
by: SJD | last post by:
I've just read Christoph Schittko's article on XmlSerializer: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnxmlnet/html/trblshtxsd.asp . . . and very informative it is too....
9
by: Rajat Tandon | last post by:
Hello there, I am relatively new to the newsgroups and C#. I have never been disappointed with the groups and always got the prompt replies to my queries.This is yet another strange issue, I am...
4
by: pjdouillard | last post by:
Hello all, Here is the context of my problem: We have an ASP.NET 1.1 application that has its own application pool setup and that runs under the identity of a NT Domain service account (this...
2
by: Miguel | last post by:
Hi, I'm developing an application in C# with Windows Forms for my company that is similar to the MSN Messenger. This application uses a webservice for registering users, etc... and as 2...
2
by: Bill Nguyen | last post by:
I ran into this error trying to run an app from Publish.htm. I can't find what is wrong with the deployment. Thanks a million Bill -------- PLATFORM VERSION INFO
1
by: cvairetti | last post by:
Hi, I just write an application in C# that show an interface with five button, each button starts an external application that it comes in front of the main C# application with focus on. When the...
5
by: lixinyi.23 | last post by:
my code: main.cpp #include <Python.h> int main(int argc, char **argv) { Py_Initialize(); FILE *file_1 = fopen("a2l_reader.py","r+"); PyRun_SimpleFile(file_1,"a2l_reader.py");
6
by: Tony Johansson | last post by:
Hello! We have a C#.ASP.NET application that runs on a IIS 6. The application contains actually several asp pages but there is no GUI. The application receive an xml file that is processed....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.