我想从Python调用WindowsTaskDialogIndirect函数。 它需要TaskDialogConfig(它相当大)结构作为指针传递
下面是我的准备运行示例。它给了我“-2147024809”(参数不正确),我无法找出什么是错误的
Python 3.7.4 x32,Windows 7 x64
import ctypes
from ctypes.wintypes import *
TDF_ALLOW_DIALOG_CANCELLATION = 8
TDCBF_OK_BUTTON = 1
class TaskDialogConfig(ctypes.Structure):
class DUMMYUNIONNAME(ctypes.Union):
_fields_ = [
('hMainIcon', HICON)
, ('pszMainIcon', LPCWSTR)
]
class DUMMYUNIONNAME2(ctypes.Union):
_fields_ = [
('hFooterIcon', HICON)
, ('sFooterIcon', LPCWSTR)
]
class _TASKDIALOG_BUTTON(ctypes.Structure):
_fields_ = [
('nButtonID', INT)
, ('pszButtonText', LPCWSTR)
]
_fields_ = [
('cbSize', UINT)
, ('hwndParent', HWND)
, ('hInstance', HINSTANCE)
, ('dwFlags', UINT)
, ('dwCommonButtons', UINT)
, ('pszWindowTitle', LPCWSTR)
, ('DUMMYUNIONNAME', DUMMYUNIONNAME)
, ('pszMainInstruction', LPCWSTR)
, ('pszContent', LPCWSTR)
, ('cButtons', UINT)
, ('pButtons', _TASKDIALOG_BUTTON)
, ('nDefaultButton', INT)
, ('cRadioButtons', UINT)
, ('pRadioButtons', _TASKDIALOG_BUTTON)
, ('nDefaultRadioButton', INT)
, ('pszVerificationText', LPCWSTR)
, ('pszExpandedInformation', LPCWSTR)
, ('pszExpandedControlText', LPCWSTR)
, ('pszCollapsedControlText', LPCWSTR)
, ('DUMMYUNIONNAME2', DUMMYUNIONNAME2)
, ('pszFooter', LPCWSTR)
, ('pfCallBack', ctypes.POINTER(None))
, ('lpCallbackData', LPLONG)
, ('cxWidth', UINT)
]
def __init__(s):
s.cbSize = ctypes.sizeof(s)
tdi = ctypes.WinDLL('comctl32.dll').TaskDialogIndirect
tdc = TaskDialogConfig()
tdc.hwndParent = None
tdc.hInstance = None
tdc.dwFlags = TDF_ALLOW_DIALOG_CANCELLATION
tdc.dwCommonButtons = TDCBF_OK_BUTTON
tdc.pszWindowTitle = ctypes.c_wchar_p('Title')
tdc.pszMainInstruction = ctypes.c_wchar_p('Main instruction')
tdc.pszContent = ctypes.c_wchar_p('Content')
print( tdi(ctypes.byref(tdc), None, None, None) )
两个问题
_pack_ = 1
定义之前添加_fields_
李>_TASKDIALOG_BUTTON
字段的类型应为ctypes.POINTER(_TASKDIALOG_BUTTON)
李>我使用一个C程序来打印结构的大小和几个字段的偏移量,并用Python打印了相同的信息,从而找到了这些字段:
相关问题 更多 >
编程相关推荐