相关疑难解决方法(0)

使用进程名称获取另一个程序的窗口标题

这个问题可能很基本,但我很难破解它。我假设我将不得不在ctypes.windll.user32. 请记住,我几乎没有使用这些库甚至ctypes整个库的经验。

我已经使用此代码列出了所有窗口标题,但我不知道应该如何更改此代码以获取带有进程名称的窗口标题:

import ctypes

EnumWindows = ctypes.windll.user32.EnumWindows
EnumWindowsProc = ctypes.WINFUNCTYPE(ctypes.c_bool, ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_int))
GetWindowText = ctypes.windll.user32.GetWindowTextW
GetWindowTextLength = ctypes.windll.user32.GetWindowTextLengthW
IsWindowVisible = ctypes.windll.user32.IsWindowVisible

titles = []
def foreach_window(hwnd, lParam):
    if IsWindowVisible(hwnd):
        length = GetWindowTextLength(hwnd)
        buff = ctypes.create_unicode_buffer(length + 1)
        GetWindowText(hwnd, buff, length + 1)
        titles.append(buff.value)
    return True
EnumWindows(EnumWindowsProc(foreach_window), 0)

print(titles)
Run Code Online (Sandbox Code Playgroud)

此代码来自https://sjohannes.wordpress.com/2012/03/23/win32-python-getting-all-window-titles/

如果我的问题不清楚,我想实现这样的目标(只是一个例子 - 我不是专门询问 Spotify):

getTitleOfWindowbyProcessName("spotify.exe") // returns "Avicii - Waiting For Love" (or whatever the title is)
Run Code Online (Sandbox Code Playgroud)

如果有多个窗口以相同的进程名称运行(例如多个 chrome 窗口),则可能出现的复杂情况

谢谢你。


编辑:为了澄清,我想要一些代码,它采用进程名称并返回该进程拥有的(可能为空的)窗口标题列表作为字符串。

python windows

3
推荐指数
1
解决办法
3万
查看次数

如何为 Python 打包的 libcrypto 和 libssl 启用 FIPS 模式?

我有一个 Python 应用程序,它与 Python 和 Libcrypto 以及 LibSSL 共享对象一起打包。该应用程序是使用 Openssl Fips Module 2.0 构建的。Python 的请求模块和 urllib3 在后台使用这些共享对象来发出 TLS 请求。

我在构建应用程序的环境中启用了OPENSSL_FIPS标志。现在,如果要检查共享对象是否在我将它们从开发环境中取出并放入另一台机器时启用了 fips 模式,我该怎么做?

如何检查 fips 模式是否启用?如果不是,我如何为这些共享对象启用 fips 模式?

可能有帮助的其他详细信息:

OpenSSL 版本:1.0.2h(从源代码构建)

Fips 模块:2.0.12(从源代码构建)

蟒蛇:3.6

操作系统:Ubuntu 16.04 LTS

如果需要任何其他详细信息,请告诉我。

谢谢!

python ssl ctypes openssl python-3.x

3
推荐指数
1
解决办法
8053
查看次数

无法在 Python 中导入 dll 模块

几天来,我一直在努力在 Windows 上编译一个修改过的 libuvc 版本,现在我终于完成了,我似乎无法在 Python 上加载它。我已经在 Linux 机器上使用相同版本的 Python 编译并成功导入的这个库根本不喜欢 w10。

系统

  • 赢得 10 64 位
  • 蟒蛇 3.8 64 位
  • libusb 1.022
  • 使用 MinGW64 编译的 libuvc.dll

问题

当尝试

import ctypes
import ctypes.util
name = ctypes.util.find_library('libuvc')
lib = ctypes.cdll.LoadLibrary(name)
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

Could not find module 'C:\Program Files (x86)\libuvc\lib\libuvc.dll'.
Try using the full path with constructor syntax. 
Error: could not find libuvc!
Run Code Online (Sandbox Code Playgroud)

问题是该文件自 util.find_library 找到以来就存在,但 python 认为它不在它所在的位置,或者输出可能只是默认值。我在这里缺少什么?不仅无法加载模块,而且无法找到它,这可能是什么原因?对不起,我没有比这更多的输出。

PS:我尝试以不同的方式重新格式化字符串,但消息没有改变。

python windows winapi ctypes uvc

3
推荐指数
3
解决办法
1万
查看次数

ctype为什么要指定argtypes

我想用python调用c ++库.

我的C++库代码:

#include <stdio.h>

extern "C" {

int test_i(int i)
{
    return i+1;
}

}
Run Code Online (Sandbox Code Playgroud)

我的python代码:

from ctypes import *
libc = cdll.LoadLibrary("cpp/libtest.so")
libc.test_f.argtypes = [c_int] # still works when comment
print libc.test_i(1)
Run Code Online (Sandbox Code Playgroud)

我的问题是:如果我没有指定argtypes,它仍然有效!我必须指定argtypes何时调用C/C++函数?

c++ python ctypes

2
推荐指数
1
解决办法
1833
查看次数

Python中C类型整数的最大值和最小值

我正在寻找一种方式来获得(使用Python)(即C型整数最大值和最小值uint8int8uint16int16uint32int32uint64int64从Python的...)。

我期待在ctypes模块中找到它

In [1]: import ctypes
In [2]: ctypes.c_uint8(256)
Out[2]: c_ubyte(0)
In [3]: ctypes.c_uint8(-1)
Out[3]: c_ubyte(255)
Run Code Online (Sandbox Code Playgroud)

但我找不到

朱莉娅(Julia)具有出色的功能:

julia> typemax(UInt8)
0xff

julia> typemin(UInt8)
0x00

julia> typemin(Int8)
-128

julia> typemax(Int8)
127
Run Code Online (Sandbox Code Playgroud)

我很确定Python具有类似的功能。

理想情况下,我什至在寻找一种方法来确保可以将给定的Python整数(据说是无界的)安全地转换为给定大小的C类型整数。如果数字不在预期的间隔内,则应引发异常。

当前溢出不会引发异常:

In [4]: ctypes.c_uint8(256)
Out[4]: c_ubyte(0)
Run Code Online (Sandbox Code Playgroud)

我看到了这样的整数值的最大值和最小值,但是由于作者正在寻找Python整数的最小值/最大值,所以有点不同……而不是C整数(来自Python)

我还注意到在python中检测C类型限制(“ limits.h”)?但是,即使它很相关,也不能真正回答我的问题。

python size ctypes integer max

2
推荐指数
1
解决办法
960
查看次数

标签 统计

python ×5

ctypes ×4

windows ×2

c++ ×1

integer ×1

max ×1

openssl ×1

python-3.x ×1

size ×1

ssl ×1

uvc ×1

winapi ×1