How this C function was called through ctypes this way?

jfong at jfong at
Fri Feb 5 01:57:51 EST 2016

eryk sun at 2016/2/4 UTC+8 7:35:17PM wrote:
> > _mod = ctypes.cdll.LoadLibrary(_path)
> Calling ctypes.CDLL directly is preferable since it allows passing
> parameters such as "mode" and "use_errno".
> IMO, the ctypes.cdll and ctypes.windll loaders should be avoided in
> general, especially on Windows, since their attribute-based access
> (e.g. windll.user32) caches libraries, which in turn cache
> function-pointer attributes. You don't want function pointer instances
> being shared across unrelated packages. They may not use compatible
> prototypes and errcheck functions. Each package, module, or script
> should create private instances of CDLL, PyDLL, and WinDLL for a given
> shared library.

Thank you for your detail and deep explanation.

I suppose the reason there are many cases using LoadLibrary() and attribute-based access is because it's the way the ctypes tutorial in Python document takes. Although both methods has been mentioned in the ctypes reference section, but no pros and cons was explained.


More information about the Python-list mailing list