在Python 3中执行windll.version.GetFileVersionInfoSizeA()失败

问题描述 投票:1回答:1

我正在尝试在python ctypes中执行windll.version.GetFileVersionInfoSizeA()。我正在执行以下代码:

_GetFileVersionInfoSizeA = ctypes.windll.version.GetFileVersionInfoSizeA
_GetFileVersionInfoSizeA.argtypes = [ctypes.c_char_p, ctypes.c_void_p]
_GetFileVersionInfoSizeA.restype = ctypes.c_uint32
_GetFileVersionInfoSizeA.errcheck = RaiseIfZero # RaiseIfZero is a function to raise error
# lptstrFilename is the file path
dwLen = _GetFileVersionInfoSizeA(lptstrFilename, None)

此代码在python 2中完美运行,但在python 3.8中不起作用。它给出以下错误:

argument 1: <class 'TypeError'>: wrong type

根据GetFileVersionInfoSizeA的msdn doc,第二个参数应为“指向该函数设置为零的变量的指针”。我尝试了以下代码,但给出的错误与以前相同。

dwLen = _GetFileVersionInfoSizeA(lptstrFilename, LPVOID)

我不确定我缺少什么。注意-这是我第一次使用ctypes。

python python-3.x python-2.7 ctypes python-3.8
1个回答
0
投票

在python2中,可以使用两种类型来表示字符串。 字符串Unicode字符串。

因此c_char_p ctypes类型用于表示python2字符串类型,而c_wchar_p ctypes类型用于表示python2 Unicode字符串类型。但是在python3中只有一种字符串类型。因此,c_wchar_p ctypes类型用于表示python3 string类型。

您可以在python 2python 2文档中找到基本数据类型。

python 3
© www.soinside.com 2019 - 2024. All rights reserved.