It is not only that ctypes.cdll.msvcrt automatically exists, but ctypes.cdll.anything automatically exists and loads on first access, loading anything.dll . Therefore, ctypes.cdll.msvcrt loads msvcrt.dll , which is the library that ships as part of Windows. This is not a C runtime environment that Python works with, so you should not call malloc / free from msvcrt .
For example, for Python 2.6 / 3.1 you should use ctypes.cdll.msvcr90 . Since this will change over time, find_msvcrt() gives you the name of the library that you really should use (and then load through ctypes.CDLL ).
The following are the names of several different versions of Microsoft CRT released at different points as part of the MSC, VC ++, platform SDK or Windows: crtdll.dll, msvcrt.dll, msvcrt4.dll, msvcr70.dll, msvcr71.dll, msvcr80.dll, msvcr90.dll.
Martin v. LΓΆwis
source share