1

我正在尝试使用 python ctypes库来访问在 Visual Fox Pro 中创建的 COM DLL 中的各种函数(来自 .prg 文件)。

这是fox pro中的一个示例(根据实际代码简化)

将 CLASS 测试定义为 CUSTOM OLEPUBLIC

    程序初始化
        开启错误
        关闭控制台
        设置通知关闭
        设置安全关闭
        关闭通话
        设置通知关闭
    ENDPROC

    功能 get_input_out(输入为字符串)为字符串
        输出 = 输入
        返回输出
    结束函数

结束定义

在python中,我正在做一些事情:

导入 ctypes

链接 = ctypes.WinDLL("path\to\com.dll")
打印链接.get_input_out("someinput")

dll 注册良好并已加载,但当我尝试调用该函数时,我只得到以下信息。

AttributeError:找不到函数“get_input_out”

我可以验证 dll 确实有效,因为我能够使用 COM 库通过 php 脚本访问这些函数。

我真的很想让它在 python 中工作,但到目前为止我的尝试都是徒劳的,ctypes 甚至可以与 VFP 一起使用吗?任何意见,将不胜感激。

4

2 回答 2

3

对于使用 OLEPUBLIC 子句的 VFP COM 对象,您应该使用 python Win32 扩展,而不是ctypes模块。Python Win32 扩展提供了一整套功能齐全的组件,允许 Python 成为 COM 客户端,这正是您在本例中所需要的。

您的代码应如下所示:

from win32com.client import Dispatch
oFox = Dispatch("com.testing")
# where the file name compiled by VFP is com.dll and the olepublic class is testing.
# in Windows this stuff is not case sensitive.
print oFox.get_input_out("something")
# to close things down..
oFox = None

如果您只想访问 VFP 表,Microsoft 提供了一个免费的 ADO 兼容组件vfpoledb,可用于通过 ADODB 访问表,而后者又可以通过Dispatch()Win32 扩展中的相同功能进行访问。

于 2012-09-18T03:50:47.607 回答
0

尝试从对函数的调用中删除括号。更改print link.get_input_out("someinput")print link.get_input_out "someinput"

于 2012-07-23T13:39:32.833 回答