如何在Python 3.1中进行Windows API调用?

6 投票
2 回答
7538 浏览
提问于 2025-04-15 12:33

有没有人找到适用于 Python 3.x 的 pywin32 版本?目前找到的最新版本似乎只支持 2.6。

或者,我该如何在 Python 3.1 中自己实现 Windows API 的调用呢?

2 个回答

10

你可以用 ctypes 来完成所有事情,虽然可能有点麻烦。

下面是一个获取“公共应用数据”文件夹的例子:

from ctypes import windll, wintypes

_SHGetFolderPath = windll.shell32.SHGetFolderPathW
path_buf = wintypes.create_unicode_buffer(255)
csidl = 35
_SHGetFolderPath(0, csidl, 0, 0, path_buf)
print(path_buf.value)

结果:

C:\Documents and Settings\All Users\Application Data
6

现在有适用于Python 3.0的pywin32库。Python 3.1在两天前发布,所以如果你需要在Python 3.1上使用pywin32,你要么等一段时间,要么自己从源代码编译。

http://sourceforge.net/project/showfiles.php?group_id=78018&package_id=79063

撰写回答