473,402 Members | 2,061 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,402 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 22 '05 #1
5 2160
"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 22 '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 22 '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 22 '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 22 '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 22 '05 #6

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

Similar topics

8
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...
2
by: Programatix | last post by:
Hi, I'm working on a project which includes WebServices and Windows Form application. The Windows Form application will call the WebServices to retrieve data from database. The data will be...
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: 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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.