使用Python ctypes访问Visual Foxpro COM DLL

使用Python ctypes访问Visual Foxpro COM DLL,python,dll,ctypes,foxpro,visual-foxpro,Python,Dll,Ctypes,Foxpro,Visual Foxpro,我试图使用PythonCtypes库访问在VisualFoxPro中创建的COM DLL中的各种函数(从.prg文件) 下面是fox pro中的一个示例(根据实际代码简化) 将类测试定义为自定义测试 程序初始化 论错误 启动控制台 启程 起爆 引起议论 启程 ENDPROC 函数get_input_out(作为字符串输入)作为字符串 输出=输入 返回输出 ENDFUNC 结束定义 在python中,我按照以下思路进行操作: import ctypes link = ctypes.WinDLL(

我试图使用PythonCtypes库访问在VisualFoxPro中创建的COM DLL中的各种函数(从.prg文件)

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

将类测试定义为自定义测试 程序初始化 论错误 启动控制台 启程 起爆 引起议论 启程 ENDPROC 函数get_input_out(作为字符串输入)作为字符串 输出=输入 返回输出 ENDFUNC 结束定义 在python中,我按照以下思路进行操作:

import ctypes link = ctypes.WinDLL("path\to\com.dll") print link.get_input_out("someinput") 导入ctypes link=ctypes.windl(“path\to\com.dll”) 打印链接。获取输入输出(“someinput”) dll注册良好并已加载,但当我尝试调用该函数时,我只得到以下信息

AttributeError: function 'get_input_out' not found AttributeError:未找到函数“get\u input\u out” 我可以确定dll是否工作,因为我可以使用COM库通过php脚本访问函数


我真的很想在python中实现这一点,但到目前为止我的尝试都是徒劳的,ctypes甚至可以在VFP中工作吗?任何建议都将不胜感激。

尝试删除函数调用中的括号。将
print link.get\u input\u out(“someinput”)
更改为
print link.get\u input\u out“someinput”

对于使用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访问表,而ADODB又可以通过Win32扩展中相同的
Dispatch()
功能访问表。

Hi,我尝试了一下,但不幸的是python认为这个语法错误:无效语法。我不认为我最初的错误与函数变量有关,而是首先找到要调用的函数。谢谢你的提议!
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