Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do windows API calls in Python 3.1?

Has anyone found a version of pywin32 for python 3.x? The latest available appears to be for 2.6.

Alternatively, how would I "roll my own" windows API calls in Python 3.1?

like image 908
Blorgbeard Avatar asked Jun 29 '09 09:06

Blorgbeard


People also ask

Can you use Windows API with Python?

Interpreted languages like Python can also be used for API hooking and have some advantages over compiled languages. In this article, we explore when and why it's best to choose Python for hooking Windows APIs and explain how to use this language for setting hooks based on easy-to-follow examples.

How do I interact with Windows API?

To call a Windows API using the DllImport attribute Open a new Windows Application project by clicking New on the File menu, and then clicking Project. The New Project dialog box appears. Select Windows Application from the list of Visual Basic project templates. The new project is displayed.

What is Win32 API in Python?

Python Python Win32api. Created: March-05, 2022. The win32api module provides various libraries and objects utilized to deal with the Windows system's Application Programming Interface (API).

Is Win32 API still used?

The Win32 API is probably the longest-living user interface framework still in use, with its initial release through Windows NT 3.1 in 1993 and its origins dating back to Windows 1.0 for 16-bit processors of 1985.


2 Answers

You should be able to do everything with ctypes, if a bit cumbersomely.

Here's an example of getting the "common application data" folder:

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)

Result:

C:\Documents and Settings\All Users\Application Data
like image 123
Ryan Ginstrom Avatar answered Oct 19 '22 13:10

Ryan Ginstrom


There are pywin32 available for 3.0. Python 3.1 was release two days ago, so if you need pywin32 for that you either need to wait a bit, or compile them from source.

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

like image 35
Lennart Regebro Avatar answered Oct 19 '22 11:10

Lennart Regebro