我的目标是从运行在Python3.6中的magnification.dll中获得。我可以放大屏幕,但我无法使输入的转换工作。我希望有人知道如何解决这个问题,并能解释我做错了什么。谢谢。( 放大API (Windows)
附注:可能会发生这样的情况:您需要手动关闭python进程,因为缩放不会停止。(至少在代码中)
magnification_api.py
import ctypes
class RECT(ctypes.Structure):
_fields_ = [("left", ctypes.c_long),
("top", ctypes.c_long),
("right", ctypes.c_long),
("bottom", ctypes.c_long)]
class Magnification:
def __init__(self):
self.dll = ctypes.CDLL("magnification.dll")
BOOL = ctypes.c_bool
FLOAT = ctypes.c_float
INT = ctypes.c_int
self.LPRECT = LPRECT = ctypes.POINTER(RECT)
self.PBOOL = PBOOL = ctypes.POINTER(ctypes.c_bool)
# MagInitialize
self.dll.MagInitialize.restype = BOOL
# MagUninitialize
self.dll.MagUninitialize.restype = BOOL
# MagSetFullscreenTransform
self.dll.MagSetFullscreenTransform.restype = BOOL
self.dll.MagSetFullscreenTransform.argtypes = (FLOAT, INT, INT)
# MagGetInputTransform
self.dll.MagGetInputTransform.restype = BOOL
self.dll.MagGetInputTransform.argtypes = (PBOOL, LPRECT, LPRECT)
def MagInitialize(self):
return self.dll.MagInitialize()
def MagUninitialize(self):
return self.dll.MagUninitialize()
def MagSetFullscreenTransform(self, magLevel, xOffset, yOffset):
return self.dll.MagSetFullscreenTransform(magLevel, xOffset, yOffset)
def MagGetInputTransform(self, pfEnabled, prcSource, prcDest):
return self.dll.MagGetInputTransform(pfEnabled, prcSource, prcDest)zoomer.py
import ctypes
from magnification_api import Magnification
import time
class Main:
def __init__(self):
self.mag = Magnification()
def zoom(self, factor, x, y):
if factor > 1.0:
while True:
if self.mag.MagInitialize():
result = self.mag.MagSetFullscreenTransform(factor, 0, 0)
if result:
fInputTransformEnabled = self.mag.PBOOL()
rcInputTransformSource = self.mag.LPRECT()
rcInputTransformDest = self.mag.LPRECT()
if self.mag.MagGetInputTransform(fInputTransformEnabled, rcInputTransformSource, rcInputTransformDest):
# fails here
print("Success")
else:
print("Failed")
time.sleep(1)
if __name__ == "__main__":
m = Main()
m.zoom(1.05, 0, 0)发布于 2018-04-19 21:35:41
首先,我要指出代码中不正确的其他内容(不一定与错误相关):
作为副词,BOOL的自定义定义与Win的定义不匹配:
ctypes.sizeof(ctypes.c_bool) 1 >>> ctypes.sizeof(wintypes.BOOL) 4
它是访问冲突的候选。
self.LPRECT = LPRECT = ctypes.POINTER(RECT)这样的东西看起来很奇怪。类型不应该是实例的成员回到错误:它是ERROR_INVALID_PARAMETER,因为传递给MagGetInputTransform的所有3个参数都是空指针,[Python 3]:指针声明:
在没有参数的情况下调用指针类型将创建一个
NULL指针。
要修复它(这只是一种方法--我认为这是最直接的)更改:
而且一切都应该很好(不过,所有3个变量都已填充了__s)。
NB:当您在Win上遇到错误时,[MSDN: GetLastError函数](https://msdn.microsoft.com/en-us/library/windows/desktop/ms679360(v=vs.140%29.aspx)是您最好的朋友!
https://stackoverflow.com/questions/49927672
复制相似问题