python调用c语言dll_用Python调用C/C++ DLL方法

我在这里有一个关于从c/c++dll调用函数的教程,这个例子是从official tutorial写的。在WINUSERAPI int WINAPI

MessageBoxA(

HWND hWnd,

LPCSTR lpText,

LPCSTR lpCaption,

UINT uType);

Here is the wrapping with ctypes:

>>>

>>> from ctypes import c_int, WINFUNCTYPE, windll

>>> from ctypes.wintypes import HWND, LPCSTR, UINT

>>> prototype = WINFUNCTYPE(c_int, HWND, LPCSTR, LPCSTR, UINT)

>>> paramflags = (1, "hwnd", 0), (1, "text", "Hi"), (1, "caption", None), (1, "flags", 0)

>>> MessageBox = prototype(("MessageBoxA", windll.user32), paramflags)

>>>

The MessageBox foreign function can now be called in these ways:

>>>

>>> MessageBox()

>>> MessageBox(text="Spam, spam, spam")

>>> MessageBox(flags=2, text="foo bar")

>>>

A second example demonstrates output parameters. The win32 GetWindowRect function retrieves the dimensions of a specified window by copying them into RECT structure that the caller has to supply. Here is the C declaration:

WINUSERAPI BOOL WINAPI

GetWindowRect(

HWND hWnd,

LPRECT lpRect);

Here is the wrapping with ctypes:

>>>

>>> from ctypes import POINTER, WINFUNCTYPE, windll, WinError

>>> from ctypes.wintypes import BOOL, HWND, RECT

>>> prototype = WINFUNCTYPE(BOOL, HWND, POINTER(RECT))

>>> paramflags = (1, "hwnd"), (2, "lprect")

>>> GetWindowRect = prototype(("GetWindowRect", windll.user32), paramflags)

>>>

这个例子适用于函数是外部的,但是,假设我有一个对象的引用,我想用params从这个对象调用一个函数,我该怎么做?在

我确实看到了“dumpbin-exports”中所有函数签名的日志,我尝试使用函数的全名,但仍然没有成功。在

任何其他的想法都会被祝福的。在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值