Re: ctmswgui vs ctypes-0.6.0

Thomas Heller <[email protected]> 06 May 2003 20:02:41 +0200
Newsgroups gmane.comp.python.anygui.devel
Message-ID <[email protected]>
Robin Becker <[email protected]> writes:

> Hi Thomas, I'm looking to convert the anygui ctmswgui.py to the latest
> ctypes and have a couple of problems.
> 
> First off I converted c_string to c_buffer. I guess that's
> uncontroversial.
> 
> I cannot seem to import _DynFunction or CFunction and there don't seem
> to be obvious candidates for our usage of the former. Can you have a
> quick scan of the code and say what needs to be done?

You would probably create a subclass of WinDLL, and use an instance of
it. Here's the ctypes.WinDLL source, straight from ctypes/__init__.py:

    class WinDLL(CDLL):
        class _StdcallFuncPtr(_CFuncPtr):
            _flags_ = _FUNCFLAG_STDCALL
            _restype_ = c_int # default, can be overridden in instances

        def __getattr__(self, name):
            if name[:2] == '__' and name[-2:] == '__':
                raise AttributeError, name
            func = self._StdcallFuncPtr(name, self)
            setattr(self, name, func)
            return func

So changing your WinDLL to this one should do (untested):

class WinDLL(ctypes.WinDLL):

    def __getattr__(self, name):
        if name[:2] == '__' and name[-2:] == '__':
            raise AttributeError, name
        try:
            func = self._StdcallFuncPtr(name, self)
        except:
            func = self._StdcallFuncPtr(name+_apiMode, self)
        setattr(self, name, func)
        return func


Let me know if you need further help,

Thomas



-------------------------------------------------------
Enterprise Linux Forum Conference & Expo, June 4-6, 2003, Santa Clara
The only event dedicated to issues related to Linux enterprise solutions
www.enterpriselinuxforum.com