[python-win32] Re: WIN32 API?

Thomas Heller theller at python.net
Thu Jun 5 10:22:07 EDT 2003


Chuck Esterbrook <ChuckEsterbrook at yahoo.com> writes:

> On Tuesday 03 June 2003 12:51 am, Thomas Heller wrote:
> > There's a win32gui.PumpWaitingMessages() which contains the complete
> > message loop.
> 
> Thanks for the numerous tips! I'm still interested in getting what I 
> would call "full access". Here's what I've been doing/thinking:
> 
> I was looking at win32all because it seems to already "know" what the 
> proper return types and arg types are for functions. However, the 
> disadvantage is that several functions (and possibly structs) are not 
> available. While I understand that win32 is somehwhat of a moving 
> target, many funcs such as beginpaint, drawtext and endpaint are not.
> 
> ctypes can call just about anything which is fantastic. But it doesn't 
> "know" the structs or the function types.
> 

For additional ctypes' based function declarations and type definitions
you can also look into Henk Punt's venster project, he build a native
windows gui framework using ctypes.

> I then briefly contemplated writing a C preprocessor and C parser that 
> would suck up *.H out of the VC98 directory and spew the Python 
> "declarations" for ctypes. After all, the information is all right 
> there in *.H.

Except for one thing: the include file doesn't have info in which dll 
a function actually is (although the search could be done by ctypes from
a known list of dlls).

> 
> BUT that made me think of SWIG which already does this and is already 
> used by win32!
> 
> So...I'm a little bit in the dark here. If SWIG's C preprocessor can 
> slurp up a header and spew out a library with the structs and 
> functions, BUT win32all only has a subset, I feel I must be missing 
> something...
> 
> Is SWIG really not capable of this? If so, is the newer SWIG 1.3 
> capable? (AFAICT win32all uses a modified SWIG 1.1)
> 

I have to leave this answer to people actually using swig.

> If I were to preprocess and parse the C headers, would anything prevent 
> me from generating Python source for ctypes to specify the return 
> types, arg types and structs?

No, it should work.

Niki spahiev mentioned Simon Burton's cdecl.py module in the
ctypes-users mailing list. I did some experiments with is and the
results are quite promising.

I sent VC98's windows.h file through the cl preprocessor (which resulted
in a 46000 line file after removing chunks of empty lines, and fed it to
the cdecl module.

I had to fix one bug with hex constants, and had to hack around several
windows specific problems (__cdecl, __stdcall, and other MS qualifiers),
and unnamed structures. cdecl does not yet parse the file completely,
but it looks promising. Maybe the end result can be something like
Python's h2py script.

Thomas




More information about the Python-win32 mailing list