PYTHON setup.py build_ext --inplace PYTHON -c "import callingconvention" ######## setup.py ######## from distutils.core import setup from Cython.Distutils import build_ext from Cython.Distutils.extension import Extension setup( ext_modules = [ Extension("callingconvention", ["callingconvention.pyx", "external_callingconvention.c"]), ], cmdclass={'build_ext': build_ext}, ) ######## callingconvention.pyx ######## # mode: compile cdef extern from "callingconvention.h": pass cdef extern int f1() cdef extern int __cdecl f2() cdef extern int __stdcall f3() cdef extern int __fastcall f4() cdef extern int (*p1)() cdef extern int (__cdecl *p2)() cdef extern int (__stdcall *p3)() cdef extern int (__fastcall *p4)() p1 = f1 p2 = f2 p3 = f3 p4 = f4 ######## callingconvention.h ######## #define DLL_EXPORT #include "external_callingconvention.h" ######## external_callingconvention.h ######## #ifndef DL_IMPORT #define DL_IMPORT(t) t #elif defined(DLL_EXPORT) #define DL_IMPORT(t) DL_EXPORT(t) #endif #ifdef __cplusplus extern "C" { #endif extern DL_IMPORT(int) f1(void); extern DL_IMPORT(int) __cdecl f2(void); extern DL_IMPORT(int) __stdcall f3(void); extern DL_IMPORT(int) __fastcall f4(void); extern DL_IMPORT(int) (*p1)(void); extern DL_IMPORT(int) (__cdecl *p2)(void); extern DL_IMPORT(int) (__stdcall *p3)(void); extern DL_IMPORT(int) (__fastcall *p4)(void); #ifdef __cplusplus } #endif ######## external_callingconvention.c ######## #include #ifndef DL_EXPORT #define DL_EXPORT(t) t #endif #if !defined(WIN32) && !defined(MS_WINDOWS) #ifndef __stdcall #define __stdcall #endif #ifndef __cdecl #define __cdecl #endif #ifndef __fastcall #define __fastcall #endif #endif DL_EXPORT(int) f1(void) {return 0;} DL_EXPORT(int) __cdecl f2(void) {return 0;} DL_EXPORT(int) __stdcall f3(void) {return 0;} DL_EXPORT(int) __fastcall f4(void) {return 0;} DL_EXPORT(int) (*p1)(void); DL_EXPORT(int) (__cdecl *p2)(void); DL_EXPORT(int) (__stdcall *p3)(void); DL_EXPORT(int) (__fastcall *p4)(void);