所以我给了这样一个标题行:
typedef PVOID (WINAPI *GDIMARSHALLOC)(DWORD dwSize, __in LPVOID pGdiRef);
如何在不调用原型的情况下维护param名称/标志?
我知道怎么做才是这样的:
GDIMARSHALLOC = POINTER(CALLBACK(PVOID, DWORD, LPVOID))
请注意,CALLBACK
是一个自定义定义,类似于WINFUNCTYPE
。
您可以在实例化CFUNCTYPE / WINFUNCTYPE原型时指定参数标志,但不能指定参数名称,但我不知道这对回调有何帮助,因为它会在您的代码之外调用。
有关paramflags的讨论,请参阅Function Prototypes文档中ctypes
的底部。
以下是该文档的示例:
>>> from ctypes import c_int, WINFUNCTYPE, windll
>>> from ctypes.wintypes import HWND, LPCWSTR, UINT
>>> prototype = WINFUNCTYPE(c_int, HWND, LPCWSTR, LPCWSTR, UINT)
>>> paramflags = (1, "hwnd", 0), (1, "text", "Hi"), (1, "caption", "Hello from ctypes"), (1, "flags", 0)
>>> MessageBox = prototype(("MessageBoxW", windll.user32), paramflags)
现在可以通过以下方式调用MessageBox外部函数:
>>> MessageBox()
>>> MessageBox(text="Spam, spam, spam")
>>> MessageBox(flags=2, text="foo bar")