Apparently using ctypes
on Cygwin has the bad side effect of not recognizing the host OS as being using Windows, so the Python interpreter cannot use/import the often used Window (API) specific DLL loaders, such as:
from ctypes import WinDLL
import wintypes
import msvcrt
The reason is that the import mechanism is using sys.platform
to check for win32
, but receives cygwin
, and thinks it's on another OS and therefore disables any Windows related imports.
As I have mentioned in this answer, you can import DLL's using the cdll
loader from ctypes, but I have no idea if this is correct and what is the difference from using the windll
.
Is there a way to side-load the windll
(or wintypes, msvcrt
) ctypes libraries on Cygwin?
(It's very sad that Cygwin, ctypes and the python maintainers have not figured out what to do in this case, even after 6+ years of being first reported.)
For reference, when trying to import wintypes
, you get:
>>> from ctypes import wintypes
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.6/ctypes/wintypes.py", line 20, in <module>
class VARIANT_BOOL(ctypes._SimpleCData):
ValueError: _type_ 'v' not supported
Where the offending lines are in wintypes.py
:
class VARIANT_BOOL(ctypes._SimpleCData):
_type_ = "v"
def __repr__(self):
return "%s(%r)" % (self.__class__.__name__, self.value)
ADENDUM
Probably we should not try to use the wintypes libraries in this use case. As stated in the python ctypes docs:
Note: Accessing the standard C library through
cdll.msvcrt
will use an outdated version of the library that may be incompatible with the one being used by Python. Where possible, use native Python functionality, or else import and use themsvcrt
module.