[英]Too many arguments in my function - Python
I am trying to access my function in a dll and pass by value as integer in it. 我试图在一个DLL中访问我的函数并将值作为整数传递给它。 But I am getting a ValueError as:
但我得到一个ValueError:
Procedure probably called with too many arguments (4 bytes in excess)
My python .py script is as below: 我的python .py脚本如下:
func2.restype = c_int
func2.argtypes = [c_int]
func2(3)
... ...
My actual function in the dll is just a simple function like: 我在dll中的实际功能只是一个简单的功能,如:
int DLLfun2(int argtest) { return argtest + 1; };
... ...
Looks like a simple problem, but I'm guessing I am missing out on something. 看起来像一个简单的问题,但我猜我错过了一些东西。 Kindly help.
请帮助。
Cheers. 干杯。
Looks weird because integer should be automatically cast, but try with a func2(c_int(3))
看起来很奇怪,因为整数应该自动转换,但尝试使用
func2(c_int(3))
EDIT : According to the ctypes doc , this exception could be raised because of a wrong calling convention (cdecl instead of stdcall). 编辑:根据ctypes文档 ,由于错误的调用约定(cdecl而不是stdcall),可能会引发此异常。 But the function is still called (just a sort of warning :s)
但仍然调用该函数(只是一种警告:s)
Be sure of you declaration in your dll. 请务必在你的dll中声明。
If you load your library with windll
, it must use stdcall calling convention, otherwise, use the cdll
module. 如果使用
windll
加载库,则必须使用stdcall调用约定,否则使用cdll
模块。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.