[Pyrex] ctypedef in a "cdef extern from" block

Matthias Baas baas at ira.uka.de
Tue Jun 17 13:24:36 CEST 2003


At 09:53 10.06.2003 +1200, Greg Ewing wrote:
> > The problem is the WINAPI macro which is defined as:
> >
> > #define WINAPI  __stdcall
>
>Ah, I see. Windows bogosity strikes again. :-(
>
> > Everything would be fine if Pyrex would just use the type name
> > (PFNWGLCREATEPBUFFERARBPROC)
>
>Try this:
>
>   ctypedef struct PFNWGLCREATEPBUFFERARBPROC
>   ctypedef PFNWGLCREATEPBUFFERARBPROC *HPBUFFERARB

I don't understand how to use this in my case. If I declare the function 
pointer as a struct, then I can't call it anymore.

Here's again an extract from an example program:

cdef extern from "wingdi.h":
     ctypedef struct HDC

cdef extern from "GL/wglext.h":

     # declare the function pointer
     ctypedef char * (*PFNWGLGETEXTENSIONSSTRINGARBPROC)(HDC hdc)

#  the above function pointer declaration should actually include the 
WINAPI macro:
#    ctypedef char * (WINAPI * PFNWGLGETEXTENSIONSSTRINGARBPROC)(HDC hdc)


def wglGetExtensionsStringARB(long dc):
     cdef PFNWGLGETEXTENSIONSSTRINGARBPROC proc
     cdef char* s

     # Retrieve the function pointer...
     proc = 
<PFNWGLGETEXTENSIONSSTRINGARBPROC>wglGetProcAddress("wglGetExtensionsStringARB")
     # ...and call the function
     s = proc(<HDC>dc)
     print s

When I call wglGetExtensionsStringARB() from Python everything works fine 
as long as we are still inside the function. It retrieves the function 
pointer using wglGetProcAddress(), calls the function and prints the return 
value (which is a list of available extensions). But when the function 
wants to return I get a crash since proc() was called using the wrong 
calling convention (__cdecl instead of __stdcall) which results in a 
corrupted stack.
Now I don't see how I could declare PFNWGLGETEXTENSIONSSTRINGARBPROC as a 
struct. If I do, then I can't call proc() anymore since it's not a function.
I still think the easiest solution (for me) would be to prevent Pyrex from 
expanding the typedef. If the name PFNWGLGETEXTENSIONSSTRINGARBPROC would 
make it into the generated C file then it would have the correct calling 
convention.

Or is there another solution how to get the exact name into the generated C 
file and still being able to call the function in Pyrex?

Cheers,

- Matthias -





More information about the Pyrex mailing list