目前使用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
|