BoboTiG / python-mss

An ultra fast cross-platform multiple screenshots module in pure Python using ctypes.
https://pypi.org/project/mss/
MIT License
1.02k stars 93 forks source link

MSS.__init__ throws AttributeError due to SetProcessDPIAware on XP #109

Closed foone closed 5 years ago

foone commented 5 years ago

General information:

Description of the warning/error

MSS.__init__ fails to initialize on XP because when SetProcessDpiAwareness fails, it falls back to SetProcessDPIAware, which was added in Vista. Wrapping it in another try/except for the Attribute error makes it work fine. (I tried to make a pull request but ran into issues with github's UI and gave up, but it's a minor fix)

Full message

Traceback (most recent call last):
  File "sc2k.py", line 58, in <module>
    take_screenshot(filename)
  File "sc2k.py", line 30, in take_screenshot
    with mss.mss() as sct:
  File "C:\Python27\lib\site-packages\mss\factory.py", line 38, in mss
    return MSS(**kwargs)
  File "C:\Python27\lib\site-packages\mss\windows.py", line 92, in __init__
    self.user32.SetProcessDPIAware()
  File "C:\Python27\lib\ctypes\__init__.py", line 379, in __getattr__
    func = self.__getitem__(name)
  File "C:\Python27\lib\ctypes\__init__.py", line 384, in __getitem__
    func = self._FuncPtr((name_or_ordinal, self))
AttributeError: function 'SetProcessDPIAware' not found
BoboTiG commented 5 years ago

Hello,

XP! :) Would you mind open a PR? It would be great.

BoboTiG commented 5 years ago

I just published 4.0.2 with your patch ;)