On 10/11/2009 8:14 AM, Greg Ewing wrote:
I have a bizarre problem. The following program:

import win32ui
app = win32ui.GetApp()
app.Run()

works fine when run from a command window using
python.exe -- it happily sits there waiting for
events until I kill it with the task manager.

However, if I run it using pythonw.exe, the
GetApp() call returns immediately with a value
of 0.

I've tried diverting stdout and stderr into a
file to see if there are any error messages or
tracebacks, but there is nothing.

Anyone have any idea what might be wrong?

I'm using Python 2.5.4 and Pywin32 build 213
on Windows 2000.

No real clues, other than noting only a "default" app will be used - you generally need to provide your own app which does magic in InitInstance. The following script is the "correct" way of booting an MFC/win32ui app - the important bit is really the side-effect (boo!) of importing pywin.framework.intpyapp.

Cheers,

Mark

import sys
import win32ui
# importing 'intpyapp' automatically registers an app object.
from pywin.framework import intpyapp

# Remove this script name from sys.argv, else Pythonwin will try and open it!
sys.argv = sys.argv[:-1]
# Get the MFC "app" object and boot it up.
app = win32ui.GetApp()
app.InitInstance()
app.Run()
app.ExitInstance()
_______________________________________________
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to