|
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的程序上运行成功
- >>> import ctypes
- >>> usbport=ctypes.c_uint16(0)
- >>> count=ctypes.c_uint16(0)
- >>> dev=ctypes.WinDLL(r'D:\560\DesignSources\3.GUI source\Code spec\S0003_F340_Control_Dll.dll')
- >>> dev.Dll_F00007_USB_Platform_Start(usbport,ctypes.byref(count))
- 0
复制代码
但是使用32bit的程序上调用总是出现function not found的错误,分别使用ctypes.WinDLL ,ctypes.CDLL,ctypes.windll.LoadLibrary,ctypes.cdll.LoadLibrary均尝试了
- >>> import ctypes
- >>> dev=ctypes.CDLL(r'D:\560\DesignDocuments\1.Software\0.module\python\python2_CIG\CredoPython\Device\dove_api.dll')
- >>> usbport=ctypes.c_uint16(0)
- >>> count=ctypes.c_uint16(0)
- >>> dev.Dll_F00007_USB_Platform_Start(usbport,ctypes.byref(count))
- Traceback (most recent call last):
- File "<pyshell#4>", line 1, in <module>
- dev.Dll_F00007_USB_Platform_Start(usbport,ctypes.byref(count))
- File "C:\Users\chenhongwen\AppData\Local\Programs\Python\Python38-32\lib\ctypes\__init__.py", line 386, in __getattr__
- func = self.__getitem__(name)
- File "C:\Users\chenhongwen\AppData\Local\Programs\Python\Python38-32\lib\ctypes\__init__.py", line 391, in __getitem__
- func = self._FuncPtr((name_or_ordinal, self))
- AttributeError: function 'Dll_F00007_USB_Platform_Start' not found
- >>> dev=ctypes.WinDLL(r'D:\560\DesignDocuments\1.Software\0.module\python\python2_CIG\CredoPython\Device\dove_api.dll')
- >>> dev.Dll_F00007_USB_Platform_Start(usbport,ctypes.byref(count))
- Traceback (most recent call last):
- File "<pyshell#6>", line 1, in <module>
- dev.Dll_F00007_USB_Platform_Start(usbport,ctypes.byref(count))
- File "C:\Users\chenhongwen\AppData\Local\Programs\Python\Python38-32\lib\ctypes\__init__.py", line 386, in __getattr__
- func = self.__getitem__(name)
- File "C:\Users\chenhongwen\AppData\Local\Programs\Python\Python38-32\lib\ctypes\__init__.py", line 391, in __getitem__
- func = self._FuncPtr((name_or_ordinal, self))
- AttributeError: function 'Dll_F00007_USB_Platform_Start' not found
复制代码
|
最佳答案
查看完整内容
这个问题应该是因为程序当前的编辑运行环境不匹配, 因为64位的python.exe只能调用64位的DLL,32位的python.exe 只能调用32位的DLL。如果你用64位环境下的python调用32位的DLL文件肯定是不行的,要保证环境一致。具体请参照https://blog.csdn.net/weixin_39590566/article/details/113320798
|