以下代码在Python2中运行良好:
import ctypes
def test():
OpenSCManager = ctypes.windll.advapi32.OpenSCManagerA
CloseServiceHandle = ctypes.windll.advapi32.CloseServiceHandle
handle = OpenSCManager(None, None, 0)
print(hex(handle))
assert handle, ctypes.GetLastError()
assert CloseServiceHandle(handle), ctypes.GetLastError()
test()
它在Python 3中不起作用:
^{pr2}$6表示句柄无效。在
另外,在python2中检索到的句柄似乎是更小的数字,例如0x100ffc0。它不是CloseServiceHandle
的特定内容。此句柄不能与任何服务函数一起使用。在
两个Python版本都是64位本机Windows Python。在
您应该使用
argtypes
和restype
,否则所有参数默认为int,并在64位中被截断。{{cd3>你不应该直接调用cd3}代码。在下面是一个有效的例子:
相关问题 更多 >
编程相关推荐