Python中使用ctypes调用Windows API
# -*- coding: cp936 -*- import ctypes import ctypes.wintypes #print(dir(ctypes)) #print(dir(ctypes.wintypes)) user32 = ctypes.WinDLL("user32.dll") FindWindowA = user32.FindWindowA GetWindowTextA = user32.GetWindowTextA EnumWindows = user32.EnumWindows #Windows回调函数 def EnumWindowProc(hWnd, lParam): text = ctypes.c_char_p() text.value = "" GetWindowTextA(hWnd, text, 200) print(text.value) return 1 #声明原型,注意需要首先要声明返回值类型 pFunc = ctypes.WINFUNCTYPE(ctypes.c_int, ctypes.wintypes.HWND, ctypes.wintypes.LPARAM) pFuncHandle = pFunc(EnumWindowProc) EnumWindows(pFuncHandle, None)