鱼C论坛

 找回密码
 立即注册
查看: 6434|回复: 6

[已解决]dll调用,出现function not found错误

[复制链接]
发表于 2021-6-9 13:55:55 | 显示全部楼层 |阅读模式
5鱼币
目前使用python调用dll程序,64位dll和32位dll是由相同的c/c++程序生成。

extern "C" __declspec(dllexport) int Dll_F00007_USB_Platform_Start(uint16_t USBPort, uint16_t & Count)

在64bit的程序上运行成功 64bit.PNG
  1. >>> import ctypes
  2. >>> usbport=ctypes.c_uint16(0)
  3. >>> count=ctypes.c_uint16(0)
  4. >>> dev=ctypes.WinDLL(r'D:\560\DesignSources\3.GUI source\Code spec\S0003_F340_Control_Dll.dll')
  5. >>> dev.Dll_F00007_USB_Platform_Start(usbport,ctypes.byref(count))
  6. 0
复制代码


但是使用32bit的程序上调用总是出现function not found的错误,分别使用ctypes.WinDLL ,ctypes.CDLL,ctypes.windll.LoadLibrary,ctypes.cdll.LoadLibrary均尝试了
  1. >>> import ctypes
  2. >>> dev=ctypes.CDLL(r'D:\560\DesignDocuments\1.Software\0.module\python\python2_CIG\CredoPython\Device\dove_api.dll')
  3. >>> usbport=ctypes.c_uint16(0)
  4. >>> count=ctypes.c_uint16(0)
  5. >>> dev.Dll_F00007_USB_Platform_Start(usbport,ctypes.byref(count))
  6. Traceback (most recent call last):
  7.   File "<pyshell#4>", line 1, in <module>
  8.     dev.Dll_F00007_USB_Platform_Start(usbport,ctypes.byref(count))
  9.   File "C:\Users\chenhongwen\AppData\Local\Programs\Python\Python38-32\lib\ctypes\__init__.py", line 386, in __getattr__
  10.     func = self.__getitem__(name)
  11.   File "C:\Users\chenhongwen\AppData\Local\Programs\Python\Python38-32\lib\ctypes\__init__.py", line 391, in __getitem__
  12.     func = self._FuncPtr((name_or_ordinal, self))
  13. AttributeError: function 'Dll_F00007_USB_Platform_Start' not found
  14. >>> dev=ctypes.WinDLL(r'D:\560\DesignDocuments\1.Software\0.module\python\python2_CIG\CredoPython\Device\dove_api.dll')
  15. >>> dev.Dll_F00007_USB_Platform_Start(usbport,ctypes.byref(count))
  16. Traceback (most recent call last):
  17.   File "<pyshell#6>", line 1, in <module>
  18.     dev.Dll_F00007_USB_Platform_Start(usbport,ctypes.byref(count))
  19.   File "C:\Users\chenhongwen\AppData\Local\Programs\Python\Python38-32\lib\ctypes\__init__.py", line 386, in __getattr__
  20.     func = self.__getitem__(name)
  21.   File "C:\Users\chenhongwen\AppData\Local\Programs\Python\Python38-32\lib\ctypes\__init__.py", line 391, in __getitem__
  22.     func = self._FuncPtr((name_or_ordinal, self))
  23. AttributeError: function 'Dll_F00007_USB_Platform_Start' not found
复制代码

32bit.PNG
最佳答案
2021-6-9 13:55:56
这个问题应该是因为程序当前的编辑运行环境不匹配, 因为64位的python.exe只能调用64位的DLL,32位的python.exe 只能调用32位的DLL。如果你用64位环境下的python调用32位的DLL文件肯定是不行的,要保证环境一致。具体请参照https://blog.csdn.net/weixin_39590566/article/details/113320798

最佳答案

查看完整内容

这个问题应该是因为程序当前的编辑运行环境不匹配, 因为64位的python.exe只能调用64位的DLL,32位的python.exe 只能调用32位的DLL。如果你用64位环境下的python调用32位的DLL文件肯定是不行的,要保证环境一致。具体请参照https://blog.csdn.net/weixin_39590566/article/details/113320798
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-6-9 13:55:56 | 显示全部楼层    本楼为最佳答案   
这个问题应该是因为程序当前的编辑运行环境不匹配, 因为64位的python.exe只能调用64位的DLL,32位的python.exe 只能调用32位的DLL。如果你用64位环境下的python调用32位的DLL文件肯定是不行的,要保证环境一致。具体请参照https://blog.csdn.net/weixin_39590566/article/details/113320798
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2021-6-16 09:38:50 | 显示全部楼层
有大神遇到类似的情况吗,怎么解决的
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-6-16 11:44:43 From FishC Mobile | 显示全部楼层
lucky邪神 发表于 2021-6-16 09:38
有大神遇到类似的情况吗,怎么解决的

把dll发出来看看
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2021-6-17 15:53:26 | 显示全部楼层
win64是64位
win32是32位
SiUSBXp.dll是标准的文件

dll.zip

327.45 KB, 下载次数: 3

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-7-21 09:57:04 | 显示全部楼层
请问你解决了吗
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2022-5-29 10:54:49 | 显示全部楼层
临时号 发表于 2021-7-21 14:13
这个问题应该是因为程序当前的编辑运行环境不匹配, 因为64位的python.exe只能调用64位的DLL,32位的python ...

我电脑上64为和32位的python,都有。后面问题解决了,dll改动后,目前64位和32位都可以使用
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-27 04:39

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表