#%% #解压函数应用 代码如下: print(pd_3d[1]) dll=ctypes.cdll.LoadLibrary("dunzip32.dll")#调用函数加载cdll.LoadLibrary(),windll.LoadLibrary() dll.dunzip.restype = None#指定调用函数返回值类型 dll.dunzip.argtypes =[ctypes.c_char_p, ctypes.c_char_p,ctypes.c_int]#指定函数参数类型 PDate = ctypes.c_char_p() PDate.value = bytes(pd_3d[1][2]) Udate=ctypes.c_char_p() PSize=ctypes.c_int(pd_3d[1][1]) USize=ctypes.c_int() dpd=dll.dunzip(PDate,Udate,USize)##, print(dpd) print(Udate.value)
运行结果
ValueError Traceback (most recent call last)
<ipython-input-256-fce7117ca0e6> in <module>() 11 USize=ctypes.c_int() 12 ---> 13 dpd=dll.dunzip(PDate,Udate,USize)##, 14 15 print(dpd)
ValueError: Procedure called with not enough arguments (4 bytes missing) or wrong calling convention
将加载方式换为windll.LoadLibrary()也不行
ValueError Traceback (most recent call last)
<ipython-input-257-cc2c600b095e> in <module>() 11 USize=ctypes.c_int() 12 ---> 13 dpd=dll.dunzip(PDate,Udate,USize)##, 14 15 print(dpd)
ValueError: Procedure probably called with too many arguments (8 bytes in excess)
将加载方式换为windll.LoadLibrary()也不行
到底是库有问题,还是调用参数传递有问题呢
1. 确认dll是C/C++的而不是C#的动态库,否则,需要使用IronPython而不是Python
2. 确认你的Python2.7是32位的
1.ValueError: Procedure probably called with too many arguments (8 bytes in excess) 一般是因为c里面用__cdecl 调用方式,但是python里用windll加载导致。
2.先把这个地方按照规范写一下:Udate=ctypes.c_char_p() 只定义了类型,没有分配存储空间,需要像PDate.value = bytes(pd_3d[1][2]) 一样处理,