注意:我原来的问题是因为话题不对而结束的,但我将重新提交这个问题,并给出一个可能遇到类似问题的人的答案。
我的系统细节:
Windows 10 64-bit
Python 3.6 64-bit
不幸的是,由于保密性,我无法共享数据文件或dll,但我使用供应商提供的dll (用Delphi编写)来读取二进制仪器数据文件。我也没有访问源代码,也没有任何权利的详细编码支持。
下面显示了一个名为filereadtest.py的示例脚本。
import ctypes
binary_file = r"C:\path\to\binaryfile"
dll_file = r"C:\path\to\dll.dll"
dll = ctypes.WinDLL(dll_file)
dll.OpenDataFile.argtypes = [ctypes.c_wchar_p]
dll.OpenDataFile.restype = ctypes.c_int32
fhandle = dll.OpenDataFile(binary_file)
print(fhandle)
dll.CloseDataFile()
当使用ipython调用时,此调用是成功的,但当使用常规python调用时,此调用将提供一个OSError:
>>> ipython filereadtest.py
0
>>> python filereadtest.py
Traceback (most recent call last):
File "filereadtest.py", line 8, in <module>
fhandle = dll.OpenDataFile(binary_file)
OSError: [WinError 250477278] Windows Error 0xeedfade
发布于 2018-03-13 14:00:28
IPython导入了许多库,并隐藏在导入树的深处,windows特定的标志导入了win32com
,而后者又导入了pythoncom
。pythoncom导入加载库pythoncomXX.dll
。(XX=36或python版本号)。在这种情况下,dll依赖于正在加载的这个库。http://timgolden.me.uk/pywin32-docs/pythoncom.html
以下脚本工作:
import ctypes
import pythoncom # necessary for proper function of the dll
binary_file = r"C:\path\to\binaryfile"
dll_file = r"C:\path\to\dll.dll"
dll = ctypes.WinDLL(dll_file)
dll.OpenDataFile.argtypes = [ctypes.c_wchar_p]
dll.OpenDataFile.restype = ctypes.c_int32
fhandle = dll.OpenDataFile(binary_file)
print(fhandle)
dll.CloseDataFile()
https://stackoverflow.com/questions/49266538
复制相似问题