Why won’t this ctypes code work with Python 3.3 but will work with Python 2.7?

SystemParametersInfoA requires a 8-bit ANSI encoded input string as a parameter, which is known as mbcs encoding in Python.

You will have to use SystemParametersInfoW in python3. This is because SystemParametersInfoW takes in a UTF-16 wide string (which is wchar_t * in C) and the ctypes library automatically converts this passed unicode argument into c_wchar_p.

Refer the documentation for more details.

Leave a Comment