472,986 Members | 3,019 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,986 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 2413
"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....
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.