1
votes

I am trying to use the python ctypes library to access various functions in a COM DLL created in Visual Fox Pro (from a .prg file).

Here is an example in fox pro (simplified from the actual code)

DEFINE CLASS Testing AS CUSTOM OLEPUBLIC

    PROCEDURE INIT
        ON ERROR
        SET CONSOLE OFF
        SET NOTIFY OFF
        SET SAFETY OFF
        SET TALK OFF
        SET NOTIFY OFF
    ENDPROC

    FUNCTION get_input_out(input AS STRING) AS STRING
        output = input
        RETURN output
    ENDFUNC

ENDDEFINE

In python i am doing something along the lines of:

import ctypes

link = ctypes.WinDLL("path\to\com.dll")
print link.get_input_out("someinput")

The dll registers fine and is loaded but i just get the following when I try to call the function.

AttributeError: function 'get_input_out' not found

I can verfiy the dll does work as i was able to access the functions with a php script using the COM libary.

I would really like to get this working in python but so far my attempts have all been in vain, will ctypes even work with VFP? Any advice would be appreciated.

2

2 Answers

3
votes

In the case of VFP COM objects using the OLEPUBLIC clause, you should use the python Win32 extensions, not the ctypes module. Python Win32 extensions provide a full featured set of components that allow Python to be a COM client, which is what you want in this case.

Your code should look something like this:

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

If all you want to do is access VFP tables, Microsoft supplies a free ADO compliant component vfpoledb which can be used to access tables via ADODB, which in turn can be accessed through this same Dispatch() capability in the Win32 extensions.

0
votes

Try removing the parentheses from the call to the function. Change print link.get_input_out("someinput") to print link.get_input_out "someinput".