python 3.6 32位调用DLL参数溢出。而3.8则正常。
python3吧
全部回复
仅看楼主
level 1
蓝梦妖蝶 楼主
只有python 3.6 32位异常。python 3.6 64位和python 3.8都正常。
而且只有几个函数会出参数溢出的报错,多数函数均可正常使用。
代码
version_info = sys.version_info
if(version_info.major>=3)and(version_info.minor>=8):
visa = WinDLL("visa32.dll",winmode=0) # python 3.8 需要加模式否则找不到函数
else:
visa = WinDLL("visa32.dll")
strRes=create_string_buffer(256)
def VISA_Read(vi_index):
visa.viScanf(vi_index, b'%t', byref(strRes))
return strRes.value
会报这个错误
visa.viScanf(vi_index, b'%t', byref(strRes))
ValueError: Procedure probably called with too many arguments (12 bytes in excess)
2024年02月29日 08点02分 1
level 1
蓝梦妖蝶 楼主
网上很多类似的问题都是换CDLL调用就解决了。错误多见于32bit Python加载32bit DLL文件时,测试过64bit Python3.6和3.8用WinDLL加载64bit dll模块并不会报错,但是最好按照ctypes约定的方式加载DLL文件。
但我使用CDLL。好奇怪viScanf不报错了。但是其他接口函数开始出错。
visa = CDLL("visa32.dll")
我分别调用几个函数
visa.viOpenDefaultRM(byref(defrm))
报错ValueError: Procedure called with not enough arguments (4 bytes missing) or wrong calling convention
visa.viVPrintf(vi_index, argwriteFmt, byref(argparams))
报错ValueError: Procedure called with not enough arguments (12 bytes missing) or wrong calling convention
visa.viScanf(vi_index, b'%t', byref(strRes))
正常运行,
2024年02月29日 10点02分 2
level 1
蓝梦妖蝶 楼主
目前怀疑是visa32.dll里的函数分别用了cdecl, stdcall
解决方法就是分别引用两次
visa = WinDLL("visa32.dll") # stdcall
visa1 = CDLL("visa32.dll") # cdecl
在引用中。分别用不同的方式调用。
visa.viVPrintf(vi_index, argwriteFmt, byref(argparams))#针对stdcall接口
visa1.viScanf(vi_index, b'%t', byref(strRes))#针对 cdecl接口。
这样程序在3.6.6里就跑通了。
2024年02月29日 10点02分 3
1