python格式字符串的参数不足,Python ctypes和参数不足(缺少4个字节)

The function i'm trying to call is:

void FormatError (HRESULT hrError,PCHAR pszText);

from a custom dll using windll.

c_p = c_char_p()

windll.thedll.FormatError(errcode, c_p)

Results in:

ValueError: Procedure probably called with not enough arguments (4 bytes missing)

Using cdll instead increases the bytes missing counter to 12. errcode above is the errercode returned from another function out of the same dll. How do I get the call right?

解决方案

At the very least, you'll get more descriptive errors if you properly set up the argtypes and the restype.

Try doing it this way:

windll.thedll.FormatError.argtypes = [ctypes.HRESULT, ctypes.c_char_p]

windll.thedll.FormatError.restype = None

There's also a very good chance you are using the wrong calling convention -- check out the Calling Functions section and the Loading Libraries section for details on how to use a different calling convention.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值