-1

我对 Ctypes 有一个问题,不知道我做错了什么。是的,我是 Python 的新手,在这里搜索了其他帖子。因此,任何建议都值得赞赏。

我想做什么:

我只是想将 FXCM C++ APP 资金加载到 Python 3.3 中,这样我就可以调用它们来连接到他们的服务器。看起来 Ctypes 似乎是最好的工具。所以一个简单的 Python 代码:

import os
dirlist = os.listdir('ForexConnectAPIx64/bin')
from pprint import pprint
pprint(dirlist)


from ctypes import  *
myDll = cdll.LoadLibrary ("ForexConnectAPIx64/bin/ForexConnect.dll")

给出一个结果:

Traceback (most recent call  File "C:\Users\scaberia3\Python_Projects      \FTC\ListDir_Test.py", line 20, in <module>
myDll = cdll.LoadLibrary ("ForexConnectAPIx64/bin/ForexConnect.dll")
File "C:\Python33\lib\ctypes\__init__.py", line 431, in LoadLibrary
return self._dlltype(name)
File "C:\Python33\lib\ctypes\__init__.py", line 353, in __init__
self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] Das angegebene Modul wurde nicht gefunden  (Module not found)

['ForexConnect.dll',
'fxmsg.dll',
'gsexpat.dll',
'gslibeay32.dll',
'gsssleay32.dll',
'gstool2.dll',
'gszlib.dll',
'java',
'log4cplus.dll',
'msvcp80.dll',
'msvcr80.dll',
'net',
'pdas.dll']                   

意味着路径是正确的 ForextConnect.dll 存在,我可能会做一些非常简单的错误,但不知道是什么。

4

1 回答 1

0

您可以使用 Dependency Walker 找出手动加载 DLL 的正确顺序,或者简单地将目录添加到系统搜索路径:

dllpath = os.path.abspath('ForexConnectAPIx64/bin')
os.environ['PATH'] += os.pathsep + dllpath
myDLL = CDLL('ForexConnect.dll')
于 2013-03-27T17:05:50.147 回答