How to use win32api from IronPython

Writing some test scripts in IronPython, I want to check if a window is displayed or not. I have a pid for the main application process and want to get a list of window names associated with pid.

I tried to avoid using win32api calls like FindWindowEx, since (as far as I know) you cannot access win32api directly from IronPython. Is there a way to do this using the built-in .net classes? Most of the materials that I came across recommends using win32api, for example, below.

.NET (C #): Getting child windows when you only have a process handle or PID?

UPDATE: I found a job around what I was trying to do. The answer is below.

+3
source share
3 answers

The following article shows how to access win32api indirectly with IronPython. It uses the CSharpCodeProvider CompileAssemblyFromSource method to compile an in-memory assembly from a C # source line. IronPython can then import the assembly.

Dynamic C # Compilation from IronPython

+2
source

IronPython 2.6 supports the ctypes module . This module provides C-compatible data types and allows you to call functions in a DLL. Quick example:

import ctypes
buffer = ctypes.create_string_buffer(100)
ctypes.windll.kernel32.GetWindowsDirectoryA(buffer, len(buffer))
print buffer.value
+1
source

, , . , win32api. , , .

, , , .

0
source

Source: https://habr.com/ru/post/1697469/


All Articles